Thursday, January 12, 2012

SparkFun Inventors Kit CIRC-03 - Motor not working (spinning)? It's an error in the instructions

I've started playing with some basic tutorial/toy electronics stuff using the Arduino platform and the "SparkFun Arduino Inventors' Kit" (hardly "inventors'", but anyway...) after picking it up as part of an order from the awesome outfit Little Bird Electronics. While generally good, I've hit an interesting issue with the kit that's worth documenting for anyone else who has it.

The short version: If you're using the SparkFun kit that specifies a 10kΩ resistor and the test circuit doesn't work (the motor won't spin) you might need to use a lower valued resistor between the transistor and pin 9 of the Arduino board.

If this is the case, you'll find that when you flick the motor's drive around with your fingers so it spins, sometimes it'll spin down slowly and sometimes it'll stop suddenly, depending on whether the Arduino is currently trying to drive it or not.

Check for all the usual errors before assuming the issue described here is what's wrong with your circuit. You might've reversed the flyback diode, made a poor connection on a power rail, etc etc.

The SparkFun kit for CIRC-03 ("Spin Motor Spin - Transitor & Motor") is based on Ardx CIRC03 but it has one difference that looks like it may be a significant error.

The SparkFun instructions specify a 10kΩ resistor but, at least with the motor supplied in my kit, the test circuit won't actually work with that much resistance between the P2N2222AG (actually marked P2N222A18 in my kit) transistor's base pin and pin 9 of the Arduino Uno board. Replacing the 10kΩ resistor with a 2.2kΩ resistor - like that specified by the ardx instructions - fixes the problem, allowing the transistor to pass enough current to let the motor spin.

A quick read suggests that P2N2222AG and P2N222218 are functionally equivalent, with different date codes or serial numbers, so that shouldn't be the cause of the issue.

If you bought the kit and don't do any other electronics stuff you may not have a 2.2kΩ (red-red-red) resistor or anything vaguely similar lying around. If so, you can always connect up 6 (or so) of the 330Ω resistors supplied in the kit in series to achieve roughly the same resistance. Or you can wind four 10kΩ resistors in parallel, which might be easier.

Remember that to get them connected in series you must put the input of one and the output of another alone on a breadboard row. Connecting five or six of them will give you a sort of stair-step or saw-tooth pattern where you have resistors connecting, say, F14-G13, F13-G12, F12-G11, F11-G10, F10-G9 and F9-G8. You can then plug the lead from the transistor base pin into F8 and the lead from Arduino pin 9 into the other end of the resistor series at G14. If your resistors have long leads and you don't want to clip them you have to space everything out a bit more than this to avoid shorts across all those resistor wires; this is just an example of how it can work.

To make sure my motor wasn't just defective I bridged it across the +5V and -GND rails. This probably wasn't a smart thing to do without a resistor in series with the motor; I got away with it, but you might not.

Update 2012:: Note that I put the motor between the +5V supply rail and GND, not between a digital output pin and GND. The latter might fry your Arduino, don't do it. The Arduino has USB over-current protection, but it doesn't have any over-current protection on the digital output pins.


  1. I got it working because I found your page. I spent about 3 hours trying to figure out why it's not working; all the time thinking that I must have wired something wrong somewhere.

    Thank you very much!

  2. Same here - cheers. I'll see what I've got lying around, but I doubt I've got anything similar in the box.

    Might have to miss this one out

  3. This page was just the right answer for me too. I had a 2.2k in my collection of stuff and still had to manually spin-start the motor. The other two programs won't run well with a manual start on the motor, though. Perhaps I have a minimally defective motor, but I can live with that for the purposes of this experiment/lesson.

    Thanks for the fix.

  4. Just found this on the sparkfun site.

    Note: There is an error with CIRC-03. Omit the 10K resistor and hook pin 9 directly to the base of the transistor.

    Wish they would update the material or add a note to the package itself!

  5. Many thanks Craig - that substitution fixed it for me too. (Well, actually I linked 7 x 330ohm resitors in series to make an equivalent of 2.31k ohms, since that's all I had available in my kit, between the transistor and pin 9 of the Arduino board. CIRC 03 worked perfectly with this).

    Much appreciated - and agree with Jem's post above!


  6. Thanks for this. I spent about 30 minutes on it and hopped on google - found your page. Good one. I'll have a crack at it tomorrow.

  7. It worked for me too, thanks for the suggestion!

  8. Hi,

    I tried with two 10k resistors in parallel, and it worked a little better, although I had to spin it manually in the beginning. I noticed, however, the transistor got quite hot. Won't hooking it up directly to the Arduino pin fry the transistor?


    Miguel Arroz

    1. Yeah, winding 5+ 10k resistors together would be fine.

      I don't understand why you fear hooking the base pin of a BJT transistor up to an Arduino pin risks frying the transistor. An Arduino digital pin on high can drive about 50mA ( at 5V. That as a base->emitter current on a BJT NPN transistor isn't going to hurt it. You're not going to get close to that level of current with 5k of resistance as in your circuit, or 2.2k as called for in CIRC-03, in the +5V-resistor-base-emitter-ground path anyway. Assuming ideal zero resistance from the transistor, Ohm's law says you'll draw:

      I = V / R (units: I in amps A, V in volts V, R in ohms Ω)
      I = 5 / 2500
      I = 0.002 (amps)
      I = 2 mA

      which is sweet FA A.

      Because the base->emitter current is amplified on the corresponding collector -> emitter current, a suitable collector -> emitter load could certainly overheat and kill the transistor. I'd be surprised if the motor drew enough, though.

      My poor understanding says that a MOSFET would be a better choice here than a BJT anyway. This application is switching "on" or "off" with nothing in between, which is ideal for a MOSEFT and will cause the MOSEFT to operate at its ideals, not in its inefficient partially-on zone. I suspect they've used a BJT because they're cheap (not that MOSFETs aren't) and they didn't want to add more parts or muddle beginners. I know it would've muddled me plenty when I did those kits.

    2. Um, that should've been 2200 or 5000, not 2500. Either way, tiny current.

    3. Thanks for the explanation. What I'm worried is the collector -> emitter current. Since there will be no resistance to limit the base current, I'm wondering if the transistor won't allow to much current to flow from the engine and fry itself (since it was already hot with using 5k on the base). Or worse, fry the arduino by drawing too much power from the pin (I don't know how well protected the arduino is). I don't mind killing the transistor, since they are really cheap, but frying the arduino would be worse. :)

    4. Note: I'm still a newbie, this is my understanding but in no way authoritative:

      The ardiuno is safe; even a 330 resistor in the +5V -> GND path is enough to prevent overcurrent with Arduino's 50mA-per-pin limit. Again, ohm's law to find the resistance needed to limit a +5V potential to 50mA:

      I = V / R or IR = V
      R = V / I
      R = 5 / 0.050
      R = 100

      You need 100Ω of resistance to protect against over-current from an Arduino pin to ground in a simple resistive circuit. You've got 5000Ω in that path, you have 50 times the resistance required.

      Read 10 ways to destroy your Arduino for things that aren't safe. Don't try them, please.

      As for excess current on the transistor's C->E junction: DC motors aren't a resistive load, they're an inductive load (mostly). Their resistance isn't particularly high, but current is still limited by the inductive/magnetic properties of the motor. There isn't any resistance (theoretically) in the [+] -> [collector->emitter] -> motor -> GND path, but current is still limited by the motor, just not resistively. In practice of course the wires, the transistor, and the motor all add a small amount of resistance too - try measuring it.

      A bit of reading suggests that the motor's worst case is when stalled, as it's then pretty much just a resistive load, and not much of one. Your transistor is probably getting too hot because your motor isn't going fast enough, strangely enough.

      "In the absolute worst case (stall) then, yeah, it appears as a resistive load since the inductance will allow the DC current flow through a single winding to eventually reach a level where the current is now limited by the resistance and thus no longer rises meaning the inductance then appears as a short"

      When the motor is not acting as an inductive load, you have a [+] -> transistor -> motor -> GND circuit where current is only limited by the other resistance on the circuit - the transistor. The transistor will be dissipating the power from the current through it multiplied by the full 5V potential difference. It'll get quite hot, depending on how much C-E current the B-E current is allowing to flow and what the intrinsic resistance on the transistor and stalled motor are. I don't know BJT transistor physics well enough to work the numbers out or give a good explanation, I'm afraid.

      What it boils down to - from my limited understanding - is that you'll be fine if the motor is actually running, but could over-current and overheat the motor + transistor if the motor is overloaded or underpowered and stalls.

      You don't really want a resistor in the [+] -> [C->E] -> motor -> GND path, as it'll just waste power. I'm not sure what the best way to prevent overcurrent in that circuit without wasting power is; it's a bit puny for a fuse. Wikipedia knows though:

    5. OK, did a little looking around. If you want to limit the +5V -> [C->E] -> motor -> GND current without adding too much unnecessary resistance, you can use a PTC / PPTC. It'll still introduce some resistance (and thus power loss) in normal operation, but protects against shorts and overcurrent.

      You can use these in series on your Arduino pins if you're worried about overcurrent damage, and a bigger one on your +5V rail if you're not able to rely on the Arduino's built-in overcurrent protection (say if you're driving the Arduino via the VIN pin or DC connector instead of via USB).

  9. Thank you so much for posting this! Like most people, I assumed the problem was with how I wired the circuit, so I sat there for an hour or two beating my head against a brick wall trying to figure out what was happening!

    The thought had occurred to me that the transistor might not be getting enough bias voltage/current, so I divided the 10k resistance in half by adding another one in parallel, but that had no effect in my case. Thing is, I pulled out a voltmeter and noticed that when the transistor was supposed to be open, the voltage drop across it (emitter - collector) was still something like 4.7V. That's when I started searching for others who might have the same issue...

  10. Same problem here...spent the last 30 min wondering what I had done wrong, de-wired, re-wired...check diagram etc...

    Quite irritating really!

    Thanks for posting this.