Using a Potentiometer to Turn on a Green Light Using Arduino

by Yug S Desai in Circuits > Arduino

39 Views, 0 Favorites, 0 Comments

Using a Potentiometer to Turn on a Green Light Using Arduino

image_2024-09-13_104519708.png


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:

  1. Arduino Uno (or any compatible board)
  2. Green LED
  3. 220Ω Resistor
  4. Potentiometer (10kΩ works well)
  5. Breadboard
  6. Jumper wires
  7. USB cable (to connect Arduino to your computer)

Setup

Circuit Setup:

  1. Green LED:
  2. Connect the longer leg (anode) of the green LED to pin 9 of the Arduino.
  3. Connect the shorter leg (cathode) to one end of the 220Ω resistor.
  4. Connect the other end of the 220Ω resistor to GND on the breadboard (ground rail).
  5. Potentiometer:
  6. Connect the middle pin of the potentiometer to A0 (analog input pin) on the Arduino.
  7. Connect one of the side pins of the potentiometer to 5V (power).
  8. Connect the other side pin to GND.
  9. Powering the Arduino:
  10. Connect your Arduino to your computer using the USB cable.


Code

image_2024-09-13_104331042.png

the image above shows the code

How It Works

How It Works:

  1. 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.
  2. 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.
  3. 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.