Hello,
I made a Arduino Bot using l293d ic, and I am controlling the motors using a tv remote and TSOP.
The bot is perfectly moving forward and turning right, but its not moving back or moving left "perfectly" as only motor 2 is rotating and motor 1 is still.
Can you please help me.
#include <IRremote.h>
int motor1Pin1 = 10;
int motor1Pin2 = 9;
int enablePin1 = 11;
int motor2Pin1 = 3;
int motor2Pin2 = 4;
int enablePin2 = 5;
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void forward()
{
digitalWrite(motor1Pin1,LOW);
digitalWrite(motor1Pin2,HIGH);
digitalWrite(motor2Pin1,LOW);
digitalWrite(motor2Pin2,HIGH);
}
void right()
{
digitalWrite(motor1Pin1,LOW);
digitalWrite(motor1Pin2,HIGH);
digitalWrite(motor2Pin1,HIGH);
digitalWrite(motor2Pin2,LOW);
}
void left()
{
digitalWrite(motor1Pin1,HIGH);
digitalWrite(motor1Pin2,LOW);
digitalWrite(motor2Pin1,LOW);
digitalWrite(motor2Pin2,HIGH);
}
void back()
{
digitalWrite(motor1Pin1,HIGH);
digitalWrite(motor1Pin2,LOW);
digitalWrite(motor2Pin1,HIGH);
digitalWrite(motor2Pin2,LOW);
}
void stop1()
{
digitalWrite(motor1Pin1,LOW);
digitalWrite(motor1Pin2,LOW);
digitalWrite(motor2Pin1,LOW);
digitalWrite(motor2Pin2,LOW);
}
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
digitalWrite(enablePin1, HIGH);
digitalWrite(enablePin2, HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value==12583000){
Serial.println("forward()");
forward();
delay(1000);
stop1();
delay(50);
}
else if(results.value==12583003){
Serial.println("right()");
right();
delay(500);
stop1();
}
else if(results.value==12583001){
Serial.println("back()");
back();
delay(500);
stop1();
}
else if(results.value==12583002){
Serial.println("left()");
left();
delay(500);
stop1();
}
irrecv.resume();
// Receive the next value
}
delay(50);
}