Oscar Gonzalez gives us a simple tutorial for speed controlling a PC FAN and reading a LM35 temperature sensor with an Arduino microcontroller. He covers the use of an optocoupler, PWM (Pulse Width Modulation) and reading analog voltages with the Arduino. He even has a video showing the fan speed control in action.
This article was submitted by Oscar Gonzalez as part of the “Hobby parts for articles” program. Oscar receives a Arduino compatible Modern Device Company Bare Bones Kit for this great article.
Control a device that requires 12V from the Arduino without frying it. The Arduino is a 5V device and can not directly drive a 12V device such as a PC fan. There are many possible solutions but my approach is using the CNY75 optocoupler to separate the two voltages.
This devices is very simple. It consist of an phototransistor and a LED inside the same package. The phototransistor turns on or conducts current when the internal LED lights. The brighter the internal LED the more current can pass through the phototransistor. The LED and phototransistor are physically isolated from each other. This physical isolation protects the input side (the LED) from voltage spikes on the output side (phototransistor) and can provide the voltage translation needed for this project. When the LED is activated from the 5V Arduino the phototransistor will turn on and pass current for the 12VDC fan. The isolation provided by the optocoupler keeps the Arduino is safe from destruction.
The optocoupler’s internal transistor does not have sufficient current capacities to drive a DC motor (like our FAN) directly. To boost the current I used a BD137 transistor which can drive up to 1.5 Amperes. This power transistor is sufficient for controlling PC Fan motors. The PC Fan model I used runs needs about 300 mA.
Controlling the speed with PWM
To control the fan speed you could reduce the drive voltage to the motor. This would be harder to do and could reduce the motor torque. PWM (Pulse Width Modulation) is easier with the Arduino and is basically like turning the motor on and off very quickly. We are turning on and off the LED inside the optocoupler which is turning on and off the transistor in the optocoupler which is in turn controlling the power transistor which is turning on and off the Fan motor. The longer the motor is on, the fast it will spin. The cycle time (off to on) is very short, so short that you will not hear it occurring. Actually it occurs so fast that the fan averages the on and off times to run at a nearly constant speed.
Testing the speed control
I tested the speed control with the “LED Fade” Arduino example sketch. Connect the internal CNY75 LED trough a 1K resistor. The motor should go from quiet (slow) to full cooling (fast) progressively. You can modify the example program to change the slow to fast cycle.
[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]Arduino[/box]
For more detail: Arduino temperature controlled PC Fan
This Post / Project can also be found using search terms:
- arduino temperature controlled fan