Mission 17 - Infrared Code Detector
 DuinoKit Jr. - View Only. See new "Mission Manual" forum for manual and code   Started by Daniel Alich   2017-06-27 17:46:30 -04:00   Comments: 1    Viewed: 1229

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1498599904_Mission 17-1.jpg
    252_1498599892_Mission 17-2.jpg
    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

    Daniel Alich, 2017-06-27 17:46:30 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!