Remote Control Leds

by rayankiwan63 in Circuits > Arduino

139 Views, 0 Favorites, 0 Comments

Remote Control Leds

Copy of IR Remote Toggles 10 LEDs.png
How to control LEDs with arduino, IR sensor and remote

check tinkercad circuit and simulation

https://www.tinkercad.com/things/aAtvMm2DffW-copy-of-ir-remote-toggles-10-leds/editel?sharecode=zAkE7Ulxv-TAesz5hKbdIe9DuATwFwZbK4fMcdkKtME

How Does It Work?

Screenshot 2021-07-19 182704.png

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

Screenshot 2021-07-19 183108.png

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.Connect the signal pin on the IR sensor to pin 8 on the Arduino.

Arduino Code

#include #define first_key 48703 #define second_key 58359 #define third_key 539 #define fourth_key 25979 int receiver_pin = 8; int first_led_pin = 7; int second_led_pin = 6; int third_led_pin = 5; int fourth_led_pin = 4; int led[] = {0,0,0,0}; IRrecv receiver(receiver_pin); decode_results output; void setup() { Serial.begin(9600); receiver.enableIRIn(); pinMode(first_led_pin, OUTPUT); pinMode(second_led_pin, OUTPUT); pinMode(third_led_pin, OUTPUT); pinMode(fourth_led_pin, OUTPUT); } void loop() { if (receiver.decode(&output)) { unsigned int value = output.value; switch(value) { case first_key: if(led[1] == 1) { digitalWrite(first_led_pin, LOW); led[1] = 0; } else { digitalWrite(first_led_pin, HIGH); led[1] = 1; } break; case second_key: if(led[2] == 1) { digitalWrite(second_led_pin, LOW); led[2] = 0; } else { digitalWrite(second_led_pin, HIGH); led[2] = 1; } break; case third_key: if(led[3] == 1) { digitalWrite(third_led_pin, LOW); led[3] = 0; } else { digitalWrite(third_led_pin, HIGH); led[3] = 1; } break; case fourth_key: if(led[4] == 1) { digitalWrite(fourth_led_pin, LOW); led[4] = 0; } else { digitalWrite(fourth_led_pin, HIGH); led[4] = 1; } break; } Serial.println(value); receiver.resume(); } }

Note

after you upload the code you should first open the serial monitor to know the serial number for each remote number then make changes on code