Distance-Controlled LED Brightness with Arduino
The project “Distance-Controlled LED Brightness with Arduino” combines ultrasonic distance sensing with LED control, creating an interactive system where LED brightness corresponds to the proximity of an object.
An ultrasonic sensor, connected to the Arduino, measures the distance, and this value is then used to calculate the intensity, influencing the brightness of an LED.
The real-time distance feedback is displayed on the serial monitor, providing a visual representation of the system’s responsiveness.
This project offers an accessible introduction to distance sensing applications and demonstrates the dynamic control capabilities of Arduino.
Component List:
Name | Quantity | Component |
---|---|---|
U4 | 1 | Arduino Uno R3 |
DIST1 | 1 | Ultrasonic Distance Sensor |
L1 | 1 | Light bulb |
The circuit involves connecting an ultrasonic sensor to pins 9 (trigPin) and 10 (echoPin) on the Arduino. The LED is connected to pin 3. The ultrasonic sensor measures the distance to an object, and the Arduino adjusts the LED’s brightness based on this distance. The simplicity of the circuit makes it an ideal learning tool for those exploring Arduino-based sensor applications.
Arduino Code:
int distanceThreshold = 0;
int trigPin = 9;
int echoPin = 10;
float timeduration;
float distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
distanceThreshold = 450;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
timeduration = pulseIn(echoPin, HIGH);
distance = timeduration * (0.034) / 2;
Serial.print("Distance: ");
Serial.println(distance);
int intensity = (distanceThreshold / 255) * distance;
analogWrite(3, intensity);
delay(500);
}
“Distance-Controlled LED Brightness with Arduino” serves as an engaging project for Arduino enthusiasts, offering hands-on experience in integrating sensors for dynamic control.
The real-world application of adjusting LED brightness based on distance demonstrates the practicality of such systems in various contexts, from interactive installations to energy-efficient lighting.
This project encourages experimentation and learning in the exciting intersection of electronics and sensor technologies.