Example-3

Controlling LED Brightness with a Potentiometer

Objective

To control the brightness of an LED using a potentiometer with Arduino Uno by converting analog input values into Pulse Width Modulation (PWM) signals.

Learning Outcomes

  • Understand how to connect and use a potentiometer as an analog input.

  • Learn about analogRead() and analogWrite() functions in Arduino.

  • Observe how PWM controls the brightness of an LED.

  • Build confidence in reading values from sensors and mapping them to actuators.

Components (From Tinkercad Palette)

  • Arduino Uno board

  • Breadboard (small)

  • 1 × LED

  • 1 × 220Ω resistor

  • 1 × Potentiometer (10kΩ)

  • Jumper wires (male-to-male)

Circuit Wiring (Exact)

  • LED Connection:

    • LED anode (long leg) → one end of 220Ω resistor → Arduino digital pin 9

    • LED cathode (short leg) → GND

  • Potentiometer Connection:

    • Middle pin → A0

    • Left pin → 5V

    • Right pin → GND



Step-by-Step in Tinkercad

  1. Open Tinkercad Circuits.

  2. Drag Arduino Uno, breadboard, LED, resistor, and potentiometer onto the workspace.

  3. Connect the LED to pin 9 (through resistor) and GND.

  4. Connect potentiometer: left pin → 5V, right pin → GND, middle pin → A0.

  5. Open the Code editor → Select Text mode (C++).

  6. Paste the following Arduino program.

int potPin = A0;    // Potentiometer connected to A0
int ledPin = 9;     // LED connected to PWM pin 9
int potValue = 0;   // Store potentiometer value
int ledValue = 0;   // Store LED brightness

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  potValue = analogRead(potPin);            // Read 0–1023
  ledValue = map(potValue, 0, 1023, 0, 255); // Scale to 0–255
  analogWrite(ledPin, ledValue);            // Output PWM
}
  1. Click Start Simulation.

  2. Rotate the potentiometer and observe the LED brightness change.

How It Works (Explain to Students)

  • The potentiometer acts like a variable resistor that gives values between 0 and 1023.

  • Arduino reads this analog value using analogRead().

  • The map() function scales it to a PWM range (0–255).

  • The analogWrite() function sends PWM signals to the LED, making it glow dim or bright.

  • Turning the knob clockwise increases brightness; turning it anticlockwise decreases it.

Common Mistakes & Quick Fixes

  • 🔴 LED not glowing → Check polarity (long leg should connect via resistor to pin 9).

  • Potentiometer not working → Ensure middle pin is connected to A0.

  • LED always at same brightness → Verify code uses analogWrite(), not digitalWrite().

  • Error uploading code → Make sure the board selected in Tinkercad is Arduino Uno.

Viva / Check-Your-Understanding

  1. What is the function of the potentiometer in this circuit?

  2. Why do we use the map() function here?

  3. What is PWM and why is it needed to control LED brightness?

  4. Which Arduino pins support PWM output?

  5. What is the difference between analogRead() and analogWrite()?

Extensions (Mini-Tasks)

  • Replace LED with a small DC motor → observe speed control.

  • Connect two LEDs to different PWM pins and control them with one potentiometer.

  • Try using Serial.print(potValue) to display potentiometer readings in Serial Monitor.

Lab Record (Suggested Headings)

  • Aim

  • Circuit diagram (screenshot from Tinkercad)

  • Code listing

  • Output observation (simulation screenshot)

  • Inference/Conclusion

Thinkercad Link

https://www.tinkercad.com/things/0vzKT8Q5vyr-example-3

Comments

Popular posts from this blog