Dynamic Light Play: Interactive LED Control with Potentiometer and Button
Concept
The aim of this project was to use a combination of analog and digital inputs to control two LEDs (one red, one blue) in a creative and functional way. The potentiometer serves as an analog input, allowing us to control the brightness of the red LED, while a button acts as a digital input to control the blue LED. This setup meets the assignment requirement to use at least one analog sensor and one digital sensor, with one LED controlled in an analog fashion and the other in a digital fashion.
Materials Used
- Arduino Uno board
- Breadboard
- Red LED and Blue LED
- Potentiometer (analog sensor)
- Button (digital sensor)
- Resistors:
- 10kΩ for the button’s pull-up resistor
- 330Ω for each LED
- Jumper Wires
Arduino Code
const int potPin = A0; const int buttonPin = 2; const int redLEDPin = 9; const int blueLEDPin = 8; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(redLEDPin, OUTPUT); pinMode(blueLEDPin, OUTPUT); } void loop() { int potValue = analogRead(potPin); int redLEDIntensity = map(potValue, 0, 1023, 0, 255); analogWrite(redLEDPin, redLEDIntensity); int buttonState = digitalRead(buttonPin); if (buttonState == LOW) { digitalWrite(blueLEDPin, HIGH); } else { digitalWrite(blueLEDPin, LOW); } delay(10); }
Implementation
Video Demonstration
Reflections
This project was a practical way to understand the difference between analog and digital inputs and outputs. The potentiometer provided smooth, gradual control over the brightness of the red LED, giving me hands-on experience with analog input. The button provided simple on/off control for the blue LED, demonstrating digital input.
Challenges:
- Button Debouncing: Without the slight delay, the button would sometimes register multiple presses in a quick succession due to “bouncing.” Adding a
delay(10);
solved this issue.
Future Improvements:
- Adding more LEDs or sensors to expand the circuit’s functionality.
- Using more advanced analog sensors, such as a temperature or light sensor, to explore other applications.