# Problems with basic DC motor circuit!

I’m new to arduino after starting a module in it this term. I am currently studying for a masters in architecture so feel very out of my depth doing electronics based work!

I’m trying to complete the activity at Breadboard Layout | Arduino Lesson 13. DC Motors | Adafruit Learning System using a MFA 6-15V Medium 9869 rpm Motor I purchased on recommendation after explaining what I needed to do to somebody at Maplin.

For some reason, when setting the circuit and code up as drawn/written in the example, it didn’t work. I accidentally pulled the jumper wire from GND - the (bd237) transistor out and stuck it the same row as the collector pin by mistake. This got the motor to work - although I’m not sure why?

Would anybody be able to point out why this worked and if it’s going to ruin something by running like this?

Also, I have tried using code to slow down the speed/rpm of the motor (another thing we have been asked to do) but this will not work. Is this because of the type of motor?

Apologies for knowing so little and asking so much.

Thanks in advance!

``````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);
}
}
}
``````

Adafruit should be ashamed that they posted that lesson -- it gives very bad advice. The people at Maplin should know better too.

Motors create severe electrical noise and almost always draw too much current to be powered by an Arduino. In fact, attempting to power a motor from the Arduino is a good way to destroy it.

Always use a separate power supply (4x AA batteries will work for most small motors) and be sure to connect the negative battery pack lead to the Arduino ground.

It is possible that the transistor has been damaged by incorrectly connecting it, but try again with correct wiring (but using a separate battery pack for the motor) and tell us what happened.

It worked because you bypassed the transistor completely.

BD237 hey? Ancient device, remember using that in the 1980's, not a patch on
any logic level MOSFET really. Assuming your motor takes less than 250mA the
given circuit might work. If the motor has a stall current above that it may overload
the transistor and just overheat it.

Thank you both for your feedback.

jremington:
I re-wired the circuit to the diagram with the battery pack going into the power Jack and the motor now turns however I am still unable to input any numbers to control the motor speed it just goes at one (quite fast) speed!

MarkT:
My in class course called for a TIP102 or a 2N2222 transistor and the BD237 was what they gave me at Maplin (out of what they had in store). Any ideas on what would be better? Is this likely to be the cause of my problem?

Thanks again, I really appreciate you both giving the time to help.

Hi,

When you look in the terminal window, do you get the "Speed 0 to 255" printed in it?

Have you got the terminal baud rate set to 9600?

Tom....

Hi Tom.. yes to both!

However whatever I type in does nothing to the motor.

Hi,

Okay
immediately after

analogWrite(motorPin, speed);

put

Serial.println(speed);

This should send back what speed value was received and used in analogWrite.

Tom…

It's coming back with all 0's:

Speed 0 to 255
0
0
50
0
100
0
255
0

Not what I was expecting and now I'm even more confused.. apologies for being such a novice.

One problem is here:

``````  if (Serial.available())
{
int speed = Serial.parseInt();
``````

Serial.available() just tells you if one or more characters has been received, not whether an entire useful number has been received. As it is now, your program tries to interpret just one character.

Robin2 kindly wrote Serial input basics to help you out.