Hi, Im using a infrared remote control to send signals to a arduino which then sends 433mhz signals out to control remote control mains sockets around the house. I
v got it all working but I wish to set a timer on certain sockets so when they turn on they will turn off after say 10 minutes but only on select sockets. Could anyone show me how this could be done when you push button 1 on the remote. So it would send the 433mhz turn on signal then wait 10 minutes then send the turn off signal. Thanks. Here is the code.
#include <RCSwitch.h>
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
RCSwitch mySwitch = RCSwitch();
byte state0 = 0;
byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
byte state6 = 0;
byte state7 = 0;
byte state8 = 0;
byte state9 = 0;
byte state10 = 0;
byte state11 = 0;
byte state12 = 0;
byte state13 = 0;
void setup(){
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Start the receiver
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.setPulseLength(189);
}
void loop(){
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
//switch case to use the selected remote control button
switch (results.value){
case 0xFF6897: //when you press the 1 button
if (state1 == 0) {
mySwitch.send(349491, 24); //(349491, 24);
}
else {
mySwitch.send(349500, 24); //(349500, 24);
}
state1 = !state1; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF9867: //when you press the 2 button
if (state2 == 0) {
mySwitch.send(349635, 24); //(349635, 24);
}
else {
mySwitch.send(349644, 24); //(349644, 24);
}
state2 = !state2; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFFB04F: //when you press the 3 button
if (state3 == 0) {
mySwitch.send(349955, 24); //(349955, 24);
}
else {
mySwitch.send(349964, 24); //(349964, 24);
}
state3 = !state3; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF30CF: //when you press the 4 button
if (state4 == 0) {
mySwitch.send(351491, 24); //(351491, 24);
}
else {
mySwitch.send(351500, 24); //(351500, 24);
}
state4 = !state4; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF18E7: //when you press the 5 button
if (state5 == 0) {
mySwitch.send(357635, 24); //(357635, 24);
}
else {
mySwitch.send(357644, 24); //(357644, 24);
}
state5 = !state5; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF7A85: //when you press the 6 button
if (state6 == 0) {
mySwitch.send(4543795, 24); //(4543795, 24);
}
else {
mySwitch.send(4543804, 24); //(4543804, 24);
}
state6 = !state6; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF10EF: //when you press the 7 button
if (state7 == 0) {
mySwitch.send(4543939, 24); //(4543939, 24);
}
else {
mySwitch.send(4543948, 24); //(4543948, 24);
}
state7 = !state7; //Swap the state: if it is 0, make it 1, if it is 1, make it 0;
break;
case 0xFF38C7: //when you press the 8 button
if (state8 == 0) {
mySwitch.send(4544259, 24); //(4544259, 24);
}
else {
mySwitch.send(4544268, 24); //(4544268, 24);
}
state8 = !state8; //Swap the state: if it is 0, make it 1, if it is 1, make it 0W);
break;
case 0xFF5AA5: //when you press the 9 button
if (state9 == 0) {
mySwitch.send(4545795, 24); //(4545795, 24);
}
else {
mySwitch.send(4545804, 24); //(4545804, 24);
}
state9 = !state9; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF4AB5: //when you press the 0 button
if (state0 == 0) {
mySwitch.send(4551939, 24); //(4551939, 24);
}
else {
mySwitch.send(4551948, 24); //(4551948, 24)
}
state0 = !state0; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF629D: //When you press the up button
if (state10 == 0) {
mySwitch.send(1398067, 24); //(4543795, 24);
}
else {
mySwitch.send(1398076, 24); //(4543804, 24);
}
state10 = !state10; //Swap the state: if it is 0, make it 1, if it is 1, make it 0;
break;
case 0xFFA857: //When you push the down button
if (state11 == 0) {
mySwitch.send(1398211, 24); //(4543939, 24);
}
else {
mySwitch.send(1398220, 24); //(4543948, 24);
}
state11 = !state11; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
break;
case 0xFF22DD: //When you push the left button
if (state12 == 0) {
mySwitch.send(1398531, 24); //(4544259, 24);
}
else {
mySwitch.send(1398540, 24); //(4544268, 24);
}
state12 = !state12; //Swap the state: if it is 0, make it 1, if it is 1, make it 0;
break;
case 0xFFC23D: //When you push the right button
if (state13 == 0) {
mySwitch.send(1400067, 24); //(4545795, 24);
}
else {
mySwitch.send(1400076, 24); //(4545804, 24);
}
state13 = !state13; //Swap the state: if it is 0, make it 1, if it is 1, make it 0
}
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
}