Using a Potentiometer to Turn on a Green Light Using Arduino
by Yug S Desai in Circuits > Arduino
59 Views, 0 Favorites, 0 Comments
Using a Potentiometer to Turn on a Green Light Using Arduino
Introduction:
In this project, we will use an Arduino Uno, a potentiometer, and a green LED to demonstrate how analog input can control an output. The potentiometer, which acts as a variable resistor, will be used to adjust the input signal to the Arduino. As you turn the potentiometer knob, the Arduino will read the changing voltage and, once it reaches a certain threshold, will light up the green LED. This project is a great way to learn the basics of analog-to-digital conversion and using inputs to control outputs in Arduino projects.
Downloads
Supplies
Materials Needed:
- Arduino Uno (or any compatible board)
- Green LED
- 220Ω Resistor
- Potentiometer (10kΩ works well)
- Breadboard
- Jumper wires
- USB cable (to connect Arduino to your computer)
Setup
Circuit Setup:
- Green LED:
- Connect the longer leg (anode) of the green LED to pin 9 of the Arduino.
- Connect the shorter leg (cathode) to one end of the 220Ω resistor.
- Connect the other end of the 220Ω resistor to GND on the breadboard (ground rail).
- Potentiometer:
- Connect the middle pin of the potentiometer to A0 (analog input pin) on the Arduino.
- Connect one of the side pins of the potentiometer to 5V (power).
- Connect the other side pin to GND.
- Powering the Arduino:
- Connect your Arduino to your computer using the USB cable.
Code
the image above shows the code
How It Works
How It Works:
- Reading the potentiometer: The potentiometer is connected to analog pin A0, which reads values between 0 and 1023. When you turn the potentiometer knob, the Arduino reads these changes.
- Controlling the LED: In the code, if the potentiometer value goes above 512 (halfway), the green LED turns on. If it’s below, the LED stays off.
- Serial Monitor (Optional): You can open the Serial Monitor (in the Arduino IDE) to see the values from the potentiometer in real-time. This helps you see what’s happening as you turn the knob.