On the first part, I talk about switching any 12V DC or higher electronic components ON or OFF. This can be easily done using an optoisolator and a 12V reed relay. In this article, I will be using a different component to control the speed of the 12V fan or motors using Pulse Width Modulation (PWM).
The TIP-122 are Darlington transistors that can support voltage up to 100V. It consist of two transistors with resistors and diode all inside a TO-220 package. You can use TIP-120 that support up to 60V. Please refer to the TIP-120/TIP-122 datasheets for details specifications here.
I've wired u my circuit like the schematic diagram below :-
The input of the circuit is using analogRead(0) to read the light level from the light dependent resistors (LDR). Depending on the light level, the value is converted by the ADC to 0 to 1023. Since the PWM can only take value of 0-254, I will divide the ADC value by 4 to match the PWM value.
The 12V DC supply is separate from the Arduino 5V supply but shared a common ground.
The LCD is to display the LDR value for debugging purpose. Cover the LDR or shine a light to it to see the fan speed change.
Arduino Pin 9 (PWM) connect to the TIP-122 Base (B) pin.
The 12V fan connect to the TIP-122 Collector (C) pin and the Emitter (E) pin connect to the Ground.
Sketch to control the 12V fan speed using PWM is as below :-
int ldr = 0;
ldr = analogRead(0)/4;
// if light level is room light, turn the fan speed higher
if ( ldr < 125 && ldr > 40 ) {
ldr = ldr + 50;
}
// if value is less than 40, do not switch the fan ON
if ( ldr < 40 ) {
ldr = 0;
}
// else run the fan speed according to light level up to 255
// send PWM value to TIP-122 base pin
analogWrite(9,ldr);
delay(500);
The TIP-122 are Darlington transistors that can support voltage up to 100V. It consist of two transistors with resistors and diode all inside a TO-220 package. You can use TIP-120 that support up to 60V. Please refer to the TIP-120/TIP-122 datasheets for details specifications here.
TIP-122 |
TIP-122 fan speed control |
The 12V DC supply is separate from the Arduino 5V supply but shared a common ground.
The LCD is to display the LDR value for debugging purpose. Cover the LDR or shine a light to it to see the fan speed change.
Arduino Pin 9 (PWM) connect to the TIP-122 Base (B) pin.
The 12V fan connect to the TIP-122 Collector (C) pin and the Emitter (E) pin connect to the Ground.
Sketch to control the 12V fan speed using PWM is as below :-
int ldr = 0;
ldr = analogRead(0)/4;
// if light level is room light, turn the fan speed higher
if ( ldr < 125 && ldr > 40 ) {
ldr = ldr + 50;
}
// if value is less than 40, do not switch the fan ON
if ( ldr < 40 ) {
ldr = 0;
}
// else run the fan speed according to light level up to 255
// send PWM value to TIP-122 base pin
analogWrite(9,ldr);
delay(500);
Hello. May I know if this circuit can drive more than one fan? If not, what else should I add to make that work?
ReplyDeletethx.
If you need to drive more than 1 fan at the same PWM speed, just hook it up in parallel ( make you the power supply can supply enough power to both the fans )..
ReplyDeleteIf you need to drive them at different speed, then just use another PWM pins and another TIP120/TIP122 ...
probably a stupid unrelated question. i am a beginner to arduino electronics and was wandering if you would have a diagram of the atmega 328 chip and what pins go to what part of the arduino (Ex- pin 16 goes to analog 2) or anything like that. i have written code to a chip for a LED chaser and would like to wire it to a circuit board but cannot do it because i dont know what pins to wire to what led's or power and ground to what pins etc. My e-mail address is doley08@gmail.com any information would be grateful. Thank you for your time
ReplyDeleteHi,
ReplyDeleteCan I use the circuit to control a motor that takes current above 40mA?
What resitor is used between de tip122 and the pwm signal
ReplyDeletethank you for this great tutorial. i am in the planning of something so i would like to make something clear to me.
ReplyDeletei would like to drive 3 of these (http://www.nodna.de/Robots-and-Accessories/Servos-Motors-Encoder/Motor-Encoder/EMG30-12V-GearMotor-with-Encoder--1076.html) motors independently.
so i would need an arduino (of course), three of the TIP-122 and a 12v power supply? is this correct?
it would be nice if you would help me here. thanx and have a nice day!
@mipu, Yes, you can drive them independently using 3 PWM pins
ReplyDelete@jos, the resistor between the TIP-122 is 1K resistor.
ReplyDelete@naasik, Yes, you can drive motors above 40mA as it is independent of the Arduino pins... it is the TIP-122 that is controlling the current across the motors.
ReplyDeletecould I control speed of fan (which is 5V 0.5A) powering it up from arduino uno?
ReplyDelete@Ziai, it is NOT recommended to power the fan even tho it is running on 5V. You can share the same power supply source, e.g. 5V from the USB and use a TIP-120 / TIP-122 to control the fan speed.
ReplyDeleteYou cannot directly power / control the fan speed from those I/O pins as the max amp is only 40mA.
is the sketch correct ?
ReplyDeletebecause arduino finds a pb on this line :
ldr = analogRead(0)/4;
(im noob but i'm trying to control speed of one fan)
Not sure yr questions...
ReplyDeleteanalogRead return values range from 0-1023 (10-bits) whereas PWM only output is from 0-255.
analogWrite(9,ldr);
if you copy the code into arduino, it won´t work. is there something missing?
ReplyDeleteThe code posted is not the complete codes.. you will need the setup() and loop() to complete the code...
ReplyDeleteI think TIP-122 B & C are swapped on the schematic diagram. 1 is B and 2 is C.
ReplyDeletegood.....
ReplyDeleteHi
ReplyDeleteCan I use this setup for 24V motor as well? I am not sure if the increased voltage would make the TIP122 overheat. Maybe if I add some kind of grille to the transistor, to cool it down. Or maybe i need to replace it with a MOSFET?
/Christian
Yes, TIP122 is rated up to 100V... you can touch the metal part to check if it is hot or not..
ReplyDeleteWill this work with controlling lights as well?
ReplyDeleteFor lights from the mains 110/220V, you would need a solid state relay.. it should work the same way...
ReplyDeleteSo if PWM is set to 0 will the fan remain at rest? Or do you also need the relay to turn power on and off?
ReplyDeleteFan will be OFF
ReplyDeleteSo I gave this a try and it does not seem to produce the desired results. All it does is spin at a constant rate. Any ideas would be great!
ReplyDeleteI have the exact setup you gave using a tip122, a 1k resistor, 12v transformer, and a 12v muffin fan.
Here is my arduino code, note that I am just giving it a value rather then getting a value from another source. My plan is to hook this up to a WiiRemote using Max/MSP to give the value in the same way your ldr is giving you your values.
int fanPin = 9; // Fan connected to digital pin 9
void setup()
{
pinMode(fanPin, OUTPUT); // sets the pin as output
}
void loop()
{
analogWrite(fanPin, 100);
delay(500);
}
Yr analogWrite is ALWAYS 100, so the fan spins at the same speed...
ReplyDeletePls join the facebook group and post yr project/questions/photos over there... lots of beginners and experience Arduino ppl over there...
This is a great tutorial... however, I might suggest you correct the diagram like anonymous pointed out. B and C are flipped. http://www.pcsilencioso.com/cpemma/ef.html helped me figure this problem out.
ReplyDeletehi there
ReplyDeletehow am i suppose to connect the motor.
"The 12V fan connect to the TIP-122 Collector (C) pin"
yes i understand that, but how? am i connecting the + of fan to the Collector and to the power supply and then the fan's - to ground?
or fan's - to collector and + to supply?
thanks
Brad, errors on the TIP-122 pins are fixed, thanks for all that pointed that out...
ReplyDeleteHi I need to do AC 230v fan, Can u help me, How to do?
ReplyDeletehttp://www.apcc.tk/diy-projects/arduino-pwm-fan-or-motor-speed-control you can rean more hear about arduino pwm
ReplyDeleteHi, This is a great tutorial, I am just getting into control circuits but have been into smaller current electronics for some time. I read the spec sheet on the TIP122, but I am still curious if this transistor would work for a high current fan like that on the radiator of my truck? or will I need a different part and circuit? I will be using the tip122 for controlling led lights on my truck though so that shouldn't be an issue. all the lights including the headlights are low current draw 12 volt supply. I assume the tip 122 and this schematic will work fine for that?
ReplyDeleteHi, from the datasheet, the max CE current is only 5A... if you need higher current, you might need to use something different.. do a part search on http://octopart.com/ with your required voltage (12V) and max current draw needed...
ReplyDeleteThanks for your reply, I can't seem to find anything online that matches my requirements. the truck supplies around 12.2 to 14.6 volts when running. the fan is rated for 11amps continues draw. I am assuming the worst and would say the start up current is somewhere around 20 amps. I need a transistor or SSR that can provide me with PWM control of the fan when connected to a 5volt PWM signal from a Microcontroller. and all of this needs to be within a small budget. I already have the arduino and other parts. thanks
Deletehello.What specific solid state relay would i need if i am controlling lights from the mains.(220v,110v)and is schematics the same with the solid state relay accept that we will replace the TIP122 with the SSR.Thanks
ReplyDeleteNo, you cannot use PWM on A/C SSR bcos SSR on the mains are Alternating Current (A/C) output... you can only do PWM on D/C..
ReplyDeleteI setup my arduino as above but the fan makes a high pitch noise when not full speed (255). Is there anything I can do to stop this?
ReplyDelete