In previous tutorials of this series, we saw how to vary the intensity (brightness) of LEDs using the PWM output of ATtiny85.
This tutorial shall take it to the next step by varying LED brightness using a potentiometer (pot). The pot will give an analog output of 0 to 5V. ATtiny85 has an inbuilt ADC with 4 input channels and 10-bit resolution. ATtiny85 will take analog input from the pot and generate PWM output to vary LED intensity. Let’s see how it is done.
If you are not following this tutorial series from the beginning, you are requested to go through the following two tutorials that explain and demonstrate how to work with ATtiny85 and step by step guide to build a hello world (LED blinking) application.
The circuit is built using only 3-4 components. One LED is connected to a PB0 pin (pin 5) and a PWM output pin. One 330 resistor is used to limit the current. The middle and slider terminal of the pot is connected to pin 3 that is analog input pin A2. The other two terminals of the pot are connected with 5V and Gnd, as shown. A 5 V supply is connected to a Vcc pin (8)
When the pot is varied, it gives analog voltage output from 0 to 5V. This is given as 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 the PB0 pin to vary the intensity of the LED.
The program is written in Arduino IDE software using C programming language. It is compiled, and a HEX file is created that is downloaded into the internal FLASH of ATtiny85
Program logic is very simple. First, ATtiny85 will read analog voltage on analog input pin A2. It will get a 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 4 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 vary DC motor speed using a potentiometer.
You may also like:
Filed Under: Tutorials