Controlling LED Brightness With Potentiometer With Arduino
by Rachna Aggarwal in Circuits > Arduino
563 Views, 1 Favorites, 0 Comments
Controlling LED Brightness With Potentiometer With Arduino
In this project ,we will control brightness of LED using variable resistance provided by potentiometer. This is a very basic project for a beginner but it will teach you many things about potentiometer and LED working which are required to make advance projects.
We can also control LED brigthness without potentiometer . click the link below to check that project
Components Required
- Arduino - https://amzn.to/32jAMUA
- Potentiometer - https://amzn.to/3iYsLdC
- LED - https://amzn.to/3iUmIad
- Resistor (220 to 1000 ohms) - https://amzn.to/2ZuPNRN
- Jumper wires - https://amzn.to/3iqdBxM
Circuit Schematic
Pin 11 --> led anode
A0 --> wiper
Vcc --> 5V
Gnd --> terminal 3 of potentiometer, cathode of LED
Arduino Code
Arduino analogRead function is used to measure the voltage between 0 to 5 volts and converts it into a digital value between 0 to 1023. The reason for value 1023 is because the analog to digital converters is 10-bit long. As analogWrite of PWM have duty cycle between 0 to 255 thats why we will divide value read by 4 in the code.
CODE
const int POTENTIOMETER_PIN = 0;
int analog_value=0;
void setup() {
// put your setup code here, to run once:
pinMode(11, OUTPUT);
pinMode(POTENTIOMETER_PIN,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
analog_value=analogRead(POTENTIOMETER_PIN);
//value of analog_value is from 0 to 1023 and duty cycle of PWM is 0 to 255.
analogWrite(11,analog_value/4);
}