Hi,
i have conected L293 to arduino nano board, have managed to start the motor, revers the direction, but no succes with on off motor with rf remote.
Regards!
Leo
Hi,
i have conected L293 to arduino nano board, have managed to start the motor, revers the direction, but no succes with on off motor with rf remote.
Regards!
Leo
Very little to go on - what RF remote? What have you tried? Sounds like you can control the motor
from code, can you receive from the remote with your code?
Post your code, tell us exactly what hardware and how you've connected it please...
Hi,
i use these remote:
http://www.arduiner.com/en/wireless/365-2262-2272-four-way-wireless-remote-control-kit-m4-non-lock-receiver-plate-four-button-wireless-remote-control.html
with PT2272-m4.
I can read the state of the buttons pressed on the remote, but haven't managed to turn on and off the motor with rf remote.
Here is the code:
int inPin0 = 2; // RF input button B
int inPin1 = 3; // RF input button D
int inPin2 = 4; // RF input button A
int inPin3 = 5; // RF input button C
int outPin0 = 8; // Digital Input 2
int outPin1 = 9; // Digital Input 1
int outPin2 = 10; // PWM Motor 1
int outPin3 = 11; // PWM Motor 2
int outPin4 = 12; // Digital Input 1
int outPin5 = 13; // Digital Input 2
int state = LOW; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 10000; // the debounce time, increase if the output flickers
void setup() {
//Motor enable PINS
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
//Motor PINS
pinMode(outPin1, OUTPUT);
pinMode(outPin0, OUTPUT);
pinMode(outPin4, OUTPUT);
pinMode(outPin5, OUTPUT);
//RF is input
pinMode(inPin0, INPUT);
pinMode(inPin1, INPUT);
pinMode(inPin2, INPUT);
pinMode(inPin3, INPUT);
}
void loop() {
// digitalWrite(outPin2, HIGH);
// digitalWrite(outPin3, HIGH);
// digitalWrite(outPin1, HIGH);
// digitalWrite(outPin0, LOW);
// digitalWrite(outPin4, HIGH);
// digitalWrite(outPin5, LOW);
// delay(10000);
// digitalWrite(outPin2, LOW);
// digitalWrite(outPin3, LOW);
reading = digitalRead(inPin2);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
previous = reading;
if (state == HIGH){
analogWrite(outPin2, 255);
analogWrite(outPin3, 255);
digitalWrite(outPin1, HIGH);
digitalWrite(outPin0, LOW);
digitalWrite(outPin4, HIGH);
digitalWrite(outPin5, LOW);
}
else
analogWrite(outPin2, 0);
analogWrite(outPin3, 0);
digitalWrite(outPin1, HIGH);
digitalWrite(outPin0, LOW);
digitalWrite(outPin4, HIGH);
digitalWrite(outPin5, LOW);
}
Regards!
Leo
p.s. Sory for the mess in the code long time not programed anything:(
Hi all, here is the working code tested and working 100%:
int inPin0 = 2; // RF input button B
int inPin1 = 3; // RF input button D
int inPin2 = 4; // RF input button A
int inPin3 = 5; // RF input button C
int outPin0 = 8; // Digital Input 2
int outPin1 = 9; // Digital Input 1
int outPin2 = 10; // PWM Motor 1
int outPin3 = 11; // PWM Motor 2
int outPin4 = 12; // Digital Input 1
int outPin5 = 13; // Digital Input 2
int state = LOW; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 400; // the debounce time, increase if the output flickers
void setup() {
//Motor enable PINS
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
//Motor PINS
pinMode(outPin1, OUTPUT);
pinMode(outPin0, OUTPUT);
pinMode(outPin4, OUTPUT);
pinMode(outPin5, OUTPUT);
//RF is input
pinMode(inPin0, INPUT);
pinMode(inPin1, INPUT);
pinMode(inPin2, INPUT);
pinMode(inPin3, INPUT);
}
void loop() {
reading = digitalRead(inPin2);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
if (state == LOW){
digitalWrite(outPin2,LOW);
digitalWrite(outPin3,LOW);
digitalWrite(outPin1, HIGH);
digitalWrite(outPin0, LOW);
digitalWrite(outPin4, HIGH);
digitalWrite(outPin5, LOW);}
else
digitalWrite(outPin2,HIGH);
digitalWrite(outPin3,HIGH);
previous = reading;
}
Regards!
Leo
p.s. Have to add some more options.