Friday, May 06, 2016

Arduino for Beginners: Controlling fan or motor speed with PWM

Arduino for Beginners: Controlling fan or motor speed with PWM by Stanley Seow: 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.



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.