Pages: [1]   Go Down
Author Topic: 9v Motor + Mosfet + Arduino = timing errors/crashes?  (Read 733 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone

I just recently got an arduino along with a bread-board and some additional control circuits (and of course a power supply, in my case it's just an AA battery pack, 6 AA's, which add up to 9 volts) and I made a circuit where there are 3 leds, controlled by the arduino. I hooked diodes on two of the outputs because I wanted to make the Mosfet, and thus, the motor, turn on when two of the lights were on, but not when the third light was on. I didn't have anything else hooked up because I just wanted to figure out how to control a motor with an Arduino, before I tried to combine motor control with more interaction. The LEDs change at a pre-determined interval, that doesn't use the delay() function, because I know delay() prevents the arduino from reading any other inputs (except interrupts).

It worked fine for a while, and I experimented with other ideas, then re-set up the same system again and re-loaded the program.
The problem I'm currently having is that occasionally, the starting and stopping of the motor causes strange things to happen. Sometimes, the LEDs appear to miss a step or change out-of-time, other times the arduino seems to crash and require a power cycle or a press of the reset button.

I have a diode to prevent a voltage spike from the motor from damaging the mosfet, and I had that last time as well. The mosfet's gate is connected directly to the two outputs (through diodes) without a resistor.

I have been using the same battery for a while and I'm wondering, could a low battery cause timing errors or system crashes when something like a motor turns on and off? Since I haven't had the arduino for that long, I don't know what the effects of a momentary voltage sag are. My other question is, if it's not likely to be a battery problem, would adding a cap between 9V and ground (on the breadboard) help? Or, should I use an external 5V voltage regulator with decoupling capacitors and attach that to the 5v input of the Arduino? (provided, of course, that I verify that the voltage is correct) because I thought the arduino had caps on the board already! Are those not big enough to smooth out the kind of noise that a motor might generate? The biggest caps I have are 470uf, 25v (my battery is only 9v)
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The mosfet's gate is connected directly to the two outputs (through diodes) without a resistor.

I assume you have the diode cathodes connected to the gate, so that the mosfet is on when either output is high. You need a pulldown resistor (1K to 10K) between the diode cathodes and ground as well, to pull the gate down to ground when both outputs are low. Also a resistor (100 to 220 ohms) in series with the gate is highly recommended.

I have been using the same battery for a while and I'm wondering, could a low battery cause timing errors or system crashes when something like a motor turns on and off?

Yes. The motor takes a high current when is turning on, and this will drag the battery voltage down, more so when it is running low.

would adding a cap between 9V and ground (on the breadboard) help? ... The biggest caps I have are 470uf, 25v (my battery is only 9v)

You should use a cap between 9v and ground anyway, value needed depends on the motor but 470uF may be on the low side. Connect the negative side as close to the mosfet source pin as possible.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. In an electronics class that I took previously, we were told that putting capacitors in parralel will result in increased total capacitance. I have a number of different values and about 6 of each, so I will add a 470 uf cap between 9v and ground, in addition to changing the batteries. If that doesn't help, I'll hook a few more caps in parralel with the 470 to increase the total capacitance and thus the noise/sag supression capability.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6619
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, you can parallel capacitors to get more capacitance.

Another thing you can try is:

- Make sure you are feeding the 9v to the Arduino through the barrel jack, not the Vin pin (the difference is that from the barrel jack it passes through a diode)

- Connect a 470uF capacitor between Vin and ground. [Also I recommend at least one between 9v and ground].

The capacitor between Vin and ground will power the Arduino for a little while when the battery voltage drops. Because of the diode, it doesn't power the motor as well; so the charge lasts longer.

btw you haven't said what else you have connected to the Arduino, however another possible explanation for the symptoms is shared ground lines. I recommend that you use one Arduino ground pin to connect the ground sides of any input devices you have, and a different ground pin to connect power and the ground side of output devices.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: