DC motor and servo problem

New account as I think I have been inactive for too long here! I’m looking for some help and suggestions for a project that I’m having a problem with.

The project uses a Pro Mini, a 5V motor, a servo, and a continuous rotation servo - it involves several other components, but the problem seems to be related to the 5V motor somehow driving the servos when it is powered.

I am pretty sure the problem is not with the code so I have not included it here.

When the sketch is edited to run without turning the motor on the servos behave as expected - rotating to given angles or completing rotations. However, when the motor is running (either using PWM or digitalWrite), both servos run continuously even though the only instruction for them to run in the sketch is when the motor is stopped.

I’m pretty sure this is a wiring problem so I have attached a sketch of the circuit. The motor and servos are powered by a battery and the Pro Mini is connected to USB via FTDI. What could the problem be?

Circuit looks fine to me.

I've seen systems where the theoretical circuit was fine but the connections turned out to be made via an old breadboard and tiny feeble alligator clips. Instant answer! So how about a picture of how it's actually wired and details of the 5V BATT?

Steve

Thanks for the replies.
A picture will probably not help right now since all of the wiring is tucked inside a Lego train. If and when I perform surgery on it I will be able to get a decent photo.
Here are a few other details that may be of help...
There are no breadboards or alligator clips. All connections to the motor are with 22awg wire and soldered. The motor is a 4.5V vintage Lego train motor that draws 100mA at no load and has a stall current of around 1A.
The battery is a lipo rechargeable rated at 5V and 2A (5000mAh). I don't think current is an issue (yet) as the other components don't draw much and I haven't tested the motor under load.
The servos (Hitec HS-425BB and HSR-1425CR) are in cars behind the engine and connected using jumper wires.
Other components include a DFRobot Mini DFPlayer, HC-05 Bluetooth module, a Hall effect sensor, a photocell, and some LEDs.
Everything is working as expected with the exception of the servos when the motor is running.

How to post an image.

Have you monitored the 5V from the battery with a DMM to see if it remains steady when the motor is running?

Thanks for posting the image. I thought attaching it would work.

I get a steady 5V at the train cars when the engine motor is idle, starting up, and running.

I am using the SoftwareSerial library for both the bluetooth module and the DFPlayer. In my searches, I have seen reference to a conflict between these libraries. While this is a possibility, I see no problem when the motor is not running. In fact, I can control the servos alone using commands over serial from the bluetooth module without issue, so I don't think there is any conflict here. Perhaps these problems have been sorted out in more recent versions of these libraries?

After some more testing, it appears to be a power supply problem. When the servos are powered from an external source they work they should should. But why?

I haven’t looked at your code but my first instinct is to suspect electrical noise as your problem.

Brushed DC motors can produce a lot of RFI (radio-frequency interference), particularly under load. This can be radiated and it can be conducted through wiring and other electronic components.

Is all the wiring bunched up together so that you can get a lot of inductive coupling between motor power and ground leads and the signal leads running to the Arduino and servos?

If you replace the motor with an LED and resistor and enable the motor part of your code do you still have the problem?

Hi,
Have you got ALL the 5V wires for the motor and servo going directly to the battery positive, or are they looped or daisy chained?
The same for the gnd wires for the three units.

Tom... :slight_smile:

I miss code in this question.

The servo library use a timer; PWM uses the timer. Does analogWrite() interfere with the servo library by chance?

Thanks for the replies!

@Blackfin: The wiring is definitely bunched up as I was running out of space. The battery sits above the motor unit, power and ground wires run alongside it, and other components are above the battery. I think that RFI is a real possibility. Would that be isolated to the 5V line though? When it worked using a separate power supply the grounds were tied together and the same servo signal wire was used.

@TomGeorge: There is some daisy chaining going on. Power from the battery goes through a switch then to a wiring harness - from there to the motor, other components in the engine car, then to each of the cars behind the engine on a single wire from the harness. Essentially, the components in the cars are daisy chained (2 servos, a handful of LEDs, and a Hall effect sensor).

@wvmarle: I thought there may have been a problem with PWM and the servo library too. Things that helped me rule it out were the fact that other PWM pins were working fine (and I tried the motor on different pins with the same result), when running the motor using digitalWrite() the problem with the servos persisted, and using a separate power supply for the servos resolved the problem. I am pretty certain the code is not the problem now.

The Servo library disables PWM on pins 9 and 10.

Some more testing is required but I think I am on the right track. I went with the idea of electrical noise as suggested by Blackfin. See also this post and especially this page.

I added a 0.1uF capacitor across the motor. This was no small feat! I had to solder it inside the Lego motor since the diode was soldered on the outer terminals where the motor wires were attached - this was all hot-glued for strain relief and difficult to get at. I've tested the train and the capacitor seems to have eliminated the problem, at least when the motor is not under load. I'll test it more thoroughly once I partially reassemble the engine.

Here is an updated circuit diagram: