SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
#137581
My 11-year old son and I are LOVING the Sparkfun Inventor's Kit; we bought two so we can work side by side (new kits, shipped a week ago). We're working on CIRC-03 (Spin Motor Spin) but have hit a wall. Code is exactly as listed in manual and verifies fine. Wiring seems correct as well - and as mentioned we're working in duplicate. Verified that transistor is P2N2222A as spec'd. Verified resistor is 10k using multimeter. Tried diode both ways to be sure. Tried resetting board and re-uploading. Nothing. Motor runs fine when directly connected to power so that's not it. Any known problems with this CIRC? Many thanks in advance for your help!
#137588
I assume when you say "hit a wall" that the motor does not spin. Since it splns when connected directly to 5V you correctly believe the problem lies elsewhere than the motor. I'll assume you've checked and rechecked the wiring for obvious problems so if you're comfortable using the voltmeter I can guide you through some more troubleshooting. But first checkout the video (if you haven't already) to see if it resembles what you've done.
http://www.youtube.com/watch?v=K3GtbPcOT50
1) On the breadboard verify there's +5V at the rails where it's supposed to be.
2) If so then move the + probe of the voltmeter to the motor lead with the "blue wire" (as shown here, in real life no doubt a red lead/wire). Verify there's +5V there as well.
3) If so then verify there's +5V at the collector of the transistor.
4) Lastly move the - probe of the voltmeter to the emitter of the transistor and verify that between the collector and emitter there's +5V.

If this is all true then it appears all the power and wiring to carry the motor current are proper. If seems as if the transistor is not switching. What should be happening is the transistor will act like a very fast opening & closing switch, connecting ground to the motor's "purple lead" when it's "closed". The longer the transistor is "closed" the faster the motor runs. At least that's the theory. In your case power is not where it needs to be (an open circuit someplace) or the transistor is not doing it's job (that could be a hardware or software problem). My GUESS at the simplest answer is that the transistor is plugged in backwards. This would be easy enough to do and it's not at all clear to me how you've been instructed to plug it in. Try flipping it around and see if it works then.

If you still can't remedy the problem after the above, check the voltage at both ends of the resistor and post back.

ps - do be sure to have the diode plugged in properly. If it's reversed it'll be shorting out the motor and suppling nearly 5V and high current to the transistor, which will do it no good.

http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf
#137647
Hey Mee_n_Mac and Chanler -
Many thanks to you both for your help! I walked through all your suggestions and got the results you suggested I should be getting. As I final step you suggested "check the voltage at both ends of the resistor and post back." I'm getting about 1.8v across the resister for about 1-1.5 secs, then flipping to -0.4v for 0.5 secs or so, constantly repeating. This is despite rock steady 4.89v across the rails. Not sure what this means.

FYI, I did flip the diode at one point just to see if it made a difference; did not.

One strange thing: The schematic that Chanler provided lists a 10k resistor, as does the schematic that came with my kit:
http://ardx.org/bbls03s/
However, the schematic that Mee_n_Mac provided lists a 2.2k resistor, with everything else being the same:
http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf
I'm not sure whether this is important or not. I don't have a 2.2k resistor on hand but I have a stack of 330 Ohm resistors that came with the kit, so I strung 7 of them together to create a rough 2.2k, but circuit still did not work.

When all this was done I again connected the motor directly to 5v and it worked fine. Weird!

Here's my code:

int motorPin = 9;
void setup()
{
pinMode(motorPin, OUTPUT);
}

void loop()
{
motorOnThenOff();
}
void motorOnThenOff(){
int onTime = 2500;
int offTime = 1000;
digitalWrite(motorPin, HIGH);
delay(onTime);
digitalWrite(motorPin, LOW);
delay(offTime);
}
#137651
StudioLou wrote: I'm getting about 1.8v across the resister for about 1-1.5 secs, then flipping to -0.4v for 0.5 secs or so, constantly repeating. This is despite rock steady 4.89v across the rails. Not sure what this means.

FYI, I did flip the diode at one point just to see if it made a difference; did not.

One strange thing: The schematic that Chanler provided lists a 10k resistor, as does the schematic that came with my kit:
http://ardx.org/bbls03s/
However, the schematic that Mee_n_Mac provided lists a 2.2k resistor, with everything else being the same:
http://ardx.org/src/circ/CIRC03-sheet-OOML.pdf
I'm not sure whether this is important or not. I don't have a 2.2k resistor on hand but I have a stack of 330 Ohm resistors that came with the kit, so I strung 7 of them together to create a rough 2.2k, but circuit still did not work.
My first impression is that given all the places that are supposed to have 5V do, the wiring is good. That you see some changing voltages across the resistor tells me your code is running and outputting to the correct pin. Your measured times are 50% of the times you've programmed but that's OK. So it appears you're doing everything needed to make the transistor switch and yet it isn't. It's hard to believe that both transistors are bad (possible, just unlikely) so I ask if you tried reversing the orientation of the transistor (not the diode) ? If you have an LED you could put it between the base and emitter of the transistor (remove the transistor) and see if it lights up, on and off, as you've seen for the resistor voltages. This will just visually confirm that the Arduino output pin is doing the right thing.

What happens in either case is that when the Arduino pin output is low (~0V) no (or very, very little) current flows out of the pin. With no current flowing there's no voltage drop across the resistor and you should measure 0V across it's terminals (and also ~0 V at each of it's ends, referenced to ground). When the pin is high (~5v) current should flow through the resistor and transistor base (or LED) to ground. With current flowing there will be a voltage drop across the resistor. The pin end should be ~5V wrt ground (obviously) and the transistor end about 0.6+ V (again wrt ground), a bit higher with an LED, depending on the LED type. The voltage across the resistor is (obviously) the difference between these 2 voltages. I'll think about the measurements you reported a bit more tomorrow. :?:

FWIW the 330 vs 2200 won't make a diference. It puts more current through the base of the transistor than is required but not destructively so. Using 10k vs 2.2k just might make a difference. I'd have to review the characteristics for a 2N2222 to be sure. If you've been using a 10k, try a single 330 instead (stringing 7 to get ~2200 is too hard).
#137655
As it turns out I had a simple 2N2222 circuit already in my Spice collection. So I simulated the motor as a simple resistor and was surprised to find out that any base resistor (the R in your circuit) above ~1200 ohms yeilded a reduced motor current. A 2.2k reduced the current to about 66% of the 340 mA that would be the nominal amount (no load on the motor). Using a 10k knocked it down to only 70 mA and I might just wonder if that amount would provide sufficient torque to overcome the motors inherent friction. So definitely try a 330 ohm resistor and see what happens then !

As for myself, now I'm really curious as to what the hFE (DC current gain) a 2N2222 is.
#137677
As a thought, try to run the blink example code and move the wire from pin 9 to 13. If the LED comes on, then we know the arduino is powering up the pin correctly and the motor should come on at that time.

The only other thing I can think of is to change the line:
int motorPin = 9;
to
define motorPin 9
#137681
This is a very special community;-) I tried all the above suggestions; the LED test confirmed that everything was working except the transistor/resistor combo. I finally replaced my various resistor combinations with a single 330 ohm and - voila! - works perfectly (with either of the 2N2222 transistors included with kit, so no problem there) ! How can we make sure this note gets into what gets distributed to new buyers of this kit? Many thanks again from my boy and me!
#137688
StudioLou wrote: How can we make sure this note gets into what gets distributed to new buyers of this kit? Many thanks again from my boy and me!
I guess you could put a post summarizing your find on the SIK product page, with a link to this thread. Also e-mail SF tech support and moon them ... errr, let them know as well.

And you're welcome.

EDIT : Well DOH, I just read the comments on the product page and sure enough there was a comment there already saying the above. Silly me for not doing what I always ask others to do. :oops:

cap9qd | about 3 days ago
I got this for my father for Christmas. He was working through the lessons and got stumped on the one where you run the little DC motor (Lesson CIRC-03). After finding a bad jumper wire we still couldn’t get it to work. Changed the motor to an LED and resistor to verify the transistor circuit worked and it did. Finally had to replace the transistor base resistor from a 10k to 1k to get enough collector current to run the motor. Hope this helps someone else who has issues.

Note that this was 3 days ago ... argghhhh :mrgreen: