EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: nikolai_korobov on May 05, 2017, 10:59:07 pm

Title: DC motor makes microcontroller freak out
Post by: nikolai_korobov on May 05, 2017, 10:59:07 pm
Hello!
I'm currently stuck with a very basic issue.

Here's my setup:
I have an ESP8266 controlling a 2N2222A transistor (through an 1K resistor) which drives a hobby DC motor and a white LED (motor and LED draw around 80mA running and 120 when motor is stalled).
Motor and LED are powered through 3x new AA batteries, ESP8266 is powered through a regulator which is also powered by the battery (they share ground)
The ESP8266 is programmed through the Arduino IDE and runs the Blink example, which turns on and off pin 14 for about 1 second or so.
I can turn the transistor on and off manually by applying a voltage on its base (this also drivers the ESP8266 crazy).

Here's what I have tried:
I've added 100nF ceramic capacitors to the motor, both between the leads and from each lead to the casing.
This has almost eliminated the issue when I'm powering everything though USB, but the issue still persists when I power though batteries.

I have tried adding a 100?F and 10?F electrolytic cap on the ESP8266, on the motor and on the batteries without any success at all.

Super weird fact: When I'm pressing firmly on the power pins on the programming header (for the TTL adapter I use to program the ESP), the problem seems to go away! I have triple checked for bad connections and I'm pretty sure there aren't any.
Title: Re: DC motor makes microcontroller freak out
Post by: jbb on May 05, 2017, 11:31:38 pm
Not familiar with ESP8266, but here are some guesses.

1) If there's a reset pin on the ESP, you should connect a capacitor from it to ground (I guess 10nF).  Electrical noise can get into reset pins and cause ... resets
2) Add a back-EMF protection diode to the driver.  A basic silicon diode with the anode (A) on the collector of the 2N2222A and cathode (K) on the +ve rail might help a lot

Good luck
Title: Re: DC motor makes microcontroller freak out
Post by: BrianHG on May 06, 2017, 04:02:43 am
Photograph of your setup & schematic please...
Title: Re: DC motor makes microcontroller freak out
Post by: Richard Crowley on May 06, 2017, 05:48:40 am
Extra care for ground currents, etc is necessary. Impossible to help you without seeing how you actually have it wired. 

The ESP8266 is NOTORIOUSLY sensitive to power noise, and it is ALSO notorious for being a power hog. Extra attention to bypassing and power "stiffness" for the ESP chip.

You have a deadly combination and you can't just wire it up any old way and expect it to work. Especially with such a dirty load as a DC brushed motor AND such a wimpy power source as 3xAA cells.

The symptom that you can reduce the problem by pressure suggests that you don't have good low-impedance connections at EVERY point in the power circuit. Any connection that isn't soldered is a prime suspect.
Title: Re: DC motor makes microcontroller freak out
Post by: wraper on May 06, 2017, 05:58:54 am
Not familiar with ESP8266, but here are some guesses.

1) If there's a reset pin on the ESP, you should connect a capacitor from it to ground (I guess 10nF).  Electrical noise can get into reset pins and cause ... reset
Better to use stronger pull-up (lower resistance resistor, like 1 - 5k)
Title: Re: DC motor makes microcontroller freak out
Post by: rx8pilot on May 06, 2017, 06:06:36 am
A schematic and physical image is critical to shake this kind of thing down. Decoupling caps, proper pull up/down on reset pin, long wires, etc will all have an impact on the stability. Motors generate lots of EMI and the MCU needs lots of protection from that.
Title: Re: DC motor makes microcontroller freak out
Post by: rob77 on May 06, 2017, 02:35:16 pm
are you using the node-mcu (or similar)  or are you just using a bare break-out board for the ESP module ?
Title: Re: DC motor makes microcontroller freak out
Post by: james_s on May 08, 2017, 08:12:10 pm
If all else fails,  you could use an optocoupler to isolate the motor from the microcontroller. As Richard mentions, the ESP8266 is notoriously sensitive to power supply issues, most of the modules using it have insufficient decoupling so you will need to pay close attention to that. DC motors tend to spew horrendous amounts of electrical noise so they're among the most challenging loads to mix with sensitive microcontrollers.