Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Controlling led with potentiometer using arduino

Introduction to controlling led with potentiometer

In the realm of electronics, the Arduino microcontroller has become a ubiquitous tool for enthusiasts and professionals alike.

One of the fundamental experiments for beginners is controlling an LED’s brightness using a potentiometer. This project serves as an excellent introduction to analog input and output manipulation using Arduino.

Understanding potentiometers

Potentiometers, often referred to as „pots,” are variable resistors with three terminals. They act as voltage dividers, allowing users to adjust the resistance and thus the voltage output. By turning the knob of a potentiometer, the resistance between the center terminal and either of the outer terminals changes, altering the voltage at the center terminal accordingly.

Components required

Before diving into the project, gather the following components:

  • Arduino Board (e.g., Arduino Uno)
  • LED (Light Emitting Diode)
  • Potentiometer (10kΩ recommended)
  • Resistor (220Ω)
  • Breadboard
  • Jumper Wires

Wiring the circuit

Begin by setting up the circuit. Insert the LED and potentiometer into the breadboard. Connect one leg of the LED to digital pin 9 on the Arduino board via a 220Ω resistor. The other leg of the LED should be connected to the ground (GND) pin on the Arduino. Connect one outer terminal of the potentiometer to the 5V pin on the Arduino and the other outer terminal to the ground (GND) pin. Finally, connect the center terminal of the potentiometer to analog pin A0 on the Arduino.

Arduino code

Now, let’s write the Arduino code. Open the Arduino IDE and create a new sketch. The following code snippet will map the analog input from the potentiometer to the brightness of the LED:

arduino
const int potPin = A0; // Potentiometer connected to analog pin A0
const int ledPin = 9; // LED connected to digital pin 9
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int brightness = analogRead(potPin); // Read potentiometer value (0-1023)
brightness = map(brightness, 0, 1023, 0, 255); // Map value to LED brightness (0-255)
analogWrite(ledPin, brightness); // Set LED brightness
}

Testing the project

Upload the code to your Arduino board and open the Serial Monitor to observe the values being read from the potentiometer. As you turn the knob of the potentiometer, you’ll notice the LED’s brightness changing accordingly. This demonstrates the real-time control of an output (LED) using an input (potentiometer) with Arduino.

Controlling an LED with a potentiometer using Arduino is a simple yet enlightening project for electronics enthusiasts. It teaches the basics of analog input and output manipulation and serves as a foundation for more complex projects. Experiment with different components and code modifications to further expand your understanding of Arduino programming.

With this project, you’ve unlocked the door to a world of possibilities in the realm of electronics and microcontroller programming.

Zobacz ten wpis:  Wyświetlacz 4 cyfry arduino - jak podłączyć i wykorzystać?