One can find the arduino analog fade and arduino serial in/out example in the arduino ide. The examples are more or less same to what i am going to discuss in this tutorial. I will go deeper and try to highlight every piece of information widely and as easily as i could.Potentiometer is used in the circuits where we need a variable resistance to control current and voltage. Have you noticed that, the speaker that you have in your home, you move its knob in clockwise and anti clock wise direction to set the volume. Actually behind the knob their is a potentiometer, that is you are varying the resistance to set the volume. Like wise in many other home appliances potentiomenter is used for the same purpose(old TV’s , old radios etc).
What happens at the potentiometer side?
Now recall Ohms law that when ever resistance in a circuit increases the current decreases. Also current is directly proportional to voltage. So with the increase in voltage current increases and with decrease in voltage current decreases.
If we consider the above statement it is clear that we can directly connect the led with potentiometer and fade/dim/control its brightness by rotating the knob of the potentiometer. Then why we are trying to fade led with potentiometer using arduino? What are the pros and cons of fading led with potentiometer and arduino?
Why potentiometer with Arduino?
Led brightness control with potentiometer and Arduino
How the system works?
Note: Applying greater voltage to arduino analog pins will damage your arduino board. So in our case the potentiometer voltage output must not increase 5 volts.
Voltage Variation Fades Led
When you rotate the knob of the potentiometer resistance decreases and the current starts flowing. As the current increases the voltage increases and their is a change in voltage which is detected by the analog input A0 pin of the Arduino. We analyze this change in voltage in our sketch(code) and then output the change to Pin#9 to which our led is connected. Led fades when we constantly rotate the potentiometer knob in clockwise and anticlockwise direction.
Its necessary to divide the analog reading by 4 because analogWrite() function outputs analog values in between range from 0 to 255. Where 0 represents low and 255 represent high, and analogRead() inputs value from 0 to 1023. At last the analogWrite() function outputs the analog value. You will now see led fading/brightness varied if you rotate the knob of potentiometer.
Watch the Project Video Here