Introduction
In this article I will explain about the controlling LED using IR Remote in Arduino Mega. The LED can be turned on/off using the remote control.
Parts of list
- Arduino Mega 2560
- IR Remote
- IR sensor
- Bread Board
- Hook Up Wires
- LED-3.
IR Remote and IR Sensor Function:
IR Remote:
Figure 1: IR Remote
Uses:
- Television
- DVD Players
- Audio Players
IR Sensor:
Figure 2: IR Sensor
- In this sensor is the main part of IR Remote.
- It will produce the signal to the remote.
- It can have the three pins Gnd, Vcc, Vin.
Connections:
Connection From the LED to the Arduino Mega 2560:
Take the THREE LED pin and fix in the breadboard.
First LED Connection:
- Positive pin = 02
- Negative Pin = Gnd
Second LED Connection:
- Positive pin =04.
- Negative Pin = Gnd
Third LED Connection:
- Positive pin =07
- Negative Pin = Gnd
Connection From the IR Sensor to the Arduino Mega 2560:
- The first pin is the Gnd pin connected to the Gnd of the Arduino Mega 2560.
- The second pin is the Vcc pin connected to the +5v of the Arduino Mega 2560.
- The third pin is the Vin pin connected to the digital pin 3 to the Arduino Mega 2560.
Programming:
- #include <IRremote.h>
- int RECV_PIN = 3;
- int led1 = 2;
- int led2 = 4;
- int led3 = 7;
- int itsONled[] = {0,0,0,0};
- #define code1 63495 // code received from button A
- #define code2 30855 // code received from button B
- #define code3 22695 // code received from button C
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- void setup()
- {
- Serial.begin(9600);
- irrecv.enableIRIn();
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- }
-
- void loop() {
- if (irrecv.decode(&results)) {
- unsigned int value = results.value;
- switch(value) {
- case code1:
- if(itsONled[1] == 1) {
- digitalWrite(led1, LOW);
- itsONled[1] = 0;
- } else {
- digitalWrite(led1, HIGH);
- itsONled[1] = 1;
- }
- break;
- case code2:
- if(itsONled[2] == 1) {
- digitalWrite(led2, LOW);
- itsONled[2] = 0;
- } else {
- digitalWrite(led2, HIGH);
- itsONled[2] = 1;
- }
- break;
- case code3:
- if(itsONled[3] == 1) {
- digitalWrite(led3, LOW);
- itsONled[3] = 0;
- } else {
- digitalWrite(led3, HIGH);
- itsONled[3] = 1;
- }
- break;
- }
- Serial.println(value);
- irrecv.resume();
- }
- }
- Before uploading the program add the library in the Arduino library.
- Click to add the library - IR Arduino library.
Explanation:
- In the section it can work under the remote control.
- To see the remote value press the button and see in the serial monitor.
- When we press button1 the led can be turn ON.
- When we press button2 the led can be turn ON.
- When we press button3 the led can be turn ON.
- Same process can be done for turning OFF the LED.
Output: Figure 3: Output
Read more articles on Arduino: