Skip to content

Instantly share code, notes, and snippets.

@Blaxdemir
Created May 29, 2022 21:22
Show Gist options
  • Save Blaxdemir/0f20adf334bf76de054d542754268ef1 to your computer and use it in GitHub Desktop.
Save Blaxdemir/0f20adf334bf76de054d542754268ef1 to your computer and use it in GitHub Desktop.
#include <IRremote.hpp>
#define RELAY_PIN 5
#define IR_RECEIVER_PIN 2
long last = millis();
relay_state = LOW;
IRrecv irrecv(IR_RECEIVER_PIN, ENABLE_LED_FEEDBACK);
void setup() {
Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT);
pinMode(IR_RECEIVER_PIN, OUTPUT);
irrecv.enableIRIn();
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
if (irrecv.decode()){
int command = irrecv.decodedIRData.command;
if (command == 8){
if (millis() - last < 500){
relay_state = !relay_state;
digitalWrite(RELAY_PIN,relay_state);
last = millis();
}
}
irrecv.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment