Let's Make Robots!

DIY L298N shield

Hi guy !

I've recetly build a L298N shield for my arduino based this shematics the shematics.

The only modification that i made is : - my diodes are 1N5821

                                                      - I've not put some pull up resistance on enablepin

                                                      - I use 5V from my arduino and 4,8V batterie for my motors

And when i plud the shield on my arduino and import the code ( see below) the software say:

avrdude: stk500_getsync(): not in sync: resp=0x00

So i try to import the code without put the shield on the arduino and it import correctly but when i plug the shield nothing hapen,the motor dont move.

Someone have an idea ?

sorry for spelling (french )

here is the code :

//-- MOTEUR A --
int ENA=5; //Connecté à Arduino pin 5(sortie pwm)
int IN1=2; //Connecté à Arduino pin 2
int IN2=3; //Connecté à Arduino pin 3

//-- MOTEUR B --
int ENB=6; //Connecté à Arduino pin 6(Sortie pwm)
int IN3=4; //Connecté à Arduino pin 4
int IN4=7; //Connecté à Arduino pin 7

void setup() {
 pinMode(ENA,OUTPUT);//Configurer les broches comme sortie
 pinMode(ENB,OUTPUT);
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(IN3,OUTPUT);
 pinMode(IN4,OUTPUT);
 digitalWrite(ENA,LOW);// Moteur A - Ne pas tourner (désactivation moteur)
 digitalWrite(ENB,LOW);// Moteur B - Ne pas tourner (désactivation moteur)

 // Direction du Moteur A
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH);

 // Direction du Moteur B
 // NB: en sens inverse du moteur A
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW);
}

void loop() {
  // Moteur A - Plein régime
  analogWrite(ENA,255);

  // Moteur B - Mi-régime
  analogWrite(ENB,128);
}



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

And a other thing, I don't have capacitors and voltage regulator on my setup because i use two power sources ( 5V of the arduino and a 9,6V batteri for my motor ).

So do you think that the capacitor are neccesery ?

 

I post a photo on my setup soon :)

Both power supplies should have a 0.1uF capacitor. Sometimes a circuit will work without a bypass capacitor sometime they don't. Sometimes not having a bypass capacitor will ruin a chip (though not often). Use ceramic capacitors for this. 0.1uF are really cheap if you buy 100 or so at a time.

The datasheet says these capacitors should be connected as close as possible to the L298's ground pin.

I think using the Arduino's 5V for the logic supply (pin 9) should be fine.

So 5V from Arduino is connected to pin 9 of L298, ground of Arduino is connected to pin 8 of L298. The "+" wire of your 9.6V pack is connected to pin 4 of the L298 and the "-" of your 9.6V pack gets connected to pin 8 of L298. The negative wire "-" of the battery pack is often referred to as the ground. So when they say you need a common ground on a circuit if means the ground wires of both power suppllies are connected at some point. I've been told it best to have these two grounds connected in only one location.

I noticed in the datasheet that the enable pins are supposed to be low when the power is connected or disconnected on the L298. This makes me think a 10K resistor connected to both enable and ground would be a good idea.

Do you have a copy of the L298N datasheet? SparkFun has a copy if you need it.

The odd numbered pins are the ones that stick out in front of the chip. As I mentioned previously, the datasheet uses "Vss" to indicate the logic power supply (5V). "Vss" often refers to ground but not in this case. Watch out for this strange notation.

The capacitors are mentioned on page 7 of the datasheet (and a couple other places).

Here is some news,

I try to re build a shield and this time im building the shield step by step and checking at every step.

So i try Duane idea to see if my L298N work correctly and when i plug the power, the motor start spinning but for 1 second.

After this 1 second, the motor stop and keep not moving until i de-plug and re-plug power.

a Idea someone ?

This is strange. It sounds like either the L298N chip or the voltage regulator is getting too hot and shutting down.

A picture of your set up may help someone identify the problem.

I don't think you need the pull-up resisitors. In fact, I'd be inclined to use pull-down resistors (10K) to make sure the motor doesn't turn on when you don't want it to.

I don't know enough about diodes to help much. I've just read they should be fast acting and I see schottky diodes often recommended.

Here's an inexpensive L298N PCB with all the additonal components already added. These are the kind I've used in my robots.

I think i'm gonna build a second shield with the shematic of my preview post

but do you think my diodes ( 1N5821 ) are too big for my use and if the pull up resictances on the enable pin are neccecery ?

OK i'm gonna test that to see if it work. But iv not understand you says that the ground of the arduino 5V and the 12V motor supply are not connected together ?

Is this shematics good ?

Like that ?

Is the pull up resistance on the enable PIN is neccecery ? Why the value of this resistance vary between different schematics ? Is by the enable pin that we control the speed of the motors ?

Thanks for your help :)

The ground of the 5V and 12V supplies do need to be connected.

I'm pretty sure the pull-up resistors aren't really needed. Often the exact value of a pull-up reisistor isn't important. In this case the resistor (if one is used) needs to be a high enough value that the uC won't need to fight the 5V line to bring the pin low.

If you had only used a 10ohm resistor as a pull up resistor, then when the Arduino pin connected to the same pin goes low, it would have to sink 500mA of current (very bad idea). With a 10K resistor the Arduino only needs to sink 0.5mA of current.

Often a pull-up resistor is used pervent a pin from floating (not being either high or low). I think that's why the pull-up is used in this example (but I'm not sure).

I don't think I have pull-up resistors on my L298N drivers but as I mentioned, I'm using PCBs I purchased from ebay.

The top diagram won't work as it is now. The current sense pins need to be connected to ground in order for it to work. Some L298N curcuits use low value resistors on the current sense to ground connection and measure the voltage drop across the resistor to compute the current used. In order to use the current sense lines this way you need resistors that can handle a lot of current. If you were usinga 12V supply, the resistors would probably need to be rated at 20 Watts or more (assuming 2 Amps with a drop of 10V). Most of the through hole resistors used in elelctronics are 1/4 Watt. High Watt rated resistors tend to be expensive so lots of L298N circuits don't use them and just connect the current sense pins to ground.

I like to test my H-bridge circuits with just wires before trying them with a microcontroller to make sure they really work.

Wire Vss(logic supply)(pin 9) to 5V. Also enable A (pin 6) and IN1(pin 5) should be connected to 5V.

Connecte IN2(pin 7) and sense A (pin 1) and pin 8 (ground) to the 5V supply's ground.

Make sure your motor power is connected to Vs(pin 4) and the motor supply ground is connected to other power supply's ground connection.

With the above connections, a motor attached to pins 2 and 3 should spin.

The L298N datasheet uses Vss to indicate logic supply. Most schematics use Vss to mean ground. Watch out for this.

The negative side of both battery packs need to be connected at some point in the circuit. This is referred to as a common ground.

Testing the h-bridge without a microcontroller can help you know if you have a hardware problem or a software problem.

BTW, there are lots of really inexpensive L298N boards on ebay. I'm using these in my two Rover 5 bots and they seem to work fine.

If you wired your L298N chip correctly, you don't need to worry about most of the connections I listed.

Just connect the pins going to the microcontroller to either 5V or ground to get the motor to spin the way your want it to. You'll want the enable pins connected to 5V and one of the IN pins on each side connected to 5V with the other IN pins connected to ground.

Ok so a 9,6V battery will do the job ?

Edit : Ive just tried with a 9,6V battery and the result is the same... There is no voltage out on the motor PIN

I think there is a short circuit on my shield and, because of that, the arduino canno't import the code and the L298N canno't do his job. But i check my solder a few times and all is allright.