Distance Sensor

This is a sensor light that specifically senses the distance. It will shine when you pass by or when you are too close to it.
Supplies
A box
Arduino
Tools to open three holes on the box
Find a Box and Make Three Holes on the Box

Find a cardboard box and cut three holes on it so that the circuit board can be completely inserted
Complete the Arduino


Finish your circuit board.
#include
#include
// For these LCD controls to work you MUST replace the standard LCD library from... // https://github.com/marcoschwartz/LiquidCrystal_I2C // Direct download https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip // 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: lcd_I2C_27.init (); // initialize the lcd lcd_I2C_27.backlight(); digitalWrite( 6 , LOW ); //set ultrasonic sensor trigPin
pinMode( 12 , OUTPUT); // sets the digital pin as output lcd_I2C_27.setCursor(0 , 0) ; // set the cursor, counting begins with 0 lcd_I2C_27.print( "distance" ); // Print a message to the LCD.
}
void loop(){ // put your main code here, to run repeatedly: if ( UltrasonicSensorCM( 6 , 7 ) < 50 ) { digitalWrite( 12 , HIGH ); // sets the digital pin on/off } else { digitalWrite( 12 , LOW ); // sets the digital pin on/off } 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.print( UltrasonicSensorCM( 6 , 7 ) ); // Print a message to the LCD. delay( 100 ); // waits a few milliseconds }
Finish

Finish it and decoration