Digital LED Staircase lightening in motion using Arduino and Ultrasonic Sensor

Automated lightening of staircase not only helps to save electricity but also takes us to advancement in quality living of life. We generally uses normal circuit to turn on and off the light in stairs, but there is loss in electricity since we turn it off only at once during sleep.
So, in this tutorial we are going to make the automated staircase that will light up only when it senses motion of people passing through stair.

Circuit diagram:
(NOTE: First upload the program to the Arduino then only do the circuit connection in order to avoid short circuit in the Arduino from previously uploaded code.Also connect 0.5k resistor to each bulb. )

COMPONENTS REQUIRED:
  1. Ultrasonic Sensor (HC-SR04)  X  2
  2. Arduino UNO
  3. 5 volt LED bulbs  X   2
CODING:
(Copy and pest the given below code to the arduino IDE and compile it.)

int trigPin1=7; //set the HC-SR04 SENSOR 1 triger on pin 7 on the arduino

int echoPin1=8;//set the HC-SR04 SENSOR 1 echo on pin 6 on the arduino

int trigPin2=A0; //set the HC-SR04 SENSOR2 triger on pin 7 on the arduino

int echoPin2=A1; //set the HC-SR04 SENSOR2 echo on pin 6 on the arduino

int led1=1;
int led2=2;
int led3=3;

void setup()
{
Serial.begin (9600); 
pinMode(trigPin1, OUTPUT); //set the trigpin to output
pinMode(echoPin1, INPUT); //set the echopin to input
pinMode(trigPin2, OUTPUT); //set the trigpin to output
pinMode(echoPin2, INPUT); //set the echopin to input
pinMode(led1, OUTPUT); //set the led1 on pin 1 to output
pinMode(led2, OUTPUT); //set the led1 on pin 1 to output
pinMode(led3, OUTPUT); //set the led1 on pin 1 to output
}

void loop()
{
float duration1, distance1; //Define two intregers duration and distance to be used to save data for sensor1
float duration2, distance2; //Define two intregers duration and distance to be used to save data for sensor2

digitalWrite(trigPin1, HIGH); //write a digital high to the trigpin to send out the pulse
delayMicroseconds(500); //wait half a millisecond
digitalWrite(trigPin1, LOW); //turn off the trigpin
duration1 = pulseIn(echoPin1, HIGH); //measure the time using pulsein when the echo receives a signal set it to high
distance1 = (duration1/2) / 29.1; //distance is the duration devided by 2 becasue the signal traveled from the trigpin then back to the echo pin, then divide by 29.1 to convert to centimeters

digitalWrite(trigPin2, HIGH); //write a digital high to the trigpin to send out the pulse
delayMicroseconds(500); //wait half a millisecond
digitalWrite(trigPin2, LOW); //turn off the trigpin
duration2 = pulseIn(echoPin2, HIGH); //measure the time using pulsein when the echo receives a signal set it to high
distance2 = (duration2/2) / 29.1; //distance is the duration devided by 2 becasue the signal traveled from the trigpin then back to the echo pin, then divide by 29.1 to convert to centimeters

if (distance1<13 || distance2< 13) //if the distance is less than 13 CM
{
digitalWrite(led1,HIGH);
delay (2000); //wait 2 seconds
digitalWrite(led2,HIGH);
delay (15000); //wait 2 seconds
digitalWrite(led3,HIGH);
delay (15000); //wait 5 seconds
}
else
{
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);  
}
}
 
In this way you can make your own automated staircase at home using Arduino and Ultrasonic sensor.

Application:
  1. You can save electricity bill when there is no one bypassing through stair.
  2. Project lead us to automated and quility living life.

Post a comment

0 Comments