1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/* * 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> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { long int decCode = results.value; String hexCode = String(decCode, HEX); String decodedSignal = decodeSignal(hexCode); if(decodedSignal != "unknown") { Serial.print("dec: "); Serial.print(hexCode); Serial.print("|"); Serial.print(decCode); Serial.print("|"); Serial.print(decodedSignal); Serial.println(); } // Serial.println(, HEX); irrecv.resume(); // Receive the next value } } String decodeSignal(String hex) { hex.toUpperCase(); if(hex == "FFA25D") return "power"; if(hex == "FF629D") return "mode"; if(hex == "FFE21D") return "mute"; if(hex == "FF22DD") return "play"; if(hex == "FF02FD") return "rewind"; if(hex == "FFC23D") return "forward"; if(hex == "FFE01F") return "eq"; if(hex == "FFA857") return "-"; if(hex == "FF906F") return "+"; if(hex == "FF6897") return "0"; if(hex == "FF9867") return "repeat"; if(hex == "FFB04F") return "usd"; if(hex == "FF30CF") return "1"; if(hex == "FF18E7") return "2"; if(hex == "FF7A85") return "3"; if(hex == "FF10EF") return "4"; if(hex == "FF38C7") return "5"; if(hex == "FF5AA5") return "6"; if(hex == "FF42BD") return "7"; if(hex == "FF4AB5") return "8"; if(hex == "FF52AD") return "9"; return "unknown"; } |
Receive IR value with Arduino
You need
Download Arduino-IRremote-master from git hub, move to library folder under arduino.
Also make sure you are using Arduino 1.0.5, latest beta 2.x not working with this IR library.
I am using infrared receiver module manufactured by keyes, come together with an IR mp3 remote control and a nomral LED, purchase from dx.com at usd4.
At the time of writing, dx.com have a new product pack where it comes with a slightly different mp3 remote controller, same infrared receiver module and an extra infrared emitter module (for sending). The price is only usd5.8.
Validate IR remote control is working
Human can’t see IR light with naked eye. How can we validate the remote control is actually functioning?
Fortunately, you can check infra-red with a smart phone camera. Latest iphone have IR filter so it will fail, but I tested on samsung galaxy s3 and works.
The IR receiver
According to dx.com spec, the receiver sensor adopt HX1838, high sensitivity; Working voltage: 5V; Testing distance: 5~8m;
Construct the circuit
The circuit is very simple.
Once you have IRremote library installed, your will beable to get the example thru arduino ide interface. Open File->Examples->IRremote->IRRecvDemo
I enhanced it by adding a function decodeSignal to transform IR value into meaningful value like button 1, 2, 3, power, mute…