Infrared (IR) light is not visible to the human eye, but this project will make you believe in it! Using a simple IR receiving module, this project will make just about any of your projects wireless.
Check out this link for more reading on the science of receiving and decoding IR signals: https://learn.sparkfun.com/tutorials/ir-communication
Materials
Robotlinking IR Receiver Module
Car MP3 IR Transmitter
Arduino Uno
Assorted Wires
Wiring for the Receiver
Arduino
IR Receiver
GND
Pin G
5V
Pin R
Pin 11
Pin Y
Basic Code for the Receiver
/*-----( Import needed libraries )-----*/
#include "IRremote.h"
/*-----( Declare Constants )-----*/
int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results' /*-----( Declare Variables )-----*/
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600);
Serial.println("IR Receiver Raw Data + Button Decode Test");
irrecv.enableIRIn(); // Start the receiver
}
void loop() { /*----( LOOP: RUNS CONSTANTLY )----*/
if (irrecv.decode(&results)) // have we received an IR signal? {
Serial.print(results.value, HEX); //raw value
Serial.print("/t");
Serial.print("-->");
translateIR();
irrecv.resume(); // receive the next value
}/* --(end main loop )-- */
/*-----( Declare User-written Functions )-----*/
void translateIR() // takes action based on IR code received // describing Car MP3 IR codes
{
switch (results.value)
{
case 0xFFA25D:
Serial.println(" CH- ");
break;
case 0xFF629D:
Serial.println(" CH ");
break;
case 0xFFE21D:
Serial.println(" CH+ ");
break;
case 0xFF22DD:
Serial.println(" PREV ");
break;
case 0xFF02FD:
Serial.println(" NEXT ");
break;
case 0xFFC23D:
Serial.println(" PLAY/PAUSE ");
break;
case 0xFFE01F:
Serial.println(" VOL- "); break;
case 0xFFA857:
Serial.println(" VOL+ "); break;
case 0xFF906F:
Serial.println(" EQ "); break;
case 0xFF6897:
Serial.println(" 0 "); break;
case 0xFF9867:
Serial.println(" 100+ "); break;
case 0xFFB04F:
Serial.println(" 200+ "); break;
case 0xFF30CF:
Serial.println(" 1 "); break;
case 0xFF18E7:
Serial.println(" 2 "); break;
case 0xFF7A85:
Serial.println(" 3 "); break;
case 0xFF10EF:
Serial.println(" 4 "); break;
case 0xFF38C7:
Serial.println(" 5 "); break;
case 0xFF5AA5:
Serial.println(" 6 "); break;
case 0xFF42BD:
Serial.println(" 7 "); break;
case 0xFF4AB5:
Serial.println(" 8 "); break;
case 0xFF52AD:
Serial.println(" 9 "); break;
default:
Serial.println(" other button ");
}
delay(500);
} //END translateIR
Project 1: Turn an LED ON/OFF
LED Wiring:
Additional Code:
In the above code, you want to insert some decision making blocks in the main loop of your code in between the lines:
“translateIR();” and “irrecv.resume();”
Try something like this…
if(results.value ==0xFFC23D)
{
digitalWrite(13,HIGH);
}
if(results.value==0xFF6897)
{
digitalWrite(13,LOW);
}
Suggested Extras
- Add an ON/OFF switch to any project you are working on. - Control a servo’s position remotely.