Spurious digital input when touching stepper motor case

I have an Arduino connected to some stepper motors (with A4988 drivers mainly) and a push button switch (first figure below). Occasionally when I touch the case of a stepper motor, I get a spurious reading on the digital input for the switch. The motors need not be moving during this test. More odd, it’s likely to happen when I touch the stepper motor with a piece of metal rather than with my hand, and if I stand up rather than sit down (no, I am not grounded), so I assume it’s static electricity. I measure infinite resistance (or at least out of range – high megaohm) resistance between the motor case and each wire on two different NEMA 17 and NEMA 23 motors.

To better understand this, I even reproduced similar behavior on a second much simpler circuit (second figure below) containing just an Arduino and a switch, tested in a different room upstairs. When I touch ground (through a 33K resistor), sometimes I see that spurious reading on the switch’s digital input (and sometimes a thin spike on an oscilliscope). The spurious reading goes away if I disconnect the long (~4 foot long) wires to the switch or protect the digital input with a 1K resistor and 0.1uF capacitor as shown. Thinking that may be the solution, I tried adding similar protection to the switch in my first circuit or even just disconnecting the switch wires entirely, but the behavior still remains in the first circuit…

I’m using a 12VDC Pololu wall mount adapter to power these through the Arduino Vin. I tried even grounding the stepper motor case to the ground from this power supply, but that doesn’t help. I have a few > 100 uF capacitors and common ground on the A4988’s power as required, plus 0.1uF on both Vin and 5V.

What might I be missing?




Hello.

It appears that your button is set up to ground the I/O pin on the Arduino, but I do not see a pull-up resistor. Are you using the internal pull-up resistor? If so, you might try using a ~10k external pull-up resistor on the pin.

By the way, it is probably not related to your spurious switching problem, but it looks like you could be running several amps of power through the breadboard rail you are using for the stepper motor power. Generally, it is not reliable to run that sort of power through the breadboard and you could have a large voltage drop across those connections to your steppers.

-Nathan

Thanks, Nathan, I’ll try the external pull-up (was using an internal INPUT_PULLUP).

Yeah, I know, a protoboard would better rated for this, though currents are dialed low for testing, and I even observed this with a single A4988 on a breadboard (and somewhat with none at all, like my second figure).

(List of cool companies: Digikey, Pololu, Adafruit…)