DC Motor not working from breadboard

So, first of all, I'm very new to all this. Started school 4 weeks ago, and we've been working with Arduino stuff for most of the time. I thought I was starting to get the hang of it, but I'm not sure anymore.

Last week, I managed to (finally) get a DC Motor to run.
Here are pictures of the setup and a breadboard view:
IMGUR ALBUM

And the code:

int motorPin = A3;
 
void setup() { 
} 
 
 
void loop() { 
  analogWrite(motorPin, 1023);
  
  delay(1000);
  
  analogWrite(motorPin, 0);
  
  delay(1000);
}

(I used digitalWrite at a later stage in our school project)

Today, at school, the motor was working for a while. But I noticed later that day, it did not. I thought maybe it was the code, and ignored it and worked on other things of the project.

When I got home, I decided to check the motor. It worked when directly applied to a power source. But not always when the power came from my breadboard.

I made an exact copy of what I did above, and it did not work. Using a LED instead of the Motor did make the LED blink on and off.

I tried to make it a bit more simple. Like these:

They did not work.

A more direct approach:

This worked.

I'm completely lost. Could something be broken, or am I missing something?
This is quite essential to our school project and I really need to know what's going on.

Looking forward to reading your replies.

Please don't waste your or our time on Fritzing diagrams. Pictures that don't show all the wires, with clear paths are almost useless. A hand drawn wiring diagram is much better than either.

The diagrams do suggest that you have no common ground connection between the Arduino and the motor board, and that you have no transistor or other means to control the motor (which is required). Google "arduino dc motor" for lots of suggestions on how to wire this up.

You have the motor directly across the battery with no means to control it.

Weedpharma

jremington:
Please don't waste your or our time on Fritzing diagrams. Pictures that don't show all the wires, with clear paths are almost useless. A hand drawn wiring diagram is much better than either.

Like I said, I just started this whole Arduino thing and it's for school. I'd love to learn more about it but I don't have much time. That being said, I have no clue how to draw anything for this kind of thing so this is kind of all I can give for now.

The diagrams do suggest that you have no common ground connection between the Arduino and the motor board, and that you have no transistor or other means to control the motor (which is required).

weedpharma:
You have the motor directly across the battery with no means to control it.

Weedpharma

http://imgur.com/a/0avZ0
The first picture in this album shows me using a transistor. It worked in the past, but when I recreate this setup it does not. And I don't know why and I want to learn why it does not work or why it's so unstable.

Google "arduino dc motor" for lots of suggestions on how to wire this up.

I've done this countless times before, and recreated all of them to no success. I guess I can try again.

EDIT:
So I recreated this example (LINK) and ... it does not work.

I use this P2N2222A transistor. The flat side is facing the right side of the breadboard and the diode stripe is facing upwards.

I tried multiple transistors and diodes but none made it work.

EDIT 2:
Connecting it to a LED does work though. Just the motor doesn't work atm.

You say it did work then stopped. This suggests a change on the way it is connected , IE, a bad connection.

Try rewiring in a different part of the board. And then try a different output port.

What transistor are you using?

Weedpharma

weedpharma:
You say it did work then stopped. This suggests a change on the way it is connected , IE, a bad connection.

Try rewiring in a different part of the board. And then try a different output port.

What transistor are you using?

Weedpharma

I'm using P2N2222A Transistors. Connecting it like this website suggests does not work for my motor. But it does work for an LED. I can power it with the Serial Monitor on my computer.

Also connecting a 9V as power source works for the LED, but still not for the motor.

Hi,
What course did you start?
You need a grounding in basic electronics, which seems this course is missing.
How does your teacher/lecturer draw circuits for you?
What are you using to power your motor/sketch?
Do you have a DMM to check voltages around your circuit?

Can you post a picture of your project please so we can see how you have assembled everything.

Tom.... :slight_smile:

TomGeorge:
Hi,
What course did you start?
You need a grounding in basic electronics, which seems this course is missing.
How does your teacher/lecturer draw circuits for you?
What are you using to power your motor/sketch?
Do you have a DMM to check voltages around your circuit?

Can you post a picture of your project please so we can see how you have assembled everything.

Tom.... :slight_smile:

My study is called Creative Media and Game Technologies. It's in The Netherlands.
We were given these tools to make something out of. We are given complete freedom, and have no teacher or lecturer with extensive knowledge about these things as far as I know. When I asked how to make a Motor Controller (so the motor could turn both ways) all I got was confused looks, which was not very promising.

I'm powering everything either from USB -> Arduino -> Board or Battery -> Arduino -> Board.

I don't know what a DMM is, so I'm pretty sure I do not have it.

Here are the pictures: http://imgur.com/a/md5zE

Hi,
Thanks, looks okay.

Can you post a copy of the sketch you are using, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

DMM, digital multimeter.

Tom.... :slight_smile:

This one is from the website I got my design from (here). I can adjust the analog data send from pin 3 by writing a number from 0 to 255 in the Serial Monitor.

int motorPin = 3;
 
void setup() 
{ 
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");
} 
 
 
void loop() 
{ 
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
}

And there is this simple loop to open and close every second.

int motorPin = 3;

void setup() {
  pinMode(motorPin, OUTPUT);
}

void loop() {
    analogWrite(motorPin, 1023);
  delay(1000);
  analogWrite(motorPin, 0);
  delay(1000);
}

Hi,
Your looping sketch is trying to send 1023 to analogWrite, it can only be 0 to 255.

Tom.... :slight_smile:

Changed it accordingly, still nothing from my motor though. LED still blinks on and off just fine.

int motorPin = 3;

void setup() {
  pinMode(motorPin, OUTPUT);
}

void loop() {
  analogWrite(motorPin, 255);
  delay(1000);
  analogWrite(motorPin, 0);
  delay(1000);
}

Directly connecting my motor with cables on the + and - strip makes it spin. So it's not broken at least.
Neither is the transistor because the LED is working fine.

Hi,
What is the value of your resistor that connects to the base of the transistor?

Tom... :slight_smile:

1000 ohm. I tried all resistors (higher and lower ohm) I got but none make the motor spin.

What happens if you put a 10k R from the base of your transistor to 5v? This should turn on the transistor and hence run the motor.

In the photo, it looks like you have plugged the ground into Aref though it may just be the angle.

Weedpharma

Hi,
You are using P2N2222A, this has its EBC leads the other way around to a 2N2222A.
Unplug your transistor and turn it around 180Deg and see if that fixes it.

I only checked 2N2222A on google and looked at the images it showed.

hmmm didn't know that, I don't use 2N2222A's.

Ya learn sumthin everyday.

Hope it fixes it.. Tom.... :slight_smile:

P2N2222A_datasheet.pdf (86.1 KB)

TomGeorge:
Hi,
You are using P2N2222A, this has its EBC leads the other way around to a 2N2222A.
Unplug your transistor and turn it around 180Deg and see if that fixes it.

I only checked 2N2222A on google and looked at the images it showed.

hmmm didn't know that, I don't use 2N2222A's.

Ya learn sumthin everyday.

Hope it fixes it.. Tom.... :slight_smile:

The LED still works, but much brighter, when I turn it 180.
The motor still does not work.

weedpharma:
What happens if you put a 10k R from the base of your transistor to 5v? This should turn on the transistor and hence run the motor.

In the photo, it looks like you have plugged the ground into Aref though it may just be the angle.

Weedpharma

It did not turn on the motor. It did turn on the LED when I connected it.

Hope I connected it like you asked. Photos: http://imgur.com/a/u6Mqs

Use a multimeter to check the voltage at the motor on the motor terminals, not on the breadboard.

If you do not have a multimeter, put a LED and series R across the motor terminals.

Weedpharma

Hi,
I think your method of connecting the jumpers to your motor is a bit dodgy, you need a good stable contact between the wires and the motor tags.
Also be careful, those jumpers are in the pictures almost shorting to the motor case.

You latest pics show the transistor still connected the way as in previous pics.

Look at the data sheet I attached to post #15, if you have P2N2222A you need to use this sheet.
You need a DMM to help you.

Tom... :slight_smile:

I agree with the need to have a multimeter.

It is a waste of time trying to do electronics without one. Even a cheap one is better than none at all.

Weedpharma