Table of Contents

Play Video

ENERGY SAVER HOME

A smart device with an LED, ULTRASONIC SENSOR, Arduino Uno, that glows the light with ultrasonic sensor when somebody opens the door, ultrasonic detects it send the  information to light to glow with the help of arduino.

In this project we made an innovative smart device that integrates an LED, an ultrasonic sensor, and an Arduino Uno. The system is designed to enhance any entryway by automatically lighting up when someone opens the door. As the door opens, the ultrasonic sensor detects the motion and sends a signal to the Arduino Uno. Then it will triggers the LED to glow, illuminating the space. This hands-free, responsive lighting solution not only adds a touch of convenience and safety but also showcases the seamless integration of sensor technology with everyday objects. We mostly see this technology in smart homes, offices, or creative installations, this project highlights the exciting possibilities of modern electronics and automation.

// Define pin connections
const int trigPin = 9; // Pin connected to the Trig pin of the ultrasonic sensor
const int echoPin = 10; // Pin connected to the Echo pin of the ultrasonic sensor
const int ledPin = 13; // Pin connected to the LED

// Define variables for calculating distance
long duration;
int distance;

void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);

// Set pin modes
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);

// Ensure the LED is off initially
digitalWrite(ledPin, LOW);
}

void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Set the trigPin high for 10 microseconds to send out a pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read the echoPin and calculate the duration of the pulse
duration = pulseIn(echoPin, HIGH);

// Calculate the distance (speed of sound is 340 m/s or 29.1 microseconds per cm)
distance = duration * 0.034 / 2;

// Debugging: print the distance
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

// If the distance is less than a threshold (e.g., 50 cm), turn on the LED
if (distance < 50) {
digitalWrite(ledPin, HIGH);
Serial.println("Door opened - LED ON");
}
// If the distance is greater than or equal to the threshold, turn off the LED
else {
digitalWrite(ledPin, LOW);
Serial.println("Door closed - LED OFF");
}

// Add a small delay before the next loop
delay(100);
}

Scroll to Top