Sorry if this has been answered somewhere, but I find the forum impossible to search. I have also noticed that some of the respondents get snarky with some of us nubees, so, sorry in advance if you find this a poor question.
I have two L298 motor controllers. I am building a robot car using only one of them. I connected everything per diagrams and instructions, but the motors never worked. I tested the spare controller and it worked fine. Supply voltage to the L298 is from two 3.7 batteries that measures 8.4 volts. The module should handle that. I switched out the modules so that I had one I was sure worked.
Once connected to the Arduino, though, it quit working completely.
My question is, is there a way to reset the controller to work again? And/or why does this happen?
The error is in line 42 of your code.
It looks like there is an error on line 1876 as well.
The snarky ones are trying to tell you that they would like to see your code (but for some reason they choose to make what they possibly think of as jokes instead of clear suggestions).
I would like to see the code too. But what's not clear from your description is when you say "I tested the spare controller and it worked fine." did you test that controller with the exact same Arduino and code and wiring as the one that failed? If not what exactly was different?
And to answer your direct question, no there is nothing about an L298N that can be reset. Problems with them are always code or wiring or you have done something that actually killed the controller.
Steve
Thank you for your reply. I don't believe it is a code problem since in no loner works on its own. That is, once the board had been connected to the Arduino it no longer worked by directly attaching the motor and battery. The power light on the board does come on.
However, here is the code. I haven't figured out the better way to post this, sorry.
Obstacle_Avoidance_Car.ino (7.17 KB)
OK. Maybe figured out how to post code.
Also, both boards were tested in the same way. I don't see how I might have fried the boards.
int inputPin=A0; // ultrasonic module ECHO to A0
int outputPin=A1; // ultrasonic module TRIG to A1
#define Lpwm_pin 5 //pin of controlling speed---- ENA of motor driver board
#define Rpwm_pin 10 //pin of controlling speed---- ENB of motor driver board
int pinLB=2; //pin of controlling turning---- IN1 of motor driver board
int pinLF=4; //pin of controlling turning---- IN2 of motor driver board
int pinRB=7; //pin of controlling turning---- IN3 of motor driver board
int pinRF=8; //pin of controlling turning---- IN4 of motor driver board
unsigned char Lpwm_val = 200; //initialized left wheel speed at 250
unsigned char Rpwm_val = 200; //initialized right wheel speed at 250
int Car_state=0; //the working state of car
int servopin=3; //defining digital port pin 3, connecting to signal line of servo motor
int myangle; //defining variable of angle
int pulsewidth; //defining variable of pulse width
unsigned char DuoJiao=60; //initialized angle of motor at 60°
void servopulse(int servopin,int myangle) //defining a function of pulse
{
pulsewidth=(myangle*11)+500; //converting angle into pulse width value at 500-2480
digitalWrite(servopin,HIGH); //increasing the level of motor interface to upmost
delayMicroseconds(pulsewidth); //delaying microsecond of pulse width value
digitalWrite(servopin,LOW); //decreasing the level of motor interface to the least
delay(20-pulsewidth/1000);
}
void Set_servopulse(int set_val)
{
for(int i=0;i<=10;i++) //giving motor enough time to turn to assigning point
servopulse(servopin,set_val); //invokimg pulse function
}
void M_Control_IO_config(void)
{
pinMode(pinLB,OUTPUT); // /pin 2
pinMode(pinLF,OUTPUT); // pin 4
pinMode(pinRB,OUTPUT); // pin 7
pinMode(pinRF,OUTPUT); // pin 8
pinMode(Lpwm_pin,OUTPUT); // pin 11 (PWM)
pinMode(Rpwm_pin,OUTPUT); // pin10(PWM)
}
void Set_Speed(unsigned char Left,unsigned char Right) //function of setting speed
{
analogWrite(Lpwm_pin,Left);
analogWrite(Rpwm_pin,Right);
}
void advance() // going forward
{
digitalWrite(pinRB,LOW); // making motor move towards right rear
digitalWrite(pinRF,HIGH);
digitalWrite(pinLB,LOW); // making motor move towards left rear
digitalWrite(pinLF,HIGH);
Car_state = 1;
}
void turnR() //turning right(dual wheel)
{
digitalWrite(pinRB,LOW); //making motor move towards right rear
digitalWrite(pinRF,HIGH);
digitalWrite(pinLB,HIGH);
digitalWrite(pinLF,LOW); //making motor move towards left front
Car_state = 4;
}
void turnL() //turning left(dual wheel)
{
digitalWrite(pinRB,HIGH);
digitalWrite(pinRF,LOW ); //making motor move towards right front
digitalWrite(pinLB,LOW); //making motor move towards left rear
digitalWrite(pinLF,HIGH);
Car_state = 3;
}
void stopp() //stop
{
digitalWrite(pinRB,HIGH);
digitalWrite(pinRF,HIGH);
digitalWrite(pinLB,HIGH);
digitalWrite(pinLF,HIGH);
Car_state = 5;
}
void back() //back up
{
digitalWrite(pinRB,HIGH); //making motor move towards right rear
digitalWrite(pinRF,LOW);
digitalWrite(pinLB,HIGH); //making motor move towards left rear
digitalWrite(pinLF,LOW);
Car_state = 2;
}
void Self_Control(void)//self-going, ultrasonic obstacle avoidance
{
int H;
Set_servopulse(DuoJiao);
H = Ultrasonic_Ranging(1);
delay(300);
if(Ultrasonic_Ranging(1) < 35)
{
stopp();
delay(100);
back();
delay(50);
}
if(Ultrasonic_Ranging(1) < 60)
{
stopp();
delay(100);
Set_servopulse(5);
int L = ask_pin_L(2);
delay(300);
Set_servopulse(177);
int R = ask_pin_R(3);
delay(300);
if(ask_pin_L(2) > ask_pin_R(3))
{
back();
delay(100);
turnL();
delay(400);
stopp();
delay(50);
Set_servopulse(DuoJiao);
H = Ultrasonic_Ranging(1);
delay(500);
}
if(ask_pin_L(2) <= ask_pin_R(3))
{
back();
delay(100);
turnR();
delay(400);
stopp();
delay(50);
Set_servopulse(DuoJiao);
H = Ultrasonic_Ranging(1);
delay(300);
}
if (ask_pin_L(2) < 35 && ask_pin_R(3)< 35)
{
stopp();
delay(50);
back();
delay(50);
}
}
else
{
advance();
}
}
int Ultrasonic_Ranging(unsigned char Mode)//function of ultrasonic distance detecting ,
//MODE=1,displaying,no displaying under other situation
{
int old_distance;
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH);
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
int distance = pulseIn(inputPin, HIGH); // reading the duration of high level
distance= distance/58; // Transform pulse time to distance
if(Mode==1){
Serial.print("\n H = ");
Serial.print(distance,DEC);
return distance;
}
else return distance;
}
int ask_pin_L(unsigned char Mode)
{
int old_Ldistance;
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH);
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
int Ldistance = pulseIn(inputPin, HIGH);
Ldistance= Ldistance/58; // Transform pulse time to distance
if(Mode==2){
Serial.print("\n L = ");
Serial.print(Ldistance,DEC);
return Ldistance;
}
else return Ldistance;
}
int ask_pin_R(unsigned char Mode)
{
int old_Rdistance;
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH); //
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
int Rdistance = pulseIn(inputPin, HIGH);
Rdistance= Rdistance/58; // Transform pulse time to distance
if(Mode==3){
Serial.print("\n R = ");
Serial.print(Rdistance,DEC);
return Rdistance;
}
else return Rdistance;
}
void setup()
{
pinMode(servopin,OUTPUT); //setting motor interface as output
M_Control_IO_config(); //motor controlling the initialization of IO
Set_Speed(Lpwm_val,Rpwm_val); //setting initialized speed
Set_servopulse(DuoJiao); //setting initialized motor angle
pinMode(inputPin, INPUT); //starting receiving IR remote control signal
pinMode(outputPin, OUTPUT); //IO of ultrasonic module
Serial.begin(9600); //initialized serial port , using Bluetooth as serial port, setting baud
stopp(); //stop
}
void loop()
{
Self_Control();
}
I am a nubee in this forum and I have a problem for using l298n motor driver shield. I want to make obstacle avoiding car but my code is good for hcsr04 ultrasonic sensor but not going good with the servo motor. The ultrasonic sensor is not getting signals while the servo is on . Please help me with the code.Here is the code::
sketch_mar09a.ino (1.72 KB)
(edit: the below is aimed at AstroJ not at Protom9900 who posted an unrelated query.)
I would be extremely inclined to ditch that fairly complex sketch for testing, and just do a digitalWrite() high and low to the outputs without all that other stuff in the way.
The 298 chip drops 2V at least, up to almost 5V under appreciable current, so your 8V in will only be about 6 at best, perhaps only about 4.
From the 298 datasheet:
I would test it with the motors disconnected and leds (with resistors) from the 298 module output pins to ground to see if the output is sequencing as you expect.
And / or measure the voltage at the 298 module outputs under load and with no load, see what you get.
Thanks for the reply. I will try it when I have new boards to work with. The code is from a Robot Car Kit and I thought I could duplicate it with my own parts. Apparently not.

