In the previous two tutorials of this series, we have seen how to vary the intensity (brightness) of LEDs using the PWM output of ATtiny85. In this tutorial, we shall use a PWM output to vary the speed of a DC motor.
DC Motor speed varies as the potentiometer is varied. As we have learned in the previous tutorial, the potentiometer gives an analog output of 0 to 5 V. ATtiny85 takes this analog input and generates a PWM output to vary the speed of the DC motor. Let’s see how it is done.
If you are not following this tutorial series from the beginning, then you should go through the following two tutorials that explain and demonstrate how to work with ATtiny85 and a step-by-step guide on how to build a hello world (LED blinking) application.
How to work with ATtiny85
LED blinking using ATtiny85
The circuit is built using only 3-4 components. The potentiometer (pot) has three pins and the middle (slider) terminal is connected to pin 2, analog input pin A1. The other two terminals of the pot are connected with 5V and Gnd, as shown. PWM output pin PB0 drives DC motor using Darlington transistor TIP122. It is connected to the base input of TIP122 through a current limiting resistor of 220 Ω. The collector output of TIP122 drives the DC motor, and the emitter is connected to ground. The motor is given a 12 V supply, and ATtiny85 is given a 5 V supply, as shown.
When the pot is varied, it gives analog voltage output from 0 to 5V. This is shown as an analog input to ATtiny85. The inbuilt ADC of ATtiny85 will convert this into digital, giving a digital value between 0 to 1023 (because of 10-bit resolution). Based on this value, it will generate PWM output on PB0 pin to vary the speed of the DC motor
The program is written in Arduino IDE software using a C programming language. It is compiled, and an HEX file is created that is downloaded into the internal FLASH of ATtiny85
Program logic is straightforward. First, ATtiny85 will read analog voltage on analog input pin A1, and it will get the value between 0 to 1023. This value will generate PWM output on pin 5 (PB0) by dividing this value by 4. The value is divided by four because the PWM value is between 0 to 255 while the input range is 0 to 1023.
In the next tutorial, we shall learn to generate different color using RGB LED.
You may also like:
Filed Under: Arduino, Electronic Projects