Read infrared code with Arduino
10-11-2017
Description below.
Language or Platform: Arduino
Code:
// Reads IR remote code and displays hex code through serial
// If correct remote button is pressed, LED will light up for that
// specific code.
// Led1 on pin 13. Led2 on pin 12.
// Make sure proper resistors are placed with Leds.
// IR Led on pin 3. 180 Ohm resistor on anode.
// IR Reciever on pin 11. IR Receiver has 3 connections...
// Output, Ground, Power
#include <IRremote.h>
int RECV_PIN = 11;
// IR Receiver on pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
int led = 13;
int led2 = 12;
void setup()
{
pinMode(led, OUTPUT);
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
unsigned int value = results.value;
switch(value) {
case 0xFF30CF: // if button with this code is pressed
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
break;
case 0xFF18E7: // if button with this code is pressed
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
delay(1000);
break;
}
}
delay(100);
}
// Open Serial Monitor and push button on remote while pointed at
// IR Receiver
// Code will be displayed.
// Put 0x in front of code when using IR output program
// Example: 0x20DF10EF
Back