I am working on a school project for a line-following car. We are using 2 motors, which operate between 12-24 Volts. Link.

We use three 9 V batteries in series to get 27 V. When we connect this to the motor driver (L298N) and try to rotate the motors at the same speed using the same PWM value (writing values between 0 and 255) we get that one motor turns faster than the other.

We used a multimeter to measure the voltages between the terminals for both the motors. We noticed that one of the terminals gives lower voltages. For example:

If we write PWM signal of 150, one motor gets 18 V while the other gets 15 V (only if we use PMW signal of 255, the motors have the same speed and thus the same voltage about 23V). The motors aren't the problem, as we changed the motors to the other terminals. One terminal constantly gives a lower voltage.

We used two different motor drivers of the type L298N and also got the same result. Does anyone know why there is a different voltage drop at the 2 motorterminals?

Thanks in advance.

  • what board? which pwm pins? – Juraj Mar 27 '19 at 5:52
  • Arduino uno, and the PWM pins are: 3 and 6 – jan Mar 27 '19 at 8:13
  • What happens when you reverse the output pins? Where is the faster motor? is it one motor specifically, a pin specifically? You say you've changed terminals, and what happened then? which motor got the 18v? which pins did you use initially and for other attempts? You really need to include more information, more diagnostics of what you tried and the results you got. You should also include a schematic. Although not required, but since you have a rather special problem, a short video wouldn't go astray. Again, not required, but it would help. – Madivad Apr 9 '19 at 14:56
  • @Madivad, you should first read the answers – Juraj Apr 9 '19 at 16:55

analogWrite() Notes and Warnings

The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g. 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.

and PWM pins 5 and 6 have different default base frequency then the other PWM pins.

Use PWM pin pair controlled by the same timer. 5 and 6 or 3 and 11 or 9 and 10

  • Thank you, I will try this tomorrow at school!! I will let you know whether it works or not. – jan Mar 27 '19 at 17:03
  • YESS it helped. Our motors now rotate at the same speed with the same voltage! Thanks man!! – jan Mar 29 '19 at 8:17
  • @jan, you can accept the answer to mark the question solved – Juraj Apr 9 '19 at 16:54
    *This miniature gearbox is of steel and brass 
construction with brass gears and is mounted on a 
1mm thickness steel bracket. It incorporates
    a high quality three pole motor with sleeved 
bearings. The design and construction of the unit 
make it suitable for a host of model and light* //no capacitor mentionend

I think the problem is actually the controller. One major drawback to working with brushed motors is the large amounts of electrical noise they produce. This noise can interfere with your sensors and can even impair your microcontroller by causing voltage dips on your regulated power line. Large enough voltage dips can corrupt the data in microcontroller registers or cause the microcontroller to reset.

You can avoid this problem by soldering capacitors along your motor terminals. Use 1µF ceramic capacitors for example

  • I actually do have capacitors on both of the motors. Thanks for your answer man – jan Mar 27 '19 at 8:12

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