On the Image you can see 2 IR Receivers. Both work, the only difference is the board on the left also includes a led light that lids up when an infrared signal is being received. Very useful for your first projects as it will help you indicate that everything is correctly connected.
In the following picture you can see a setup that allows us to load the program to receive and send IR signals without changing components. Pin 2 is being used for receiving the IR signal. Pin 3 is being used to send IR signals.
Below I will leave you the programs to receive the Signals and another on how to Send the programs. At the end I will explain how to change a raw signal so it can be used in the sending program. So with the receiver receive a signal and then apply some changes and then use it in the sender program as you want.
Program to Receive IR Signals in Raw Format. Credits go to the author on this page https://sites.google.com/site/angmuz/home/proyecto-25-2-arduino-ir-receiver
/*
* IRremote: IRrecvDump - dump details of 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
* http://as3breeze.com/arduino-sending-samsung-ir-codes/
*/
#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
// decode_results *results = (decode_results *)v
void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.print("Unknown encoding: ");
}
else if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
else if (results->decode_type == PANASONIC) {
Serial.print("Decoded PANASONIC: ");
}
else if (results->decode_type == JVC) {
Serial.print("Decoded JVC: ");
}
else if (results->decode_type == SAMSUNG) {
Serial.print("Decoded SAMSUNG: ");
}
int val1 = results->value;
Serial.print(val1, HEX);
Serial.print(" (");
int valbits = results->bits;
Serial.print(valbits, DEC);
Serial.println(" bits)");
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
int valen = results->rawbuf[i]*USECPERTICK;
Serial.print(valen, DEC);
}
else {
int negvalen =-(int)results->rawbuf[i]*USECPERTICK;
Serial.print(negvalen, DEC);
}
Serial.print(", ");
}
Serial.println("");
}
void loop() {
if (irrecv.decode(&results)) {
int hexen = results.value;
Serial.println(hexen, HEX);
dump(&results);
irrecv.resume(); // Receive the next value
}
}
Program To send Raw signals. The example below will send some basic commands to the Conga Excelence floor cleaning robot.
#include <IRremote.h> // use the library
IRsend irsend;
unsigned int RobotPlay[67] = {9050, 4500, 600, 500, 600, 550, 600, 1650, 600, 1700, 600, 500, 650, 500, 600, 1650, 650, 500, 600, 1650, 650, 1650, 600, 550, 600, 500, 600, 1650, 650, 1650, 600, 550, 600, 1650, 600, 550, 600, 500, 600, 1700, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600, 1700, 600, 1650, 600, 1650, 600, 550, 600, 550, 600, 500, 600, 1700, 600, 500, 600, 550, 600};
unsigned int RobotHome[67] = {9050, 4450, 600, 550, 600, 550, 550, 1700, 600, 1650, 600, 550, 600, 550, 550, 1700, 600, 550, 550, 1700, 600, 1650, 600, 550, 600, 550, 550, 1700, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 550, 550, 1700, 600, 1650, 600, 1700, 550, 550, 600, 550, 600, 1650, 600, 1700, 550, 1700, 600, 550, 550, 550, 600, 550, 600, 1650, 600, 1700, 550, 550, 600};
unsigned int RobotMaxProgram[67] = {9050, 4500, 550, 550, 600, 550, 550, 1700, 600, 1700, 550, 550, 600, 550, 550, 1700, 600, 550, 550, 1700, 600, 1700, 550, 550, 600, 550, 550, 1700, 600, 1700, 550, 550, 600, 1700, 550, 550, 600, 550, 600, 550, 550, 1700, 600, 550, 550, 550, 600, 550, 600, 1650, 600, 1700, 550, 1700, 600, 1650, 600, 550, 600, 1650, 600, 1700, 550, 1700, 600, 550, 550};
unsigned int RobotCircleProgram[67] = {9050, 4450, 600, 550, 550, 550, 600, 1700, 550, 1700, 600, 550, 550, 550, 600, 1700, 550, 550, 600, 1700, 550, 1700, 600, 550, 550, 550, 600, 1700, 550, 1700, 600, 550, 550, 1700, 600, 550, 550, 600, 550, 550, 600, 550, 550, 600, 550, 550, 600, 550, 550, 1700, 600, 1700, 550, 1700, 550, 1700, 600, 1700, 550, 1700, 600, 1650, 600, 1700, 550, 550, 600};
unsigned int RobotSquareProgram[67] = {9050, 4500, 600, 550, 550, 550, 600, 1700, 600, 1650, 600, 550, 600, 500, 600, 1700, 550, 600, 550, 1700, 550, 1650, 600, 600, 550, 550, 600, 1700, 550, 1650, 650, 550, 550, 1700, 600, 550, 600, 1650,600, 550, 550, 550, 600, 550, 600, 550, 550, 550, 600, 1700, 550, 1700, 600, 550, 600, 1650, 600, 1700, 550, 1700, 550, 1700, 600, 1700, 550, 550, 600};
unsigned int Robotleft[67] = {9050, 4500, 550, 600, 550, 550, 600, 1700, 550, 1700, 550, 600, 550, 550, 600, 1700, 550, 550, 600, 1700, 550, 1700, 600, 550, 550, 550, 600, 1700, 550, 1700, 600, 550, 550, 1700, 600, 1650, 600, 550, 600, 550, 550, 1700, 600, 1650, 600, 550, 600, 550, 550, 550, 600, 550, 600, 1650, 600, 1700, 550, 550, 600, 550, 600, 1650, 600, 1700, 600, 1650, 600};
unsigned int Robotright[67] = {9050, 4450, 600, 550, 600, 550, 600, 1600, 650, 1650, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600, 1700, 600, 500, 600, 550, 600, 550, 600, 500, 600, 550, 600, 1650, 600, 550, 600, 550, 600, 1650, 600, 1650, 600, 1700, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600};
unsigned int Robotup[67] = {9050, 4450, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600};
unsigned int Robotdown[67] = {9050, 4450, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 1650, 600};
unsigned int RobotCornerProgram[67] = {9050, 4450, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 1650, 600, 1650, 650, 500, 600, 550, 600, 550, 600, 500, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 1700, 600, 1650, 600, 1650, 600, 1700, 600, 500, 600};
int canal = 0;
void setup()
{
Serial.begin(9600);
Serial.println("a: Start Robot");
Serial.println("b: Go Home Robot");
Serial.println("c: MAX Program Robot");
Serial.println("d: Circle Program Robot");
Serial.println("e: Square Program Robot");
Serial.println("f: Corner Program Robot");
Serial.println("4: Robot turn Left");
Serial.println("6: Robot turn Right");
Serial.println("8: Robot Go Up");
Serial.println("2: Robot Go Down");
}
void GoRobot()
{
irsend.sendRaw(RobotPlay,67,38);
delay(100);
}
void HomeRobot()
{
irsend.sendRaw(RobotHome,67,38);
delay(100);
}
void MaxProgramRobot()
{
irsend.sendRaw(RobotMaxProgram,67,38);
delay(100);
}
void CircleProgramRobot()
{
irsend.sendRaw(RobotCircleProgram,67,38);
delay(100);
}
void SquareProgramRobot()
{
irsend.sendRaw(RobotSquareProgram,67,38);
delay(100);
}
void CornerProgramRobot()
{
irsend.sendRaw(RobotCornerProgram,67,38);
delay(100);
}
void RobotLeft()
{
irsend.sendRaw(Robotleft,67,38);
delay(100);
}
void RobotRight()
{
irsend.sendRaw(Robotright,67,38);
delay(100);
}
void RobotUp()
{
irsend.sendRaw(Robotup,67,38);
delay(100);
}
void RobotDown()
{
irsend.sendRaw(Robotdown,67,38);
delay(100);
}
void loop() {
// @param1 Raw data
// @param2 length
// @param3 frequency, (most devices use 38khz)
if (Serial.available() > 0)
{
canal = Serial.read();
switch(canal)
{
case 97: //tecla A
GoRobot();
GoRobot();
GoRobot();
Serial.println("Start Robot");
break;
case 98: //tecla B
HomeRobot();
HomeRobot();
HomeRobot();
Serial.println("Go Home Robot");
break;
case 99: //tecla C
MaxProgramRobot();
MaxProgramRobot();
MaxProgramRobot();
Serial.println("MAX Program Robot");
break;
case 100: //tecla D
CircleProgramRobot();
CircleProgramRobot();
CircleProgramRobot();
Serial.println("Circle Program Robot");
break;
case 101: //tecla E
SquareProgramRobot();
SquareProgramRobot();
SquareProgramRobot();
Serial.println("Square Program Robot");
break;
case 102: //tecla F
CornerProgramRobot();
CornerProgramRobot();
CornerProgramRobot();
Serial.println("Corner Program Robot");
break;
case 52: //tecla 4
RobotLeft();
RobotLeft();
RobotLeft();
Serial.println("Robot turn Left");
break;
case 54 : //tecla 6
RobotRight();
RobotRight();
RobotRight();
Serial.println("Robot turn Right");
break;
case 56: //tecla 8
RobotUp();
RobotUp();
RobotUp();
Serial.println("Robot Go Up");
break;
case 50: //tecla 2
RobotDown();
RobotDown();
RobotDown();
Serial.println("Robot Go Down");
break;
}
}
}
In the following steps I will explain how to convert a code received like this in a format for the sender program. So for example the following code is being received:
FFFF817E
Decoded NEC: FFFF817E (32 bits)
Raw (68): -20800, 9050, -4450, 600, -550, 600, -500, 650, -1650, 600, -1650, 600, -550, 600, -500, 650, -1650, 600, -550, 600, -1650, 600, -1650, 600, -550, 600, -500, 650, -1650, 600, -1650, 600, -550, 600, -1650, 600, -1650, 650, -500, 600, -550, 600, -550, 600, -500, 600, -550, 600, -550, 600, -1650, 600, -550, 600, -1650, 600, -1650, 600, -1700, 600, -1650, 600, -1650, 600, -1700, 600, -500, 600,
Then to use this code remove the first number. In this example -20800
9050, -4450, 600, -550, 600, -500, 650, -1650, 600, -1650, 600, -550, 600, -500, 650, -1650, 600, -550, 600, -1650, 600, -1650, 600, -550, 600, -500, 650, -1650, 600, -1650, 600, -550, 600, -1650, 600, -1650, 650, -500, 600, -550, 600, -550, 600, -500, 600, -550, 600, -550, 600, -1650, 600, -550, 600, -1650, 600, -1650, 600, -1700, 600, -1650, 600, -1650, 600, -1700, 600, -500, 600,
Then replace the negative numbers with a positive number (so -4450 will convert in 4450)
9050, 4450, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 1650, 600, 1650, 650, 500, 600, 550, 600, 550, 600, 500, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 1700, 600, 1650, 600, 1650, 600, 1700, 600, 500, 600,
Then put the field indicator in front of it and add also the brackets at the end and ; Also do not forget to indicate how many values you have because each remote control can have different amount of values
unsigned int RobotCornerProgram[67] = {9050, 4450, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 550, 600, 1650, 600, 1650, 600, 550, 600, 500, 650, 1650, 600, 1650, 600, 550, 600, 1650, 600, 1650, 650, 500, 600, 550, 600, 550, 600, 500, 600, 550, 600, 550, 600, 1650, 600, 550, 600, 1650, 600, 1650, 600, 1700, 600, 1650, 600, 1650, 600, 1700, 600, 500, 600};
Copy this line in the program and you now can use this code in the sender program.