(Not native english speaker here, feel free to edit my sentences)

I try to control the speed of a DC motor with a L298N shield but it doesn't work very well. Here is my scheme :

enter image description here

The power comes from a transfo with an adjustable voltage of ~7v 1.0 Amp. I don't care about the sens of rotation, so I set IN1 to 5v and IN2 to the ground, is it right to do it like that ?

Now here is the code I'm using :

#define CONTROL_M   9  // To Enable input 

void setup () 

void loop () 

void test_analog_motor() 
    for (int i; i < 250; i=i+25) 
        analogWrite(CONTROL_M, i); // Any value between 0 and 255

With that code, the speed of my motor should progressively increase and then goes back to 0. I'm aware that, maybe if the value is too low, the motor will have trouble to start so I "help" it manually.

If I doesn't use the Enable output of my Arduino and just use the jumper instead, the motor turns with a good torque. This prooves at least that my shield isn't damaged.

enter image description here

Now here is the problem I have : With the scheme I've shown above, it simply doesn't work, nothing happens when I set the grounds in common, why ? Then if I remove the cable that goes to the arduino ground, it works but the motor has a very low torque, it seems also that there is a kind of latency in regards to what display the Serial monitor.

I feel a bit stupid with what I did with the grounds, it seems wrong t me but I don't know what to do instead :/ What can I do ? My goal is to have the best possible control of the speed of that DC motor in term of reactivity, does a L298N is suited for that ?

EDIT I did tested the PWM with an oscilloscope and a multimeter, the arduino PIN I was using worked correctly. I don't know why but now, the shield works too, I mean : Problem solved. One theory is that I adjusted the tension of my power supply under 5V. In that cas the shield doesn't nothing Arduino is magic sometimes...

  • 1
    Your delay is probably too long - your code will take over 2 minutes to reach full speed. Also the L298 is an obsolete, antiquated, lossy part. FET drivers have been the norm for over a decade, but people keep putting these obsolete designs on ecommerce sites for the unsuspecting to buy. – Chris Stratton Apr 15 '18 at 1:52
  • could you cite the names of some good FET drivers example ? – snoob dogg Apr 15 '18 at 2:24
  • 1
    @ChrisStratton By the way, my code will not take over 2 min to reach its full speed. look, it's i = i + 25 so 10 step of 500 ms period is about 5 secondes – snoob dogg Apr 15 '18 at 2:37
  • for (int i; i < 250; i=i+25)? You might want to initialize the variable i, like so for (int i=0; i < 250; i=i+25). – Gerben Apr 15 '18 at 16:18
  • Are you sure you don't need to supply 5V to the board? – Gerben Apr 15 '18 at 16:20

You do need the ground wire. The reason it 'works' without it is that enable input effectively then has an aerial connected and is responding in the same was as if you touch the input jack on an amplifier and hear a buzzing sound.

There is a link behind the blue connectors that enables the onboard 5v regulator. I assume you have this fitted, or it wouldn't work with the jumper as you describe.

There is a tutorial here : http://www.instructables.com/id/How-to-use-the-L298-Motor-Driver-Module-Arduino-Tu/

I can't see anything different from what you're doing that would cause it to fail, but perhaps you have a problem with pin 9 from your board - you might have damaged it by misconnection, as certain ways of wiring that schematic could put 12V on the arduino pin. You could also try using pin 13 : the arduino LED should then be lit in sympathy with the PWM signal and you'll know it's working.

  • Yes what you say about buzzing sound makes sence. indeed, I'm wondering if I'm not damaging the pins of my arduino with that assembly. so what's weird is that the board doesn't seems to do anything when grounds are common. I will test the PWM separately to see if they work as expected – snoob dogg Apr 16 '18 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.