Hey there,
located below is my code. I am attempting to turn on and off 4 relays with my Arduino & Seed studio relay shield first version. I am able to press the first button the the remote and turn on the first relay but the last 3 don’t do anything. the 5th button towards the end of the code turns off all the relays successfully. Can anyone determine a solution or help out. The end goal is to make it so 4 buttons turn on and off individual relays.
Thank You!
Chris
#include <IRremote.h>
int RECV_PIN = 11;
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;
int on = 1;
int on1 = 0;
int on2 = 0;
int on3 = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(relay4, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay1, OUTPUT);
pinMode(13, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
unsigned long last = millis();
void loop() {
if (irrecv.decode(&results))
{
if (results.value == 551505585)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay4, HIGH);
}
last = millis();
}
else if (results.value == 551521905)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}
else if (results.value == 551519865)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay4, HIGH);
}
last = millis();
}
else if (results.value == 551494365)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
}
last = millis();
}
irrecv.resume(); // Receive the next value
}
}
}