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.
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).
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..
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.
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.
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.