Hi,
I check the TV lift using infrared signals with DC motors. When the control signal from the bottom and moving up or down depending on the state of the overlying limit switches. I am also sending a signal to open while moving up to the TV. TV's remote control when I press the power button repeatedly to produce two different codes for both code "or" I have written form. When I press program all power is working correctly, but when it comes to the different signals from the remote control (volume up and down, changing channels, etc.) hangs. I think I'm doing a loop error.
Furthermore, when the motor is in motion again when I send it to the switch control signal stopped moving again in the opposite direction.
Please help me.
My code is as follows:
#include <IRremote.h>
int RECV_PIN = 11;
int MOVE_UP = 8;
int MOVE_DOWN = 9;
int TOP_SW = 6;
int BOTTOM_SW = 7;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
void setup()
{
irrecv.enableIRIn();
pinMode(MOVE_DOWN,OUTPUT);
pinMode(MOVE_UP,OUTPUT);
pinMode(TOP_SW,INPUT);
pinMode(BOTTOM_SW,INPUT);
Serial.begin(9600);
}
void loop() {
if ((irrecv.decode(&results)) && ((results.value == 0x84C) || (results.value == 0x4C)) && digitalRead(TOP_SW) == HIGH ) {
digitalWrite(MOVE_DOWN, HIGH);
digitalWrite(MOVE_UP, LOW);
Serial.println("MOVE_DOWN");
irrecv.resume();
}
if ((irrecv.decode(&results)) && ((results.value == 0x84C) || (results.value == 0x4C)) && digitalRead(BOTTOM_SW) == HIGH ) {
digitalWrite(MOVE_UP, HIGH);
digitalWrite(MOVE_DOWN, LOW);
Serial.println("MOVE_UP");
sender();
irrecv.resume();
}
if ( digitalRead(BOTTOM_SW) == HIGH && digitalRead(MOVE_DOWN) == HIGH) {
digitalWrite(MOVE_UP, LOW);
digitalWrite(MOVE_DOWN, LOW);
Serial.println("BOTTOM_STOP");
irrecv.resume();
}
if ( digitalRead(TOP_SW) == HIGH && digitalRead(MOVE_UP) == HIGH) {
digitalWrite(MOVE_UP, LOW);
digitalWrite(MOVE_DOWN, LOW);
Serial.println("TOP_STOP");
irrecv.resume();
}
}
void sender()
{
irsend.sendRC5(0x84C, 12);
Serial.println("TV_ON");
delay(100);
setup();
}