0

I've set up a DC motor connected to my Arduino Uno with the following layout. I'm using a 1.5V - 3V DC motor that was purchased from RadioShack.

Here is my code:

int controlPin = 9;

void setup(){
  pinMode(controlPin, OUTPUT);
  Serial.begin(9600);
  while(!Serial);
  Serial.println("Ready"); 
}

void loop(){
  if(Serial.available()){
    int s = Serial.parseInt();
    if(s >= 0 && s <= 255){
      Serial.println(s);
      analogWrite(controlPin, s); 
    }
  } 
}

If I connect the motor through the Arduino 5V pin it only hums until I set the speed s to 200 or greater. This seems odd because I'm supplying 5V.

As a next step I decided to try a 9V battery (I don't really care if I fry the motor, I just wanted to experiment). Of course this is over the recommended voltage, but I assumed if I sent a low enough signal (s) through pin 9 it might not destroy the motor. However, to my surprise, when I connected the 9V battery (as illustrated below) the motor immediately starts spinning. I measured the current and it seems to be ~150mA when connected to the 9V battery. It seems like the circuit is connected even though I'm not sending any signal from pin 9 to the transistor. If I removed any of the wires connected to ground, the motor, obviously, stops spinning. My expectation, which is apparently wrong, was that the motor wouldn't spin until I sent a signal from pin 9 to the transistor. What am I not grasping here?

enter image description here

Here's a picture as my diagram may be wrong based on comments below. This shows the diode reversed as suggested by Chris.

enter image description here

I also moved the jumper going from pin 9 to the breadboard out of the Vcc column and directly into the row with the resistor. I'm not sure if that resolves the short mentioned in comments.

5
  • If you connect the base resistor to ground instead of the Arduino, does the motor stop? If not, you probably have either mixed up the pins of the transistor such that it is merely functioning as a diode (very easy to do - especially "pin circle" vs "pin line") or have already blown the transistor. Aug 14, 2014 at 20:09
  • You should try to respect usual conventions on breadboard usage: the 2 pairs of lines one each side should be reserved for Vcc and GND. The way you wire your breadboard makes it more difficult to interpret.
    – jfpoilpret
    Aug 14, 2014 at 21:51
  • 2
    Also it seems your 280 Ohm resistor is useless because shorted by the breadboard wires.
    – jfpoilpret
    Aug 14, 2014 at 21:52
  • jfpoilpert - thanks. I intended for the 2 pairs of lines on each side to represent vcc and gnd. Do I need to label them as such? Also, can you further explain why the 280 Ohm is useless? I have pin 9 going to the vcc column and then a jumper going from vcc to the row containing the resistor?
    – Marvin
    Aug 15, 2014 at 1:23
  • Currently you don't use the Vcc line as Vcc sicne it is linked to pin 9 not to Vcc. Regarding the resistor, looking at your scheme it looks like it is wired on the same rail of the whiteboard. I you used a better tool for drawing your circuits (eg Fritzing) it would make it easier to read.
    – jfpoilpret
    Aug 17, 2014 at 7:59

2 Answers 2

3

Your wiring diagram is a jumbled mess, and makes it impossible to figure out what's really going on.

My guess is that you have a mistake somewhere in your wiring.

Problems I see with your wiring diagram:

  • You show pin 9 from the Arduino wired to the positive rail of your breadboard. If the positive rail is connected to a 9V battery, this will likely destroy pin 9 of your Arduino.

  • You show the gate/base of your transistor wired to the positive rail of your breadboard. This would switch your transistor on constantly.

  • You show the symbol for a MOSFET transistor, but the label on it lists it as a 222A, which is an NPN BJT, not a MOSFET.

  • You don't show any wires connecting the left and right side rails of your breadboard.

  • You're using a row of your breadboard as the ground rather than the rails.

The picture you posted is too small to tell if your wiring diagram is wrong or if you actually connected things incorrectly, and the wire from your 9V battery is blocking the camera's view of key connections.

It looks like your wire from pin 9 is NOT connected to the power rail, but is instead connected to column 1 in your breadboard, which is good.

There are some strong conventions in wiring with breadboards and you should learn to follow them. The two pairs of columns of sockets on the left and right are for positive and negative supply voltage. Usually you wire them together and connect them to regulated power. Sometimes they will be used for different voltages, although you need to be really careful if you do this, since connecting to the wrong side can fry components.

It's confusing the way you've created your wiring diagram, but it looks like you have your flyback protection diode wired correctly, which is good. That's very important, as DC motors and other inductors create destructive reverse voltages as they are switched on and off, and without a flyback diode it can destroy solid state devices like ICs or even transistors.

You should re-wire your breadboard using the proper conventions, and post a corrected wiring diagram that really shows what's going on.

A picture where we can see all the wires and components clearly would also help.

Until you better learn what you are doing I would strongly advise against powering things directly from a 9V battery. When you do that, a mistake in wiring will fry your Arduino and/or any ICs you have on your breadboard.

Wire the 9V to the V-in pin on your Arduino, and then bring 5V and ground from the Arduino onto the +/- supply rails of the breadboard.

I also notice that in your code, you never set the state of controlPin in your setup method. You should add this line to your setup:

digitalWrite(controlPin, LOW);

That way the pin starts out in the OFF state, and then later on you can us an analogWrite to set it to the desired output level.

3
  • Awesome feedback! Thanks. I see how the diagram is incorrect now. I also understand how my unconventional breadboard wiring is confusing the issue. I'll clean that up. Currently, I'm supplying power to the right hand rails but not crossing it over to the left side, so I don't think I'll destroy pin 9, correct? I realize this layout is still wrong, but just verifying. Also re: MOSFET vs NPN BJT - I wasn't sure which icon to choose in Visio hence the label (I'll correct that too). Again, great feedback. Really appreciate the guidance.
    – Marvin
    Aug 15, 2014 at 14:19
  • Which kind of transistor are you using?
    – Duncan C
    Aug 15, 2014 at 14:43
  • 1
    And what SW are you using to create your wiring diagrams? I use CircuitLab on the EE stack exchange (a web-based schematic editor) but haven't found a good one for use here. (I use Macs BTW)
    – Duncan C
    Aug 15, 2014 at 14:52
2

You need to turn the transistor 180 degrees (assuming you are indeed p2n2222a).

enter image description here

Collector should go to the motor, Emitter should go to ground. In your photo you have those two swapped.

Also, I don't think the diode is the correct way around in that photo. That will just short out the battery, thought admittedly that would prevent the motor from spinning (-:

4
  • Swapping the emitter and collector would be unlikely to result in the transistor always being "on" (it would just make it perform poorly). However, in a transistor package which does not put the base in the center ("pin circle" vs today's common "pin line") then it could indeed be an explanation. Aug 15, 2014 at 20:00
  • @Gerben seems to be correct. I reversed the transistor and two things occurred 1.) when using 5V from the Arduino, I get much better performance. The motor starts spinning around a speed of 40 (vs ~200 previously) 2.) when using 9V the motor doesn't spin immediately. Only spins when I send a signal from pin 9. I also modified diagram and breadboard setup on the main post.
    – Marvin
    Aug 16, 2014 at 1:35
  • 1
    Actually, I take that back - the breakdown voltage when emitter and collector are accidentally swapped might be low enough for 9v to force it on. Aug 16, 2014 at 4:06
  • Emitter - Base Breakdown Voltage is 6V. 9V power minus the voltage the motor uses (3v motor). Could be just enough. Or would the voltage at the Emitter be 9v when the transistor is off? Which would mean any voltage above 6v would make the transistor pass some current, though not much if the voltage is just above 6v? Funny thing; turning pin 9 HIGH might even turn the motor off :-).
    – Gerben
    Aug 16, 2014 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.