Closing Light Reminder

Introduction: Closing Light Reminder

This is a piece of equipment about reminding you to close the light when you leave the room. It's using an Arduino Leonardo board. And it's equipped with an ultrasonic detector that can detect when you are walking out of the room. A speaker to remind you when the light is on after you walk out of the room. A sensor that detects if the light is on or off. And an LCD that shows the distance between the door and the ultrasonic sensor.

video of how it works:

Step 1: Assembling the Parts

Assembling the parts in the picture. Which is ultrasonic sensor, light sensor, LCD, speaker.

Step 2: Writing Codes

here are the codes that are used to perform the actions (using ardublock):

#include

#include

int _name ; // For these LCD controls to work you MUST replace the standard LCD library from... // https://github.com/marcoschwartz/LiquidCrystal_I2... // Direct download https://github.com/marcoschwartz/LiquidCrystal_I2... // Your project will not compile until this is done. LiquidCrystal_I2C lcd_I2C_27(0x27,16,2); // set the LCD address for a 16 chars and 2 line display int UltrasonicSensorCM(int trigPin, int echoPin) //Ultrasonic Sensor Code Auto Generated Return CM max distance 200 { long duration; pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(20); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); duration = duration / 59; if ((duration < 2) || (duration > 200)) return false; return duration; }

void setup(){ // put your setup code here, to run once: Serial.begin(9600); // opens serial port, sets data rate to 9600 bps lcd_I2C_27.init (); // initialize the lcd lcd_I2C_27.backlight(); digitalWrite( 6 , LOW ); //set ultrasonic sensor trigPin

_name = 180 ;

Serial.print(analogRead( A0 )); //print message Serial.print(" "); //print a blank Serial.println();

delay( 20 ); // waits a few milliseconds

}

void loop(){ // put your main code here, to run repeatedly: lcd_I2C_27.clear(); lcd_I2C_27.setCursor(0 , 0) ; // set the cursor, counting begins with 0 lcd_I2C_27.print( "Distance :" ); // Print a message to the LCD. lcd_I2C_27.setCursor(0 , 1) ; // set the cursor, counting begins with 0 lcd_I2C_27.print( UltrasonicSensorCM( 6 , 7 ) ); // Print a message to the LCD. Serial.print( UltrasonicSensorCM( 6 , 7 )); //print message Serial.print(" "); //print a blank Serial.println(); if ( UltrasonicSensorCM( 6 , 7 ) <= 70 && analogRead( A0 ) > 600 ) { tone(11, 440, 2000); //buzzer or speaker frequency } else { tone(12, 0, 1000); //buzzer or speaker frequency } delay( 500 ); // waits a few milliseconds }

Step 3: Make an Outer Case of the Equipment

Step 4: Done!

Be the First to Share

    Recommendations

    • Back to School: Student Design Challenge

      Back to School: Student Design Challenge
    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest
    • Micro:bit Contest

      Micro:bit Contest

    2 Comments

    0
    timothyong16
    timothyong16

    Reply 11 months ago

    My pleasure