Controlliong the speed of the motor with 2N2222 transistor and PWM not working!!

Hi, I'm trying to control the speed of a 3.3v coreless DC motor. Unfortunately, the motor runs at full speed and the PWM code does not work. The emitter is connected with Ground Pin. The collector is connected to 3.3v output of the board and base is connected to pin 9 (PWM). The PWM code works for LED (example: Fade) but it does not work for the motor setup. I have attached a basic schematic with the question. The board is powered by 5v power source.

Board: Arduino Nano 33 BLE Sense
Transistor: 2N2222
Diode: 1N4007

You cannot use the Nano 3.3v to power a motor.

That circuit connection is wrong.

Study these circuits:

Study these circuits:

@LarryD,
You're getting a lot of mileage out of that schematic..

It’s best to say here it is, help yourself ;).

@ raschemmel
I like your new face lift !

I like your new face lift !

Thanks !
I thought I'd turn over a new leaf ...

It's best to say here it is, help yourself

or,
"A picture is worth a thousand words..."

Do a little "visual walk" from 3.3V to the motor and back to ground. See?

1 Like

Do a little "visual walk" from 3.3V to the motor and back to ground. See?

The motor with the parallel diode should have +3.3V on the positive side and the "-" side should go to the collector.
The way it is the transistor is a direct short across the motor (bypassing the motor) which is why it doesn't work.

You are no fun :frowning:

This is an example of why it is such a good idea to keep "power" at the top of a schematic, and "ground" at the bottom. The short circuit would almost "jump off the page" if it was laid out that way.

You are no fun

That's what BallscrewBob said.

This should work better --

see attachment

Screenshot 2020-12-22 113456.jpg

Screenshot 2020-12-22 113456.jpg

Ah ok. Thanks a bunch :slight_smile:

raschemmel:
The motor with the parallel diode should have +3.3V on the positive side and the "-" side should go to the collector.
The way it is the transistor is a direct short across the motor (bypassing the motor) which is why it doesn't work.

2N2222 is a NPN, it works best in this arrangement Sinking current to Gnd, vs Sourcing current to a load.
Put the motor/diode between 5V and the NPN collector, with emitter to Gnd.
Put a resistor between Nano and the base.
Value: (Vs - Vbe-sat)/current.
Where Vs is the output level of the Nano, Vbe-sat is the NPN Base-Emitter saturation voltage, and current is the high output current the Nano is capable of.
Say you had Vs = 3.3V, Vbe-sat is 0.7V, and current = 20mA, then R = (3.3V - 0.7V)/.02A = 130 ohm.

runaway_pancake:
This should work better --

see attachment

Screenshot 2020-12-22 113456.jpg

But is still very wrong.

See this circuit from Sparkfun:

(And use 150 ohm base resistor if your Arduino can drive 30mA or more)

This is the standard switching configuration which should allow the transistor to run
relatively cool, as it will only drop a small fraction of a volt. Even so don't expect to be
able to drive much more than 0.6A motor this way - more than that and a MOSFET is
pretty much required.

"But is still very wrong."
Well, you don't like it, but that's you man.
Emitter-follower or run a "3V" on 5V.
People around here sometimes. . .

runaway_pancake:
"But is still very wrong."
Well, you don't like it, but that's you man.
Emitter-follower or run a "3V" on 5V.
People around here sometimes. . .

RP ...... I thought that was great that you drew a diagram and put in time to help. That was really great. I think instead of 'but is still very wrong' ..... Mark could have just quickly pointed out what that actually meant.

In your diagram, the motor was kept on the 'low side' of the circuit, which will get in the way of allowing the transistor to work properly. So just shifting the motor up to the high-side will sort that out ..... allowing this transistor to be on the low-side. But I also know what you were meaning to draw actually. So thumbs up on that.

Well, thanks, but it's neither wrong nor bad.
The transistor will work properly. It's emitter follower, sometimes called a pass transistor; high Z_in, low Z_out.

Please see the following link --

'Page Down' and find Simple Variable Power Supply and Simple Motor Speed Controller. With regard to the latter, my configuration here has the varying PWM feeding the base instead of a varying voltage.

@ runaway_pancake

Will you fix the offered url.

runaway_pancake:
Well, thanks, but it's neither wrong nor bad.
The transistor will work properly. It's emitter follower, sometimes called a pass transistor; high Z_in, low Z_out.

RP ----- in the diagram you first showed a few posts above, the emitter voltage will be the same voltage across the motor. So if the voltage of the motor builds up, then that will impact the behaviour of the transistor (or what we want the transistor to do). That is, V_be is going to be dependent on the motor voltage. Power will go into the motor for a short time, and then the transistor will probably turn off for a bit ..... then on again .... then off again ... repeatedly.

The circuit diagram below just shows the configuration you have right now. Just including it only - just for showing.

circuit_issue.jpg

circuit_issue.jpg