Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Motor speedcontrolling with transistor (PWMorTransistor-pot)

Wed Nov 27, 2013 9:58 am

Hi!
I want to connect DC motor to raspberry PI Gpio. I have used Arduino, done some robots, but never did this on Raspberry Pi.

I want to control speed of DC motor and i was wondering whats the best way to do it. I want it for my raspberry fan.

For example: if CPU temp < 35C then Motor uses half of 5V, 2-3V (Between emiter and collector).
And if CPU temp > 35C then Motor runs of full speed using 5V.

The point is, i want to control Voltage on Transistor Base and use transistor as pot.

Using 2 GPIO outputs with Different Resistors on Base.
Example: Resistor X have more resistance than Y.
If CPU temp < 35C then GPIO 23 activated 3.3V goes on transistor base through resistor X and opening Transistors Emiter-Collector only by half - so i get 2-3V on motor.
If CPU temp < 35C then GPIO 24 activated 3.3V goes on transistor base through resistor Y and opening Transistors Emiter-Collector completely and i get 5V on motor.

Image


Second way is to control motor speed by PWM, using one PWM PIN. So i can change voltage current on BASE by changing hz frequency.

Image

ALSO:
What kind of NPN transistor can i use? I have some c945 npn transistor and some mosfet transistors.

sorry for my english :)

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Wed Nov 27, 2013 3:30 pm

I'd suggest the second version - just one transistor or driver, and driving it by PWM.

My reason is the first version is, I think, driving the transistor half on - not fully saturated - and this can be inefficient, making the transistor heat up. It may be enough to damage it. (Maybe.)

As for a transistor I'd suggest some sort of Darlington transistor type. Maybe search for a motor driver circuit using a single darlington. (You might need a diode, called a flyback diode, to prevent the fan's motor from damaging the transistor too.)

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Wed Nov 27, 2013 6:00 pm

The first version is not likely to work as you hope.

The reason is that transistors are current-operated devices - while it's not saturated (fully on), collector current = base current times the gain of the transistor.
But the gain can vary from transistor to transistor, even of the same type, and can change over time.
So the resistor feeding the base would have to be selected for a specific transistor to give the right current.

But there's one more problem - a typical motor is controlled by the voltage across it - the more voltage, the faster it goes. The current it takes depends on the mechanical load.
So controlling the current won't control the speed, only the torque.

Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 9:02 am

Burngate wrote:The first version is not likely to work as you hope.

The reason is that transistors are current-operated devices - while it's not saturated (fully on), collector current = base current times the gain of the transistor.
But the gain can vary from transistor to transistor, even of the same type, and can change over time.
So the resistor feeding the base would have to be selected for a specific transistor to give the right current.

But there's one more problem - a typical motor is controlled by the voltage across it - the more voltage, the faster it goes. The current it takes depends on the mechanical load.
So controlling the current won't control the speed, only the torque.
Sorry, but yes i was thinking about VOLTAGE, not current. 5V full speed, 3V medium speed. I want to control voltage.

Here is video, maybe this will explain http://www.youtube.com/watch?v=eQt92EIoCus

Also, im not sure, what kind of transistor models i should use, MOSFET should work this way?

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 12:34 pm

I've spent a little time (actually quite a lot - I don't like being defeated) trying to work out what you've got connected where, but it's not clear what transistor you're using, or how you've connected it.
Perhaps you could draw a schematic, and post it here?

If I'm half-way correct, watching your video, it seems you may be using the potentiometer to put a variable voltage onto the base of an NPN transistor. The clue is that not much of a turn takes your LEDs from off to on.
As I said above, NPN transistors are current-operated devices. That means, as soon as the voltage goes above the Vbe of the transistor, current will flow into the base, and a large current will flow into the collector.

A FET operates more like what you want - its source-drain resistance depends on the gate-source voltage. It won't be very linear, and not very controllable, but it may work.

However, what you really want is a controllable voltage. To do that, you'll require a rather more complex circuit, maybe an op-amp.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 1:26 pm

Senka7 wrote:Second way is to control motor speed by PWM, using one PWM PIN. So i can change voltage current on BASE by changing hz frequency.
I think the above is what you really want to do. Just use a transistor (darlington?) on/off circuit and PWM it. (You vary the voltage by making the on time longer though.)

As you've already said, it's for a fan so doesn't need to reverse the motor - just change the speed by changing the average voltage.

I once saw a place where they ran a motor by computing the voltage, outputting it with DAC, and running it into an audio amplifier (slightly modified for DC.) That is possible, but overkill for a fan. :twisted:

You could use a ULN2803 or similar, that way you'd have spare outputs for several other things.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 4:29 pm

This 2 speed fan controll might be what you want
Using just the one GPIO output
Select the transistor to suit motor full load current
Select resistor to give voltage drop for
Fan speed

1. GPIO at active high output .Transistor ON Full speed

2. GPIO at active Low output Transistor OFF half speed ?
Attachments
img023.jpg
img023.jpg (19.19 KiB) Viewed 11496 times
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 6:52 pm

boyoh wrote:This 2 speed fan controll might be what you want
Using just the one GPIO output
Select the transistor to suit motor full load current
Select resistor to give voltage drop for
Fan speed

1. GPIO at active high output .Transistor ON Full speed

2. GPIO at active Low output Transistor OFF half speed ?
Wow! This is another great idea! This will work perfectly also.

Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 7:05 pm

Burngate wrote:I've spent a little time (actually quite a lot - I don't like being defeated) trying to work out what you've got connected where, but it's not clear what transistor you're using, or how you've connected it.
Perhaps you could draw a schematic, and post it here?

If I'm half-way correct, watching your video, it seems you may be using the potentiometer to put a variable voltage onto the base of an NPN transistor. The clue is that not much of a turn takes your LEDs from off to on.
As I said above, NPN transistors are current-operated devices. That means, as soon as the voltage goes above the Vbe of the transistor, current will flow into the base, and a large current will flow into the collector.

A FET operates more like what you want - its source-drain resistance depends on the gate-source voltage. It won't be very linear, and not very controllable, but it may work.

However, what you really want is a controllable voltage. To do that, you'll require a rather more complex circuit, maybe an op-amp.

This is schematic
Image

I have done that kind of process in Arduino, i could change speed by changing frequncy i think. I probably used MOSFET transistor.

Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Thu Nov 28, 2013 7:09 pm

Ravenous wrote:
Senka7 wrote:Second way is to control motor speed by PWM, using one PWM PIN. So i can change voltage current on BASE by changing hz frequency.
I think the above is what you really want to do. Just use a transistor (darlington?) on/off circuit and PWM it. (You vary the voltage by making the on time longer though.)

As you've already said, it's for a fan so doesn't need to reverse the motor - just change the speed by changing the average voltage.

I once saw a place where they ran a motor by computing the voltage, outputting it with DAC, and running it into an audio amplifier (slightly modified for DC.) That is possible, but overkill for a fan. :twisted:

You could use a ULN2803 or similar, that way you'd have spare outputs for several other things.
PWM is best solution i think. I'm not sure about resistors, should i use some resistors on motor? And how can i find resistors for Transistor and Motor? Motor is 5V 0.12A.

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Fri Nov 29, 2013 9:36 am

Try page 12 of the following:

http://www.picaxe.com/docs/picaxe_manual3.pdf

... or page 16 for a ULN-something chip, which contains an array of darlington transistors.

In fact that manual has lots of handy circuits like that. The only thing is it's made for PIC controllers which have 5V logic outputs, the raspi has around 3.3V outputs. But I think most of it will work without changes.

ps - you need the diode in the diagrams on p12 (unless the transistor you use has a one specially built in.) Every time a motor switches off suddenly, it gives out a voltage surge - the diode is there to stop the surges from eventually damaging the transistor.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Fri Nov 29, 2013 12:21 pm

The more electronic circuits you use
To monitor the temperature of the Pi
To control the cooling fan, Could
Be self defeating, the total current
To do this will only make Pi get hotter
Keep the circuit very simple , and keep
The component count down

BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Senka7
Posts: 39
Joined: Sun Oct 27, 2013 4:32 pm

Re: Motor speedcontrolling with transistor (PWMorTransistor-

Sat Nov 30, 2013 1:09 pm

Ravenous wrote:Try page 12 of the following:

http://www.picaxe.com/docs/picaxe_manual3.pdf

... or page 16 for a ULN-something chip, which contains an array of darlington transistors.

In fact that manual has lots of handy circuits like that. The only thing is it's made for PIC controllers which have 5V logic outputs, the raspi has around 3.3V outputs. But I think most of it will work without changes.

ps - you need the diode in the diagrams on p12 (unless the transistor you use has a one specially built in.) Every time a motor switches off suddenly, it gives out a voltage surge - the diode is there to stop the surges from eventually damaging the transistor.
Need to test Mosfet transistor with pot :)

Return to “Automation, sensing and robotics”