Interference problem with slotted IR sensors


I'm having an issue with what I think is noise affecting my sensors. It's really got me stuck.

My setup is below and link to a high res drawing [u]HERE.[/u]

I have two 12V motors (A & B), their speed is controlled with PWM from an Arduino Uno running PID for each motor. The setpoints for motors A & B are controlled via a potentiometer for each one. On each motor shaft there is a single slotted disc which are read by two LM393 FC-03 slotted IR speed sensors. This setup runs perfectly ok when it is running on its own.

I also have a small 12V Gearmotor (C) which is connected to another Arduino Uno. The speed is controlled by a pot and PWM.

When I turn Gearmotor C on and increase the speed with the pot, motors A & B start to pulse as if the power is being intermittently cut. I've tried removing the PID code from motors A & B and I notice if I Serial.print both speed sensors info, the readings go crazy when I turn the pot up for gearmotor C, then return back to normal when I turn the pot down to 0V. I'm thinking there is interference with the sensors which is having a knock on affect to the PID which controls motors A & B.

I'm quite new to electronics, but I've tried twisting the power leads of Gearmotor C and soldering a 0.1uf ceramic capacitor across the terminals, sadly there is no change. The 3 cables for each IR sensor VCC, GND & DO are soldered to the speed sensors & roughly 1 meter long (just unshielded silicone cable). These can be shortened when I know where I will route them. I tried twisting together the VCC & GND for each sensor in case that helps.

I'd greatly appreciate any advice on what I can try to fix this problem.

Many thanks,


My setup is below and link to a high res drawing [u]HERE.[/u]

Another nice candidate for the Fritzing Wall of Shame. Please post a circuit diagram instead.

Also please post your code, another major candidate for problems.

Thanks wvmarle.

I've attached the code to this post as it exceeds the character limit. It's largely based on Robin's easyPID program. With this code, motors A & B run as they should without any problems. The issue seems to be when gearmotor C is turned on which is connected to another arduino. I think it is interfering with the sensors which is causing motors A & B to start stuttering.

Does anybody have any suggestions on what else I could try to stop this interference?

Thanks again,


Motors_A_B_Code.ino (11.8 KB)

Missed the part about the separate Arduino.
In that case it's almost certainly a hardware/wiring issue, a circuit diagram is needed to have any idea on that.
Also make sure your power supply can supply enough current for all three motors and then some.

The battery is the one in the drawing, a 12V 22AH SLA battery. The small gearmotor C which seems to cause the problem when it is turned on has a stall current of 3.8A. With gearmotor C turned off at the switch or it's pot turned right down to 0V the stuttering on motors A & B (each controlled via PID & the two sensors) goes away.

Apologies the drawing isn't clear, I'm not sure I know how to do a circuit diagram.

Let me know if there is any other information I can give you which might help.



Apologies the drawing isn't clear, I'm not sure I know how to do a circuit diagram.

A legible hand drawn schematic is acceptable. Even if you don't know the symbols, you can draw rectangles and write the component name inside and add the connecting wires and label with voltages/signal names. Convention is inputs on left, outputs on right, positive voltages at top, ground/negative at bottom.

Take a picture of the drawing and attach it to a post.

Thanks dougp. I've been looking into how to do a circuit diagram so I'll try drawing one up and posting it to make things clearer.

As a test I tried moving the gearmotor C away from both the sensors of motors A & B to see if it lessened the interference, it was a marginal improvement at best. When the gearmotor C was 6' away from the sensors it would still make motors A & B stutter.

I then tried powering the troublesome gearmotor C and it's circuit from a different 12V battery. If I moved gearmotor C 6' away from motors A & B, the interference and stuttering in A & B seemed to diminish. As I moved the turning gearmotor C closer to motors A & B the interference started again. It actually seems worse when the speed of gearmotor C is higher.

Does all this suggest that it could be a combination of radiated and conducted noise causing the problems with the IR sensors?


Does all this suggest that it could be a combination of radiated and conducted noise causing the problems with the IR sensors?

Other possibilities include an inadequate power supply, inadequate power supply decoupling, inadequate motor controllers, poor solder connections, unsoldered connections, etc.

A decent circuit diagram will help immensely, but a Fritzing will not. Post links to the power supply product page or data sheet, similarly for all other major components.

Right, I've tried my best to draw up a circuit diagram which will be clearer. Hopefully it's better than my last attempt.

Here's a link to the battery i'm using which has a datasheet on the page: REC22-12I - REC - VRLA - Cyclic Use - Industrial - Batteries

The Gearmotor C I'm using:

Gearmotor C driver (Adafruit DRV8871):

5V step down voltage regulator: Pololu 5V, 2.5A Step-Down Voltage Regulator D24V25F5

I don't seem to be able to find the FC-03 speed sensor datasheet, nor one for the IBT-2 43A motor driver.

Let me know if there is anymore information I can give to help.

Many thanks,


Other possibilities include an inadequate power supply, inadequate power supply decoupling, inadequate motor controllers, poor solder connections, unsoldered connections, etc.

Datasheet for the DRV8871 wants a .1µf and a bulk capacitance on VM (47µf shown). Are these in place?

I didn't check other sheets but they no doubt also have specs for filtering/decoupling.

Nice job on the schematic! However, it does not show decoupling capacitors on the motors, motor drivers or the sensors. For the sensors, you should have 10uF in parallel with 0.1 uF right across the sensor power terminals. For the drivers, typically 100 uF is used, again right across the motor driver power terminals.

Nothing else really jumps out, except that the DRV8871 driver is inadequate for that motor. The peak driver current is only 3.6A, for a startup current of 3.8A.

Are all your motor and power connections well soldered, with reasonably heavy (16-18) gauge stranded wire?

You may need to borrow an oscilloscope to check for voltage spikes or drops on the power leads.

Thank you both for your replies,

A few things I forgot to add to the circuit diagram:

Motors A & B both have large ferrite cores which came looped on to the 14 AWG leads.

For the Adafruit DRV8871 gearmotor C driver, I removed the smd resistor (3002 – 30KOhms?) and added a 20KOhm resistor to increase the current limit of the driver as described in page 9 of the DRV8871 driver pdf.

I’ve also soldered a 0.1uf ceramic capacitor across the gearmotor C terminals.

I’ve not intentionally added any decoupling capacitors to the circuit – unless these components are included on the driver boards?
The IBT-2 drivers have what I think is a large black electrolytic capacitor next to the battery terminals, it is rated at 50V and 330uf – I’ve attached a photo, see what you think. Should I still add a 100uf electrolytic capacitor?
For the sensors, should the 10uf be an electrolytic capacitor and the 0.1uf ceramic? I’m guessing I need to solder these as close to the sensor VCC, GND pins as possible?
Motors A & B use 14 AWG stranded wire, they are connected to the screw terminals which came pre fitted on the IBT-2 motor drivers
Gearmotor C uses 18 AWG stranded wire. I intended to solder them directly to the board but the holes were too small so I soldered the supplied screw terminals and am using those – see picture

For the Adafruit DRV8871 gearmotor C driver, I’ve soldered the supplied male header pins to IN2, IN1, VM AND GND and the supplied screw terminals to MOTOR and POWER. Should the capacitors be soldered to the 18AWG wires going in to the POWER terminals – see attached picture. It says on this page, second picture down ‘These two sets of pads are connected internally’. If so, should they just be soldered as close to the POWER screw terminals as possible?
Would the required capacitors for the DRV8871 be a 47uf electrolytic and a 0.1uf ceramic?

What I don’t understand is how motors A & B are right next to both speed sensors yet they don’t seem to cause interference. Yet when I turn the gearmotor C on (which I’ve even moved 6’ away) all of sudden it causes the motors A & B to start stuttering and the speed sensor readings start going erratic.

If there is anymore information, pictures etc on the setup, which might help, just let me know.



Something is wrong with your setup that I can't see. You will need a scope to troubleshoot it.

However, the 3.6A current limit is inherent to the design of the DRV8871 and can't be increased. It will go into overcurrent and/or thermal shutdown with that motor. Data sheet here:

This driver can handle 5A peaks. I have been using this one for 7A motors for about two years, and have never had any problems.

Arh man, gutted. The effort to get to this point and it might all be for nothing.

As a test, I removed the DRV8871 gearmotor C driver and used one of the IBT-2 motor drivers from A & B. With just motor A running with the PID, I turned the gearmotor C on and increased the speed with the pot - it just acted exactly the same as with the DRV8871 - motor A starts to stutter, it seems to get worse when the speed of gearmotor C is increased.

The gearmotor C is 4' from the sensors, the only thing the gearmotor C circuit shares with A & B is the same battery. I've even tried it running on another 12V battery but if you move it within a few feet of motors A & B when they're running - they start stuttering again.


It occurred to me that I had another smaller gearmotor by the same manufacturer, link here and motor curves.
I tried swapping it for the gearmotor which seems to be giving me all the trouble and to my amazement, it will run alongside motors A & B without interfering with them, perhaps a slight pulse from motors A & B when I turn the gearmotor switch on, but that's it.

Now, I'm not sure if it's strong enough for the same purpose, but does it suggest that the interference/noise is all coming from the other gearmotor. If so, what would be the best steps to try and stop it?



You have an unusually difficult problem, and until you can pinpoint the cause (e.g. by using an oscilloscope), only guesswork can be offered.

Even the "slight pulse" you mention (using the other motor) is cause for concern.

Filtering. Add filter caps to the motor leads.

Also don't share any power leads with the other motors, instead connect them together only at the battery poles.

Thanks a lot for the replies.

Unfortunately I don't have a scope, so I'm certainly willing to go with 'best guess' at this stage.

Could I ask, what spec and type these capacitors need to be for the gearmotor? That way I can order them to try.

I've already put a 0.1uf ceramic capacitor across the gearmotor terminals.

Thanks again,


I've already put a 0.1uf ceramic capacitor across the gearmotor terminals.

Those type/size should do. Ceramic is best for this kind of filtering.

If your motor has a metal case, try also adding caps between the terminals and the case for additional filtering.

Success!!! The extra 2 ceramic capacitors soldered to the motor body seems to have made a massive difference. I'll have to test it further, but it seems to have solved the problem! When I finally route the cables in the chasis, is the idea to keep the sensor & motor cables as short as possible? I've also read to route the sensor wires away from the power lines, but to do that I'd need longer cables. So my question is, which is most important?

Thanks a lot to everyone who has helped with this.