Hi I am currently working on a little home automation project where I am using an old VHS remote for the control of the power to the outlets in my room as well as my ceiling fan/light by toggling a relay.
Currently I press the power button on the remote to turn on the power to the outlets and press the eject button to turn it back off.
I have tried to figure it out on my own and have sadly failed but my goal is to be able to use the same button to turn on and off the power. If anyone has some suggestions or advice with the code I'd love to hear it, Thanks
Here is the basic code I have so far that just toggles the lights as well as the power.
#include <IRremote.h>//includes IR library
int RECV_PIN = 11; //IR input
int Light1 = 7; // Pin 7 used for relay
int Light2 = 6; // Pin 6 used for relay
int Power = 5; // pin 5 used for relay
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
irrecv.enableIRIn(); // Start the receiver
pinMode(Light1, OUTPUT); // declare pin 7 to be an output
pinMode(Light2, OUTPUT); // declare pin 6 to be an output
pinMode(Power, OUTPUT); // declares pin 5 as an output
}
void loop()
{
if (irrecv.decode(&results)) //revieves IR info
{
irrecv.resume(); // Receive the next value
}
delay(100);
if (results.value == 31377463)//if power button is hit then do the following
{
digitalWrite(Power,HIGH);
}
if(results.value == 31355533)//if eject button is pressed turn off power
{
digitalWrite(Power,LOW);//turn off power
}
if (results.value == 31352983)//if play button is hit then do the following
{
digitalWrite(Light1,HIGH);//turn on wire 1
digitalWrite(Light2,HIGH);//turn on wire 2
}
if (results.value == 31385623)//if stop button is hit then do the following
{
digitalWrite(Light1,LOW);//turn off wire 1
digitalWrite(Light2,LOW);//turn off wire 2
}
I know it may seem simple to you but it isn't to me so if you can help thanks if not that's fine.