#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address and dimensions
const int triggerPin = 26; // Define the trigger pin
const int echoPin = 25; // Define the echo pin
float cm;
float inches;
long readUltrasonicDistance() {
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(3, 1);
lcd.print("Head Dou Big");
lcd.setCursor(1, 3);
lcd.print(" Ar ha ar ha ar ha");
delay(2500);
lcd.clear();
}
void loop() {
cm = 0.03420 / 2 * readUltrasonicDistance();
if (cm < 40) {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Warning! Full!");
} else {
inches = (cm / 2.54);
lcd.setCursor(5, 0);
lcd.print("Please fill in");
lcd.setCursor(2, 3);
lcd.print("Inches");
lcd.setCursor(13, 3);
lcd.print("CM");
lcd.setCursor(3, 2);
lcd.print(inches, 1);
lcd.setCursor(12, 2);
lcd.print(cm, 1);
lcd.setCursor(14, 1);
}
delay(2000);
lcd.clear();
}