Hi how to setup the arduino code to activate two led end one relay through ir remote with two button?
first push of button1 activate led1 after some sec push button 2 then activate led2 end relay,after 30 sec automatically shut down two led-s but relay stay active,to shut down relay push button1 end button2 relay off,after 30 sec automatically shut down two led-s Thanks!
Well first you need to get a sensor that will read an IR remote's output. Most use a 38kHz modulated signal in which case you would use something like this.
Then you would probably use a library to decode the signal so you can see what arrives at the Arduino so you can have your program look for and act on whatever value it is.
Get that part done first....
Yes I have 2 x led,1 ir rx,1 relay,1 arduino uno/pro mini v2,IRremote library,1 remote panasonic all its working fine but I dont know how to set the code?
it may be easiest to when I press the first button that lights up LED1 and when I press another button that lights up LED2 then the code turn relay on end after 30sec LED1 & LED2 off
if (digitalRead(1) == HIGH && digitalRead(2) == HIGH) { // read two switches to activate relay
// ...
}
#include <IRremote.h>
int RECV_PIN = 6; // the pin where you connect the output pin of TSOP4838
int led1 = 12;
int led2 = 11;
int relay = 8;
int itsONled[] = {0,0,0};
int itsONrelay[] = {0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 3812
// code received from button A
#define code2 17969
// code received from button B
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean relayOn = true;
void setup()
{
Serial.begin(9600); // you can comment this line
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(relay, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
if (digitalRead(12) == HIGH && digitalRead(11) == HIGH)
{
relayOn = true;
digitalWrite(relay, HIGH);
delay(100);
}
else
{
relayOn = false;
digitalWrite(relay, LOW);
delay(100);
}
break;
}
Serial.println(value); // you can comment this line
irrecv.resume(); // Receive the next value
}
}