I have been trying to revive one of my old rc cars using arduino uno. I am trying to make it autonomus by using an ultrasoinc sensor but I couldn't get far with it because of a problem that I do not understand. I am using a L298N motor driver. I connected both of the motors and I don't think there's a problem with the electronics but I can't run the rear motor while steering the front wheels. I think there's a problem with my code or I'm just missing something obvious. Here's my code,
int in1 = 9;
int in2 = 8;
int in3 = 3;
int in4 = 4;
int trigPin = 13;
int echoPin = 11;
int speed1;
float echoTime;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(speed1, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin,LOW);
delayMicroseconds(200);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
echoTime = pulseIn(echoPin, HIGH);
Serial.println(echoTime);
if(echoTime>617){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(speed1, 80);
}
if(echoTime<617){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(speed1, 80);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
Like I said, I am a newbie therefore I'm sorry if I am missing something obvious. I would appreciate some help,