//Include LCD library
#include <LiquidCrystal_I2C.h>
#include <HCSR04.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2);
UltraSonicDistanceSensor distanceSensor(A0,A1);
float distance;
float boxHeight = 185.0;
int buzzerPin= 8;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(buzzerPin, OUTPUT);
printInstructions();
}
void loop() {
distance = distanceSensor.measureDistanceCm();
Serial.println(distance);
delay(1000);
/*
lcd.clear();
lcd.setCursor(0,0);
lcd.print(distance);
*/
if (distance < 65 ) {
printHeight();
delay(1000);
tone(buzzerPin, 1000);
delay(1000);
noTone(buzzerPin);
delay(5000);
} else {
printInstructions();
}
}
void printInstructions() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Stand under the");
lcd.setCursor(0,1);
lcd.print("box!");
}
void printHeight() {
int heightInCm = boxHeight - distance;
int heightInInches = heightInCm/1;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Height:");
lcd.setCursor(8,0);
lcd.print(heightInInches);
lcd.setCursor(11,0);
lcd.print("IN");
lcd.setCursor(0,1);
//lcd.print(distance);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
bz1:1
bz1:2
ultrasonic1:VCC
ultrasonic1:TRIG
ultrasonic1:ECHO
ultrasonic1:GND