/* Arduino Projects for Dummies * by Brock Craft * * Chapter 14: Building a Remote Controlled Car * Detects signals from a garden variety remote control * to drive two servo motors. * * This code is only for decoding your IR remote control * * Uses the standard Arduino servo library and * the IR Remote Library by Ken Shirriff: * https://github.com/shirriff/Arduino-IRremote * Adapted from code by Michael Margolis * * v0.1 30.04.2013 */ #include const int irReceivePin = 2; // Pin connected to IR detector output IRrecv irrecv(irReceivePin); // create the IR library decode_results results; // IR results are stored here void setup() { Serial.begin(9600); // Start the serial port irrecv.enableIRIn(); // Start the IR receiver } void loop() { if( irrecv.decode(&results) ) { showReceivedData(); irrecv.resume(); // Receive the next value } delay(250); } void showReceivedData() { if (results.decode_type == UNKNOWN) { Serial.println("-Could not decode message"); } 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: "); } Serial.print("Value = "); Serial.println(results.value, DEC); // Print the results as a decimal value } }