Arduino IR Remort Sensor
Arduino IR Remort Sensor
In this project you’ll use an infrared (IR) receiver and an Arduino to control 3 LEDs with a remote control. This is
useful to re-use old remote controls or give some functionally to some of your remote’s buttons.
Parts required
To follow this project you need the following parts:
Arduino UNO – read Best Arduino Starter Kits
1x Breadboard
1x Remote control
1x IR receiver ( I’ll be using TSOP4838)
3x LED’s
3x 220 Ohm resistors
Jumper wires
Each button sends specific information. So, we can assign that information to a specific button.
Schematics
Connect the IR receiver accordingly to the schematics below.
Code
To control the IR receiver, you need to install the IRremote Library in the Arduino IDE.
Copy the following code to your Arduino IDE, and upload it to your Arduino board. Make sure that you have the right
board and COM port selected.
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
In this project you want to control 3 LEDs. Choose 6 buttons for the following tasks:
1. LED1 – ON
2. LED1 – OFF
3. LED2 – ON
4. LED2 – OFF
5. LED3 – ON
6. LED3 – OFF
Press, for example, the button number 1 of your remote control. You should see a code on the serial monitor. Press
the same button several times to make sure you have the right code for that button. If you see something like
FFFFFFFF ignore it, it’s trash.
Write down the code associated with each button, because you’ll need that information later.
Building the final circuit
In this part, you’ll build the circuit with three LEDs that will be controlled using your remote.
Schematics
Assemble all the parts by following the schematics below.
Code
Now, grab the codes you captured in the previous step. You need to convert your codes from hex to decimal.
/*
* Modified by Rui Santos, http://randomnerdtutorialscom
* based on IRremote Library - Ken Shirriff
*/
#include <IRremote.h>
IRrecv irrecv(IR_Recv);
decode_results results;
void setup(){
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(bluePin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(yellowPin, OUTPUT); // sets the digital pin as output
void loop(){
//decodes the infrared input
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(results.value);
//switch case to use the selected remote control button
switch (results.value){
case 551520375: //when you press the 1 button
digitalWrite(bluePin, HIGH);
break;
case 551495895: //when you press the 4 button
digitalWrite(bluePin, LOW);
break;
case 551504055: //when you press the 2 button
digitalWrite(greenPin, HIGH);
break;
case 551528535: //when you press the 5 button
digitalWrite(greenPin, LOW);
break;
case 551536695: //when you press the 3 button
digitalWrite(yellowPin, HIGH);
break;
case 551512215: //when you press the 6 button
digitalWrite(yellowPin, LOW);
break;
}
irrecv.resume(); // Receives the next value from the button you press
}
delay(10);
}
Demonstration
In the end you can control each LED individually using the buttons of your remote control.