Introduction
In my
previous article, I explained how we can control led using a button. In this article, I'll show you how can we use remote control using Arduino UNO.
Requirements
- Arduino
- IR sensor
- Bread Board
- IR Remote
- Led
- Jumper wires
Connection
Step 1: Connect the Arduino board to the pc using the USB cable.
Step 2: Fix the led and IR sensor on the breadboard.
Step 3: IR sensor connection.
Figure 1: IR Sensor
Step 4: Connect the IR Sensor to the Arduino board
Vin -3pin, Gnd - Gnd and Vcc - 5v.
Step 5: Connect the led to the Arduino board Anode pin - 13pin and Cathode pin to the Gnd.
Programming
- # include < IR.Remote.h >
- int RECV_PIN = 3;
- Iint led = 13;
- int its ONled[] = {2};
- int ledstates[] = {0,0};
- # define code1 22695
- IRrec irrecv(RECV PIN);
- decode_results.results;
- void setup()
- {
- serial.begin(9600);
- irrecv.enableIRIn();
- pinMode(led, OUTPUT);
- }
- void loop()
- {
- if (irrecv.decode(results))
- {
- unsigned int value = results.value;
- switch (value)
- {
- case code1:
- if (itsONled[1] == 1)
- {
- digitalWrite(led, LOW);
- itsONled[1] = 0;
- }
- else
- {
- digitalWrite(led, HIGH);
- itsONled[1] = 1;
- }
- break;
- }
- serial.println(value);
- Irrec resume();
- }
- }
IR REMOTE FUNCTION:
Figure 2: IR Remote
Step 1: To use the
IR REMOTE we have to download the
IR LIBRARY
Step 2: Click to download the library -
IR Arduino library
Step 3: Add the library to the Arduino software library.
Explanation
Press any button and see the code value in the serial monitor, copy the code, and sketch the code in the program. We can add many LEDs in the connection. If we press the first button the led can be
ON. Then on pressing another button, the first led is ON and second led
TURN ON. We can add other LEDs and it can be changed in the switch() function. We can control the
TV, AC by using the remote.