What happens is that the motor starts making a continuous high-pitched beep noise. Not very different from a PC speaker beep.
It just makes that noise and it doesn't turn at all.
If I change the PWM value to around 250 it start to turn normally and makes no noise.
Does anyone know what the problem may be and how to solve it so that I can use lower PWM values ? My goal is to make the motor turn as slow as possible.
You might need to hook up a capacitor to the lead going to the base of the transistor (arduino pin 5 to ground). What you are hearing is the PWM signal in the motor. PWM Is not quite analog, but does have some of the properties (most of the time...)
You might have a problem - the motor might be designed to run in a certain speed range and won't perform well outside this range. If you want slow rotation you would be better off with a gear motor or a stepper motor.
Try starting the motor at PWM of 255 and slowly reducing that number. You need enough torque to get the motor started and then it will require less torque once it is moving.
You have the diode connected in the wrong place, you'll blow the transistor if you leave it like that. Connect it in parallel with the motor, anode to TIP120 collector, cathode to +9v. This will also make the circuit more efficient and more likely to work as intended.
I recommend adding a large capacitor (e.g. 1000uF) between motor +ve terminal and TIP120 emitter.
A TIP120 like any Darlington has a relatively high voltage drop, it could be as high as 3 volts depending on motor current. You can measure the voltage drop across the TIP120 when you digitalWrite HIGH to the pin. Darlingtons are obsolete, mosfets are much better for switching large currents.
If the 9v supply is a 9v rectangular battery, then unless it's the expensive lithium variety, it's unlikely to be able to supply enough current to drive the motor well.
If you get the motor working with PWM but it still makes a noise, increasing the PWM frequency will help make it quieter.
You have the diode connected in the wrong place, you'll blow the transistor if you leave it like that. Connect it in parallel with the motor, anode to TIP120 collector, cathode to +9v. This will also make the circuit more efficient and more likely to work as intended.
Just doing this helped a lot . I can now run down to PWM values of 160 which is pretty good for what I need to do.
If this is the best way to wire up a TIP120 and a motor, I'm surprised at the number of wrong tutorials that can be found by googling. Lots of them suggest wiring the diode the way I originally did.
dc42:
2. I recommend adding a large capacitor (e.g. 1000uF) between motor +ve terminal and TIP120 emitter.
I suppose a ceramic capacitor will be ok, or is an electrolytical cap ok too ?
For the sake of learning, what's the purpose of this capacitor ? Is it for smoothing out the current going to the motor ?
dc42:
3. A TIP120 like any Darlington has a relatively high voltage drop, it could be as high as 3 volts depending on motor current. You can measure the voltage drop across the TIP120 when you digitalWrite HIGH to the pin. Darlingtons are obsolete, mosfets are much better for switching large currents.
If the 9v supply is a 9v rectangular battery, then unless it's the expensive lithium variety, it's unlikely to be able to supply enough current to drive the motor well.
The supply is a laptop PSU, it's rated 3.5A @ 9.5V, so I think it should be fine, even considering the voltage drop of the darlington.
I've read that mosfets are more sensitive to static and in general less rugged than transistors, and I'll need to use this circuit in an environment that is not extremely friendly. I may of course be misinformed.
Do you have any suggestion for a good mosfet that can replace the TIP120 for driving relatively small motors (from printers or RC toy cars) ?
dc42:
5. If you get the motor working with PWM but it still makes a noise, increasing the PWM frequency will help make it quieter.
dc42:
2. I recommend adding a large capacitor (e.g. 1000uF) between motor +ve terminal and TIP120 emitter.
I suppose a ceramic capacitor will be ok, or is an electrolytical cap ok too ?
For the sake of learning, what's the purpose of this capacitor ? Is it for smoothing out the current going to the motor ?
You'll have a hard time finding a 1000uF ceramic capacitor, and if you do, it will be huge! It's to smooth out the current pulses drawn by the transistor/motor combination so that the power supply has a more even load. This is especially important when running from a battery.
nerochiaro:
I've read that mosfets are more sensitive to static and in general less rugged than transistors, and I'll need to use this circuit in an environment that is not extremely friendly. I may of course be misinformed.
Do you have any suggestion for a good mosfet that can replace the TIP120 for driving relatively small motors (from printers or RC toy cars) ?
When you're handling and soldering them, they can be damaged by static charge between the gate terminal and the other terminals. Once they are in a circuit, whatever is driving the mosfet gate (e.g. Arduino) will protect the gate, and they are then more rugged than transistors, e.g. they can take higher current pulses and they are not damaged by avalanche breakdown due to overvoltage provided the total avalanche energy is limited. They also have a built-in reverse diode between source and drain (in an equivalent position to where you originally connected the diode in tour circuit) so they are protected against negative-going transients too.
There are hundreds of mosfets to choose from, but if you want to drive it directly from the Arduino it needs to have "logic level gate drive". To replace an NPN transistor like the TIP120 you need an N-channel mosfet. For switching currents up to 3A or so, IRLZ24PBF is the cheapest I have found (voltage rating is 60V). For higher current you need a lower on-resistance to avoid the need for a heatsink, and IRLB8742PBF would be a good choice for switching relatively low voltages (voltage rating is 30V).
nerochiaro:
Noise is rather ok now. But if I want to increase the PWM frequency, do you think using this code will be ok ? Arduino Playground - HomePage
Yes, but be aware that changing the PWM frequency affects anything else using the timer associated with that PWM pin. In particular, Timer 0 is used for system timekeeping, e.g. millis() and micros() functions. So choose which PWM pin to use with care.
dc42 - You mentioned "logic level gate drive" as a requisite for a transistor driven directly by the Arduino. Is the reason for this that the output of the Arduino is very low amperage? Also, logic level, to me, means on or off - is this thinking correct? What other type(s) of gate drive might there be? Just trying to get my head around some of the terms. Thanks.
"Gate drive" refers to the voltage you apply between the gate and source terminals of a mosfet to turn it on, and "Logic level gate drive" means this is around 5v instead of higher. In other words, the Arduino has outputs that change by 5v, so if you want to drive a mosfet from such an output without having to amplify it first, you need a mosfet that will switch fully on with just 5v between its gate and source.
Mosfets that are not "logic level" are typically specified for 10v gate drive.