1 /* Arduino Projects for Dummies
4 * Chapter 14: Building a Remote Controlled Car
5 * Detects signals from a garden variety remote control
6 * to drive two servo motors.
8 * This code is only for decoding your IR remote control
10 * Uses the standard Arduino servo library and
11 * the IR Remote Library by Ken Shirriff:
12 * https://github.com/shirriff/Arduino-IRremote
13 * Adapted from code by Michael Margolis
21 const int irReceivePin = 2; // Pin connected to IR detector output
22 IRrecv irrecv(irReceivePin); // create the IR library
23 decode_results results; // IR results are stored here
27 Serial.begin(9600); // Start the serial port
28 irrecv.enableIRIn(); // Start the IR receiver
32 if( irrecv.decode(&results) )
35 irrecv.resume(); // Receive the next value
40 void showReceivedData()
42 if (results.decode_type == UNKNOWN)
44 Serial.println("-Could not decode message");
48 if (results.decode_type == NEC) {
49 Serial.print("- decoded NEC: ");
51 else if (results.decode_type == SONY) {
52 Serial.print("- decoded SONY: ");
54 else if (results.decode_type == RC5) {
55 Serial.print("- decoded RC5: ");
57 else if (results.decode_type == RC6) {
58 Serial.print("- decoded RC6: ");
60 Serial.print("Value = ");
61 Serial.println(results.value, DEC); // Print the results as a decimal value