Skip to content

Instantly share code, notes, and snippets.

@gausie
Created February 4, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gausie/01578ebbe466396ad6a4da77bbf12205 to your computer and use it in GitHub Desktop.
Save gausie/01578ebbe466396ad6a4da77bbf12205 to your computer and use it in GitHub Desktop.
Script to on/off my Toshiba TV when I open/close the cupboard its in!
#include <IRremote.h>
IRsend irsend;
int avoidSensor = 2;
int lastAvoidState = 1; // 1 means clear, 0 means covered
void setup()
{
Serial.begin(9600);
pinMode(avoidSensor, INPUT);
}
void sendOnOffSignal() {
for (int i = 0; i < 3; i++) {
irsend.sendRC5(0x84C, 12);
delay(40);
}
}
void loop() {
int avoidState = digitalRead(avoidSensor);
if (avoidState != lastAvoidState) {
lastAvoidState = avoidState;
sendOnOffSignal();
}
delay(1);
}
@gausie
Copy link
Author

gausie commented Feb 4, 2017

Using a Keyes IR Transmitter and a Keyes Avoid Detector from a cheap box of knock-off sensors and transmitters I bought a few years ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment