Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
A potentiometer, often referred to as a „pot,” is a variable resistor that allows you to manually adjust the resistance along its track.
This component is widely used in electronics for controlling things like volume, brightness, and speed. Arduino, on the other hand, is an open-source platform used for building digital devices and interactive objects. It consists of both hardware and software components, making it ideal for various projects, including LED control.
Before diving into the project, let’s gather the necessary components:
Now, let’s proceed with wiring the circuit. Follow these steps:
With the circuit set up, it’s time to write the code. Open the Arduino IDE and create a new sketch. Copy and paste the following code:
cpp
const int ledPin = 9; // LED connected to digital pin 9
const int potPin = A0; // potentiometer connected to analog pin A0
int brightness = 0; // variable to store the brightness value
void setup() {
pinMode(ledPin, OUTPUT); // set the LED pin as an output
}
void loop() {
brightness = analogRead(potPin); // read the potentiometer value (0-1023)
brightness = map(brightness, 0, 1023, 0, 255); // map the potentiometer value to a brightness range (0-255)
analogWrite(ledPin, brightness); // set the LED brightness
delay(10); // add a small delay to prevent flickering
}
Upload the code to your Arduino board and power it up. You should see the LED light up, with its brightness controlled by rotating the potentiometer. Rotate the potentiometer knob to adjust the brightness level accordingly.
Congratulations! You’ve successfully learned how to control LED brightness using a potentiometer with Arduino. This project is just one example of the endless possibilities offered by Arduino in the world of electronics and DIY projects.
Experiment with different components and code variations to expand your knowledge and create even more exciting projects!