IR DECODER AND IR CONTROLLED LIGHT

ETHINGS
0

                                                    

IR DECODER


 #include <IRremote.h>


const int IR_RECEIVER_PIN = 2;

const int OUTPUT_PIN = 13;

const unsigned long DEBOUNCE_DELAY = 1000; // 1 second debounce delay


IRrecv irrecv(IR_RECEIVER_PIN);

decode_results results;

bool signalReceived = false;

unsigned long lastReceiveTime = 0;


void setup()

{

  pinMode(OUTPUT_PIN, OUTPUT);

  digitalWrite(OUTPUT_PIN, LOW);


  Serial.begin(9600);

  irrecv.enableIRIn(); // Start the IR receiver

}


void loop()

{

  if (irrecv.decode(&results))

  {

    unsigned long currentTime = millis();


    // Check if enough time has passed since the last IR signal was received

    if (currentTime - lastReceiveTime >= DEBOUNCE_DELAY)

    {

      // Check if the received signal matches the specific IR code

      if (results.value == 261063890) // Replace YOUR_IR_SIGNAL with the desired IR code

      {

        if (!signalReceived)

        {

          // If the signal is received for the first time, set the 8th pin to HIGH

          digitalWrite(OUTPUT_PIN, HIGH);

          signalReceived = true;

        }

        else

        {

          // If the signal is received again, set the 8th pin to LOW

          digitalWrite(OUTPUT_PIN, LOW);

          signalReceived = false;

        }

      }


      lastReceiveTime = currentTime; // Update the last received time

    }


    irrecv.resume(); // Receive the next value

  }

}


                               IR CONTROLLED LAMP

#include <IRremote.h>


const int IR_RECEIVER_PIN = 2;

const int OUTPUT_PIN = 13;

const unsigned long DEBOUNCE_DELAY = 1000; // 1 second debounce delay


IRrecv irrecv(IR_RECEIVER_PIN);

decode_results results;

bool signalReceived = false;

unsigned long lastReceiveTime = 0;


void setup()

{

  pinMode(OUTPUT_PIN, OUTPUT);

  digitalWrite(OUTPUT_PIN, LOW);


  Serial.begin(9600);

  irrecv.enableIRIn(); // Start the IR receiver

}


void loop()

{

  if (irrecv.decode(&results))

  {

    unsigned long currentTime = millis();


    // Check if enough time has passed since the last IR signal was received

    if (currentTime - lastReceiveTime >= DEBOUNCE_DELAY)

    {

      // Check if the received signal matches the specific IR code

      if (results.value == 261063890) // Replace YOUR_IR_SIGNAL with the desired IR code

      {

        if (!signalReceived)

        {

          // If the signal is received for the first time, set the 8th pin to HIGH

          digitalWrite(OUTPUT_PIN, HIGH);

          signalReceived = true;

        }

        else

        {

          // If the signal is received again, set the 8th pin to LOW

          digitalWrite(OUTPUT_PIN, LOW);

          signalReceived = false;

        }

      }


      lastReceiveTime = currentTime; // Update the last received time

    }


    irrecv.resume(); // Receive the next value

  }

}


Tags

Post a Comment

0Comments

Post a Comment (0)