potentiometer controlled led using Arduino Uno

A potentiometer-controlled LED project is a great way to learn about analog inputs and PWM (Pulse Width Modulation) with Arduino. Here's a guide:

Components Needed
- Arduino Board (e.g., Arduino Uno)
- LED
- Potentiometer (10k-ohm or suitable)
- Resistor (220-ohm or suitable for your LED)
- Breadboard and jumper wires

Circuit Setup
1. Connect the LED to a PWM-capable digital pin on the Arduino (e.g., pin 9).
2. Connect the potentiometer to analog input pins on the Arduino:
    - VCC to 5V pin
    - GND to GND pin
    - Signal pin to an analog input pin (e.g., A0)

Code
const int potPin = A0;
const int ledPin = 9;

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

void loop() {
  int potValue = analogRead(potPin);
  int brightness = map(potValue, 0, 1023, 0, 255);
  analogWrite(ledPin, brightness);
  delay(50);
}
How it Works
1. The potentiometer's analog value is read by the Arduino.
2. The `map()` function converts the analog value (0-1023) to a PWM value (0-255).
3. The `analogWrite()` function sets the LED's brightness based on the PWM value.

Tips
- You can adjust the `map()` function to change the LED's brightness range.
- You can also use this project to control other devices, like motors or servos.

Do you have any questions about this project or would you like to explore more advanced analog-controlled projects?

Popular posts from this blog

Blink led light using Arduino r3

Temperature sensor using Arduino Uno

Traffic light using Arduino Uno