peter_england
Full Member level 4
I need Help :- I am working on project of Infrared Remote control for controlling 2 relay Board. I am using TV Tuner Cards remote for Controlling the Relay , I have done all things like Extracting raw code for Remote Controller, coding the ARDUINO UNO , wiring the sensor on breadboard and tested project for working, it's working but the problem is when i shutdown the arduino and restart it's power the two relays goes ON automatically when i press specific key on Remote Controller it's toggles ON / OFF as expected but when reboot or Cold start ';; the relay get ON automatic.. Please tell why this getting happened. Below is the Code i am using .
//---------------------------------------CODE FROM HERE -----------------------------------------------------------------------------------------------
#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 == 0x61D648B7)
{ // Remote Control Power Code
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250)
{
on = !on;
digitalWrite(relay1, on ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x61D638C7)
{
if (millis() - last > 250)
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x40BD28D7 )
{
if (millis() - last > 250)
{
on2 = !on2;
digitalWrite(relay1, on2 ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x61D6609F)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay4, on3 ? HIGH : LOW);
}
last = millis();
}
irrecv.resume(); // Receive the next value
}
}
//---------------------------------------------------CODE END ---------------------------------------------------------------------
//---------------------------------------CODE FROM HERE -----------------------------------------------------------------------------------------------
#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 == 0x61D648B7)
{ // Remote Control Power Code
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250)
{
on = !on;
digitalWrite(relay1, on ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x61D638C7)
{
if (millis() - last > 250)
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x40BD28D7 )
{
if (millis() - last > 250)
{
on2 = !on2;
digitalWrite(relay1, on2 ? HIGH : LOW);
}
last = millis();
}
else if (results.value == 0x61D6609F)
{
if (millis() - last > 250)
{
on3 = !on3;
digitalWrite(relay4, on3 ? HIGH : LOW);
}
last = millis();
}
irrecv.resume(); // Receive the next value
}
}
//---------------------------------------------------CODE END ---------------------------------------------------------------------