Controlling LED Brightness With Potentiometer With Arduino

Introduction: Controlling LED Brightness With Potentiometer With Arduino

About: pursuing Bachelors in Electronics and Communication at Chandigarh University

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

link: - Led brightness control without potentiometer .

Step 1: Components Required

Step 2: Circuit Schematic

Pin 11 --> led anode

A0 --> wiper

Vcc --> 5V

Gnd --> terminal 3 of potentiometer, cathode of LED

Step 3: 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);

}

Be the First to Share

    Recommendations

    • Soup & Stew Speed Challenge

      Soup & Stew Speed Challenge
    • Lamps and Lighting Contest

      Lamps and Lighting Contest
    • First Time Author Contest

      First Time Author Contest

    Comments