# Project - IR Sender
In the previous project, we learned how to capture signals from a remote controller. In this project, we’ll build our own remote controller to replicate the functionality of an existing one.
First, choose a button from an existing remote that you’d like to duplicate, and check the Protocol, Address, and Command information from the serial monitor in the previous project.
Now, let’s write the code to replicate it!

```cpp
#include
#include
#define SEND_PWM_BY_TIMER //Using a hardware timer to generate the PWM signal
#define IR_SEND_PIN 4
#define BTN_PIN 3
void setup() {
Serial.begin(9600);
pinMode(BTN_PIN, INPUT);
IrSender.begin(IR_SEND_PIN);
}
void loop() {
if (digitalRead(BTN_PIN) == HIGH) {
uint8_t sAddress = 0xE;
uint8_t sCommand = 0x14;
uint8_t sRepeats = 0;
Serial.println("Protocl=Samsung, address=0xE, command=0x14, repeats=0");
IrSender.sendSamsung(sAddress, sCommand, sRepeats);
delay(300); //button debounce
}
delay(10);
}
```
```cpp
#define IR_SEND_PIN 4
#define BTN_PIN 3
```
The right leg of the IR908-7C is connected to GPIO 4 on the Lonely Binary UNO R3. The left leg is connected to a 220Ω resistor, which is then connected to Ground.
The button is connected to GPIO 3 on the Lonely Binary UNO R3, with the other end connected to 5V. This means that when the button is pressed, GPIO 3 will be in a HIGH state. To ensure that GPIO 3 defaults to a LOW state when the button is not pressed, we use a pull-down resistor of 10kΩ connected to Ground.
```cpp
pinMode(BTN_PIN, INPUT);
```
Sets the button pin (pin 3) as an input.
```cpp
IrSender.begin(IR_SEND_PIN);
```
The IR sender is initialized on pin 4.
```cpp
if (digitalRead(BTN_PIN) == HIGH) {
... ...
}
```
The code constantly checks if the button connected to pin 3 is pressed (digitalRead(BTN_PIN) == HIGH).
```cpp
IrSender.sendSamsung(sAddress, sCommand, sRepeats);
```
The IrSender.sendSamsung() function sends the IR signal with the defined address, command, and repeats using the Samsung protocol.
```cpp
delay(300); //button debounce
```
Don't forget to add button debounce delay before the if end.
Project - IR Sender
RELATED ARTICLES
Photoresistor Sensor
Project - Temperature Measurement
NTC Temperature Sensor
Project - IR Receiver
Remote infrared Sensor
Project - Motion Detection Alarm
PIR Motion Sensor
- Choosing a selection results in a full page refresh.