int trig=13,echo=12,buzzerPin=1;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.println("test");
pinMode(buzzerPin, OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
}
unsigned long time, distance;
void loop()
{
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
time = pulseIn(echo, HIGH);
distance=time/58;
Serial.print("distance= ");
Serial.println(distance);
delay(100);
if(distance<100){
noTone(buzzerPin);
lcd.clear(); // clear display
//lcd.setCursor(0, 0); // move cursor to (0, 0)
// lcd.print(""); // print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (2, 1)
lcd.print("battery is full "); // print message at (2, 1)
delay(1000); // display the above for two seconds
}
else if (distance>=100){
lcd.print("battery is empty"); // print message at (0, 1)
delay(1000);
tone(1,distance );
delay(5000);
noTone(1);
lcd.clear(); // clear display
// lcd.setCursor(3, 0); // move cursor to (3, 0)
//lcd.print(""); // print message at (3, 0)
lcd.setCursor(0, 1); // move cursor to (0, 1)
}
}