Author Topic: Lesson 8 - IR Remote Control LED  (Read 891 times)

dalich

  • Administrator
  • Jr. Member
  • *****
  • Posts: 78
Lesson 8 - IR Remote Control LED
« on: June 28, 2016, 02:16:28 PM »
Lesson 8-1.bmp

Lesson 8-2.bmp

Code: [Select]
/*
 IR_remote_detector sketch
 An IR remote receiver is connected to pin 2.
 The LED on pin 13 toggles each time a button on the remote is pressed.
 Displays IR HEX code in serial monitor
 */

#include <IRremote.h>                    //adds the library code to the sketch

const int irReceiverPin = 2;             //pin the receiver is connected to
const int ledPin = 13;

IRrecv irrecv(irReceiverPin);            //create an IRrecv object
decode_results decodedSignal;            //stores results from IR detector

void setup()
{
  pinMode(ledPin, OUTPUT);
  irrecv.enableIRIn();      // Start the receiver object
  Serial.begin(9600);      // Open serial monitor


}

boolean lightState = false;     //keep track of whether the LED is on
unsigned long last = millis();  //remember when we last received an IR message

void loop()
{
  if (irrecv.decode(&decodedSignal) == true) //this is true if a message
      //has been received
  {
    if (millis() - last > 250) {       //has it been 1/4 sec since last message
      lightState = !lightState;              //toggle the LED
      digitalWrite(ledPin, lightState);
      Serial.println(decodedSignal.value, HEX);    //Display IR code in serial monitor
      irrecv.resume(); // Receive the next value



    }
    last = millis();
    irrecv.resume();                         // watch out for another message
  }
}



mbeise

  • Newbie
  • *
  • Posts: 1
Re: Lesson 8 - IR Remote Control LED
« Reply #1 on: January 16, 2017, 09:52:24 AM »
Hello-

My students are getting a compiling error for the code associated with this code.

The error says: int RECV_PIN =TKD2

we are running Arduino 1.7.11


dalich

  • Administrator
  • Jr. Member
  • *****
  • Posts: 78
Re: Lesson 8 - IR Remote Control LED
« Reply #2 on: January 18, 2017, 09:19:13 AM »
Try this new code.  I think this is now fixed.