Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Infrared Remote using Arduino UNO help.

Status
Not open for further replies.

peter_england

Full Member level 4
Full Member level 4
Joined
Jul 24, 2012
Messages
199
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Visit site
Activity points
2,478
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 ---------------------------------------------------------------------
 

Inside setup() making relays low will work..
and to memorise which relay was on before power off we can use inbuilt EEPROM..;-)
 

Hey Hi, ANJ your reply sounds interesting pls tell how to memories the states of relay .. I am waiting your reply and the "Inside setup() making relays low will work.." actually worked for me but tell me some more about EEPROM saving the state of relay.
 

I had heard some problem, about long time delay error . I's guess there many way to cope with probelm by many cause , many method form manufacture company .


Like , An error in Turboc 2.0 that there are missing parts of compiler on website . I think that we could not check compiler program so we must investigate the time to collect symptom by own .
 

Hello Everybody.

I am New Here From Aluminum Parts india Company. We Provide Custom word Wide Aluminum Parts india service as per client requirement. So if you have any question about that are welcome.

Thanks.
 

Hi... peter_england.. thanks. :smile:
as you should probably knowing that ATmega328 has inbuilt 512 bytes of EEPROM.
so there will be total 512 variable can be saved and for using it in relay purpose you can store your flag status inside EEPROM and
inside void you can read it again and drive relay accordingly. hope I've not confused you.. ;-)
let me know if you want furthur help..
regards ANJ. :smile:
 
Thanks anj,, Can you give me example of Saving state to EEPROM , for my following code ? This code is working perfectly for my project so pls give some example for that code .. Thanks for giving ur time.

THE code is starts from Here ----------------------------------------

#include <IRremote.h>

int RECV_PIN = 11;
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;

int on = 0;
int on1 = 0;
int on2 = 0;
int on3 = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
digitalWrite(relay4, HIGH);
pinMode(relay4, OUTPUT);

digitalWrite(relay3, HIGH);
pinMode(relay3, OUTPUT);

digitalWrite(relay2, HIGH);
pinMode(relay2, OUTPUT);


digitalWrite(relay1, HIGH);
pinMode(relay1, OUTPUT);

pinMode(13, HIGH);



irrecv.enableIRIn(); // Start the receiver
}


unsigned long last = millis();

void loop() {
if (irrecv.decode(&results))
{
if (results.value == 0x61D6807F)
{ // 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();
}
//EXTRA CODE FROM HERE FOR TESTING WITH OTHER REMOTE CONTROLS

if (irrecv.decode(&results))
{
if (results.value == 0x61D640DF)
{ // 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();
}

//EXTRA CODE UPTO HERE FOR TESTING WITH OTHER REMOTE CONTROLS



else if (results.value == 0x61D640BF)
{
if (millis() - last > 250)
{
on1 = !on1;
digitalWrite(relay2, 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 Ends here ----------------------------------------------------
 

Thanks :smile:
ok. for your code it seems you are toggling the relays whenever particular code comes through IR.
so, this can be done in this way: let's select addresses 1,2,3 & 4 of EEPROM out of 0 to 512.(all values inside EEPROM are initially zero).
now dedicate address 1 for relay1, 2 for relay2 and so on.
you have to include library <EEPROM.h> too in your code.
(I am considering your relays are active HIGH.).
when IR code comes to toggle relay1 you have to write variable on1 in address 1 of EEPROM like this:
EEPROM.write(1,on1);
so if relay is on then value of EEPROM(1) will be one.(since it's active on HIGH)
now inside setup you will read this value and make relay on/off like this:

if(EEPROM.read(1)==1)
{
on1=1;
digitalWrite(relay1,on1);
}

no need to make off beacause it's alredy made LOW (in your case you have made it HIGH why? is it active LOW??).
same thing for relay 2,3 and 4.
you have to made some changes in variables and other methods which is yup, not a big issue. ;-)
so it will be like this:

Code:
#include <EEPROM.h>

#include <IRremote.h>

int RECV_PIN = 11;
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;

int on4 = 0; // taking this variables for each relay 1,2,3 & 4
int on1 = 0;
int on2 = 0;
int on3 = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
digitalWrite(relay4,LOW);
pinMode(relay4, OUTPUT);

digitalWrite(relay3, LOW);
pinMode(relay3, OUTPUT);

digitalWrite(relay2, LOW);
pinMode(relay2, OUTPUT);


digitalWrite(relay1, LOW);
pinMode(relay1, OUTPUT);

pinMode(13, HIGH);

    if(EEPROM.read(1)==1)
   {    
        on1=1;    
        digitalWrite(relay1,on1);
   }
       if(EEPROM.read(2)==1)
   {    
        on2=1;    
        digitalWrite(relay2,on1);
   }
       if(EEPROM.read(3)==1)
   {    
        on3=1;    
        digitalWrite(relay3,on1);
   }
       if(EEPROM.read(4)==1)
   {    
        on4=1;    
        digitalWrite(relay4,on4);
   }



irrecv.enableIRIn(); // Start the receiver
}


unsigned long last = millis();

void loop() {
if (irrecv.decode(&results))
{
if (results.value == 0x61D6807F) 
{ // 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) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();
} 
//EXTRA CODE FROM HERE FOR TESTING WITH OTHER REMOTE CONTROLS

if (irrecv.decode(&results))
{
if (results.value == 0x61D640DF) 
{ // 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) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();
} 

//EXTRA CODE UPTO HERE FOR TESTING WITH OTHER REMOTE CONTROLS



else if (results.value == 0x61D640BF) 
{
if (millis() - last > 250) 
{
on2 = !on2;
digitalWrite(relay2, on2 ? HIGH : LOW);
EEPROM.write(2,on2);
}
last = millis();
}


else if (results.value == 0x40BD28D7 ) 
{
if (millis() - last > 250) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();




}


else if (results.value == 0x61D6609F) 
{
if (millis() - last > 250) 
{
on4 = !on4;
digitalWrite(relay4, on4 ? HIGH : LOW);
EEPROM.write(4,on4);
}
last = millis();

}
irrecv.resume(); // Receive the next value
}
}}
 

Thanks for efforts but what i check in my case, you are right :smile:; its active low means i need to change your code to high at void setup() if i am not changing this the relay get auto ON after power on or reset . and after changing that code, the state of relay is not remain saved and after new start it goes OFF .pls check this .

- - - Updated - - -

and please change code so that i can see what is going in EEPROM memory i think its possible to make visible the status of EEPROM addresses through serial monitor. I think we use the EEPROM Read method for this (actually i checked that :smile: and see the two states of 1 and 2 to HIGH (1) but not sure because i cant mix two codes of our relay code and EEPROM Read Example from arduino IDE. Thanks in advanced . )
 

ok.. for active low relays we have to write all the EEPROM values to '1' so on your arduino you have to run this code once. before loading relay program on it.
making EEPROM values '1':
Code:
#include <EEPROM.h>

void setup()
{
  // write a 0 to all 512 bytes of the EEPROM
  for (int i = 0; i < 512; i++)
{
    EEPROM.write(i, 1);
 }  
  // turn the LED on when we're done
  digitalWrite(13, HIGH);
}

void loop()
{
}

then load the relay program:
Code:
#include <EEPROM.h>

#include <IRremote.h>

int RECV_PIN = 11;
int relay1 = 2;
int relay2 = 3;
int relay3 = 4;
int relay4 = 5;

 // taking this variables for each relay 1,2,3 & 4
int on1 = 0;
int on2 = 0;
int on3 = 0;
int on4 = 0;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
digitalWrite(relay4,HIGH);
pinMode(relay4, OUTPUT);

digitalWrite(relay3,HIGH);
pinMode(relay3, OUTPUT);

digitalWrite(relay2,HIGH);
pinMode(relay2, OUTPUT);


digitalWrite(relay1,HIGH);
pinMode(relay1, OUTPUT);

pinMode(13, HIGH);

    if(EEPROM.read(1)==0)
   {    
        on1=1;    
        digitalWrite(relay1,on1);
   }
       if(EEPROM.read(2)==0)
   {    
        on2=0;    
        digitalWrite(relay2,on1);
   }
       if(EEPROM.read(3)==0)
   {    
        on3=0;    
        digitalWrite(relay3,on1);
   }
       if(EEPROM.read(4)==0)
   {    
        on4=0;    
        digitalWrite(relay4,on4);
   }



irrecv.enableIRIn(); // Start the receiver
}


unsigned long last = millis();

void loop() {
if (irrecv.decode(&results))
{
if (results.value == 0x61D6807F) 
{ // 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) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();
} 
//EXTRA CODE FROM HERE FOR TESTING WITH OTHER REMOTE CONTROLS

if (irrecv.decode(&results))
{
if (results.value == 0x61D640DF) 
{ // 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) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();
} 

//EXTRA CODE UPTO HERE FOR TESTING WITH OTHER REMOTE CONTROLS



else if (results.value == 0x61D640BF) 
{
if (millis() - last > 250) 
{
on2 = !on2;
digitalWrite(relay2, on2 ? HIGH : LOW);
EEPROM.write(2,on2);
}
last = millis();
}


else if (results.value == 0x40BD28D7 ) 
{
if (millis() - last > 250) 
{
on1 = !on1;
digitalWrite(relay1, on1 ? HIGH : LOW);
EEPROM.write(1,on1);
}
last = millis();




}


else if (results.value == 0x61D6609F) 
{
if (millis() - last > 250) 
{
on4 = !on4;
digitalWrite(relay4, on4 ? HIGH : LOW);
EEPROM.write(4,on4);
}
last = millis();

}
irrecv.resume(); // Receive the next value
}
}}
yes we can watch EEPROM values serially to by using serial library.. no need to explain that since you have already done that..cool.. :cool:
I don't understand what this means...tell me what's this in your code. what you want to do by this?? :roll:
Code:
digitalWrite(relay1, on ? HIGH : LOW);
 
Hi Thanks for Help : as you write , if i remove that line of code relay is not working .and actually i have get this code from some website and I am just learning things in Arduino coding .. Can i give you a video of what i am doing ?? thanks.
 

always welcome..:-D
of course we can get from websites which is the best feature of an open source prototype. video can explain your intentions that what you want to do with relay..
yes we can change that part of code too.. I've operated relay like this:
when a switch on/off is pressed on remote then relay gets toggled that is once it's on and next time it will be off..
but there was simply digital write function without ' ? HIGH:LOW'...
regards
ANJ
 

Bad News,,:-( today i have mistakenly connected IR receiver IC PC3388 Ground pin to vcc3.3v and vcc pin to Ground of Arduino and after that its not working at all.:-(
I think I have broken the IC by changing its Supply pins. very sad. now i am searching that ic some where in local.
 

You may buy every parts from same company and version. Or, Consult you manual of Arduino Board for compatible equipments in warranty period.


If there are hard to contract with Arduino Board's company, May modify Arduno board: hardware or software programming in law & safty.

STUDY TERM OF OPERATIONS !!!!!!!!
 
Thanks ,phongphanp actually i haven't purchased it from Arduino Makers but its salvaged from OLD not working TV Tuner Card. I am searching anyways.

- - - Updated - - -

Hey Hi anj I am From India , Maharashtra. and I am searching the part here in Local electronics Stores. Thanks for advice also can you Give your some time for my new Question ? actually i am come across the GOBETWINO Software and i its working proper but i need do some changes in that and want to send some sensor data from Arduino over serial to pc but get stuck at code part.

- - - Updated - - -

following is the code for Example :---
______________________________________________________________________

int led = 13;


void setup() {

pinMode(led, OUTPUT);
Serial.begin(9600);
}


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(5000); // wait for a second
Serial.println("#S|TRIGGER|[]#");

}

-----------------------------------------------------------------------------------------

What it does actually :- when Arduino blinks Led on pin13 it sends the "#S|TRIGGER|[]#" command over serial and The Software on PC Detects it and do some already set task like sending mail . in my case the mail goes proper in this example but i want some sensor data get send in mail. how to do this ?? Sorry The software I am using is GOBETWINO.
 

That may about parameters configuration , or you must use the another set of command or you must review source code and/or Hex file, again. (By the different compiler) . Try to study all I think.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top