Infrared DC Motor Control with Two Limit Switch Problem
hi,
i check tv lift using infrared signals dc motors. when control signal bottom , moving or down depending on state of overlying limit switches. sending signal open while moving tv. tv's remote control when press power button repeatedly produce 2 different codes both code "or" have written form. when press program power working correctly, when comes different signals remote control (volume , down, changing channels, etc.) hangs. think i'm doing loop error.
furthermore, when motor in motion again when send switch control signal stopped moving again in opposite direction.
please me.
my code 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();
}
i check tv lift using infrared signals dc motors. when control signal bottom , moving or down depending on state of overlying limit switches. sending signal open while moving tv. tv's remote control when press power button repeatedly produce 2 different codes both code "or" have written form. when press program power working correctly, when comes different signals remote control (volume , down, changing channels, etc.) hangs. think i'm doing loop error.
furthermore, when motor in motion again when send switch control signal stopped moving again in opposite direction.
please me.
my code 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();
}
get irrecv.decode(&results) outside of if tests - call many times
you need first receive ir commands
basically if ir key pressed decide returned true know have play , can if statements results data
don't forget irrecv.resume(); @ end of big first if
you need first receive ir commands
code: [select]
if ( irrecv.decode(&results)) {
// tests here ir commands without calling decode again
...
irrecv.resume();
}
// end switch detection here happen time
basically if ir key pressed decide returned true know have play , can if statements results data
don't forget irrecv.resume(); @ end of big first if
Arduino Forum > Using Arduino > Programming Questions > Infrared DC Motor Control with Two Limit Switch Problem
arduino
Comments
Post a Comment