Concept
This project explores the interaction between analog and digital sensing to create an adaptive lighting system. The system uses an photoresistor as an analog sensor to measure ambient light levels, converting physical light quantities into continuous electrical signals. A push button serves as our digital sensor, providing discrete binary input. These sensors control two LEDs – one with PWM for variable brightness and another in simple on/off mode.
Schematic
Code snippet
const int LDR_PIN = A0; // Analog input const int BUTTON_PIN = 2; // Digital input const int PWM_LED_PIN = 9; // PWM output const int DIGITAL_LED_PIN = 13; // Digital output int lastButtonState = HIGH; bool ledState = false; void setup() { pinMode(BUTTON_PIN, INPUT); pinMode(PWM_LED_PIN, OUTPUT); pinMode(DIGITAL_LED_PIN, OUTPUT); Serial.begin(9600); } void loop() { // Read analog sensor int lightLevel = analogRead(LDR_PIN); // Convert 0-1023 range to 255-0 PWM range (inverted) int brightness = map(lightLevel, 0, 1023, 255, 0); analogWrite(PWM_LED_PIN, brightness); // Handle digital sensor int buttonState = digitalRead(BUTTON_PIN); if (buttonState != lastButtonState && buttonState == LOW) { ledState = !ledState; digitalWrite(DIGITAL_LED_PIN, ledState); } lastButtonState = buttonState; delay(50); }
Demo
Analog Control:
The LDR continuously measures ambient light levels, producing variable voltage outputs that are converted to digital values through the Arduino’s ADC. This analog signal controls the first LED’s brightness through PWM, creating a smooth dimming effect as environmental lighting changes.
Digital Control:
The push button provides binary input (HIGH/LOW), demonstrating the discrete nature of digital sensors. Each button press toggles the second LED between two states, showing the fundamental difference between analog and digital control systems.
Reflection and Future Improvements
This project effectively demonstrates the distinction between analog and digital sensing and control. The analog sensor provides continuous, proportional control, while the digital sensor offers precise, binary control.
Potential improvements could include:
- Adding hysteresis to the LDR readings to prevent flickering in borderline lighting conditions
- Implementing an exponential mapping for the PWM values to create more natural-feeling brightness transitions
- Adding a mode selector that allows the digital button to switch between different lighting patterns
- Incorporating a digital temperature sensor to adjust brightness based on both light and temperature
These enhancements would create a more sophisticated adaptive lighting system while maintaining the fundamental demonstration of analog versus digital sensing and control.