In this project, we are going to control LEDs using an IR sensor and a remote. The IR sensor is a 1838B IR receiver. Whenever a button on the remote is pressed, it will send an infrared signal to the IR sensor in the coded form. The IR sensor will then receive this signal and will give it to the Arduino.

How Does It Work?

Whenever a button is pressed on the remote, it sends an infrared signal in encoded form. This signal is then received by the IR receiver and given to the Arduino.

We will save the code for the buttons that we want to control the LEDs in the Arduino code. Whenever a button on the remote is pressed, the Arduino receives a code. The Arduino will compare this code with the codes already saved, and if any of them match, the Arduino will turn on the LED connected to that button.

Circuit Diagram

First, connect the four LEDs to the Arduino. Connect the positives of the four LEDs to the pins 7, 6, 5, and 4. Connect the negative of the four LEDs to GND on the Arduino through the 220 ohm resistors. The longer wires on the LEDs are positive and the shorter wires are negative.

Then connect the IR sensor to the Arduino. The connections for the IR sensor with the Arduino are as follows:

Connect the negative wire on the IR sensor to GND on the Arduino.

Connect the middle of the IR sensor which is the VCC to 5V on the Arduino.

Code Explanation

First of all, we added the library for the IR sensor and remote, then we defined the codes for the keys that we are going to use in our project. If you are using the code for the first time and do not know the code for the keys, then upload the Arduino code as it is and press the remote keys—the code for the keys you pressed will be shown in the serial monitor. Now change this code with the previous code for the key that you want to control the LED with.

In the loop function, first, we check if any key has been pressed. If any key has been pressed, then we compare that key with the keys that we have defined in our code. If the key matches, then the LED connected to that pin will light up. If the LED connected to that pin is already lit up, then it will go down.