DC Motor Power

I'm trying to control a small dc motor right now, with the transistor connected to pin 9, and it does run when I use analogWrite(9,255). The thing is, when I use analogWrite(9,0), it goes to half the speed of 255.

This is the code:

int motorControl = 9;

void setup() {
pinMode(motorControl, OUTPUT);

}

void loop() {

analogWrite(motorControl, 255);
delay(5000);
analogWrite(motorControl, 0);
delay(5000);
}

Am I missing anything?

What is the part number of the transistor?
What is the rated voltage of the motor and the stall current?

Am I missing anything?

A schematic of the motor wiring.
A photo of the actual wiring.
Code tags. http://forum.arduino.cc/index.php/topic,148850.0.html See #7.

Here is the diagram:

It looks like you are trying to power a dc motor with a arduino pin.

Not a good idea.

You should put a 1K resisstor between the arduino pin and the base of the transistor. Then you should put 5V on the collector. Then put the motor on the emitter pin.

Don't forget a diode between ground and the emitter. A pin to ground and K pin to emitter.

Unsigned_Arduino:
You should put a 1K resisstor between the arduino pin and the base of the transistor. Then you should put 5V on the collector. Then put the motor on the emitter pin.

:o An emitter follower could work for a super tiny 3volt motor, but not for anything else.

If an NPN transistor is used, then the motor/diode should go between supply(+) and collector, with emitter to ground.
Base resistor value should be calculated, and depends on motor current and type of transistor.

But OP seems to be using a mosfet of the "unknown" variety, and has connected things very wrong.
First diagram here is the right way to connect a motor to a 12volt (or 9volt) supply.
Not very wise to power a motor from Arduino's 5volt pin.
Leo..

No details of the motor. No details of the transistor. No details of what is powering it all. Unreadable Fritzing diagram (seems to have connections to only one leg of the transistor - that's never going to work).

Not much chance of us sorting that out.

Steve

Most of us know how to draw a schematic right?

I missed a wire, sorry about that, i had a 5v wire coming to one of the transistor pins

This is what I have:

Everything in that diagram is wrong.
Can't even find one wire connected right.
Leo..

Wawa:
But OP seems to be using a mosfet of the "unknown" variety, and has connected things very wrong.
First diagram here is the right way to connect a motor to a 12volt (or 9volt) supply.
Not very wise to power a motor from Arduino's 5volt pin.
Leo..

@AlohaGuys, listen to @Wawa and follow the link!!!

You should use a new Arduino when you use the diagram from the link because you probably shorted your Arduino by now.

I would use the diagram, except, unless I'm mistaken, the motor in the diagram is only connected to 5v, and I want to turn it on and off with a delay. 5v gives continuous power, but with out both the 5v and pin 9, it doesn't even turn on.

Unsigned_Arduino:
You should use a new Arduino when you use the diagram from the link because you probably shorted your Arduino by now.

It still works.

Wawa:
Everything in that diagram is wrong.
Can't even find one wire connected right.
Leo..

It was the only wiring that actually worked when I experimented with it.

AlohaGuys:
I would use the diagram, except, unless I'm mistaken, the motor in the diagram is only connected to 5v, and I want to turn it on and off with a delay. 5v gives continuous power, but with out both the 5v and pin 9, it doesn't even turn on.

That story doesn't make a lot of sense (to me).

A motor runs when it's connected to + and - of a power supply.
If you disconnect the + wire, the motor stops running,
but if you disconnect the - wire, the motor also stops running.

The diagram in the link disconnects the - wire of the motor with a mosfet used a a switch,
because it's electrically easier to connect/disconnect the - wire.
Leo..

AlohaGuys:
It was the only wiring that actually worked when I experimented with it.

If your current wiring works then your actual wiring definitely isn't what you have drawn. So we're no nearer knowing what you're actually doing. And you still refuse to tell us what motor and what transistor you're using or to show a picture of your set up.

Good luck with your experiments.

Steve

Before you post another schematic, learn how to draw a schematic!!!

A circuit diagram needs the following: identification of part numbers, clear layout, correct symbols for
components.

Any use of a FET or transistor without connecting all three leads is clearly wrong.

You've done enough wrong that there's a serious chance you've fried an Arduino pin.

When connecting a motor or other inductive load you have to get things right or risk damage,
that means using a free-wheel diode, and connecting the transistor or FET the right way from
the beginning - no guesswork please.

The diagram here for driving a relay is perfectly good for driving a small DC motor too:
https://www.electroschematics.com/8975/arduino-control-relay/, but use a 150 ohm base resistor, not a 1k, and a 2N2222 or other high current switching transistor instead of a BC547.

The motor replaces the winding of the relay (the box with a line through it is the winding).
The diode is absolutely required. The resistor is absolutely required. If you use a MOSFET instead of
a BJT then it must be a logic-level power MOSFET.

slipstick:
If your current wiring works then your actual wiring definitely isn't what you have drawn.

I assure you this exactly what I have. I double-triple checked.

slipstick:
And you still refuse to tell us what motor and what transistor you're using or to show a picture of your set up.

Transistor: N channel MOSFET (on package it said Major Brands IRF540 Transistor).

Motor: 12v DC toy motor