#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int TRIGGER_PIN =9;
int ECHO_PIN =10;
int BUZZER_PIN =5;
int SERVO_PIN =6;
Servo myServo;
long duration;
int distance;
void setup() {
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Systeme Init...");
delay(1000);
lcd.clear();
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
myServo.attach(SERVO_PIN);
tone(BUZZER_PIN, 1000, 500);
lcd.setCursor(0, 0);
lcd.print("Pret a fonctionner");
delay(1000);
lcd.clear();
}
void loop() {
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = duration * 0.034 / 2;
lcd.setCursor(0, 0);
lcd.print("Niveau d'eau:");
lcd.setCursor(0, 1);
lcd.print(distance);
lcd.print(" cm ");
if (distance > 30) {
myServo.write(90);
tone(BUZZER_PIN, 1000, 200);
lcd.setCursor(10, 1);
lcd.print("Remplissage...");
} else {
myServo.write(0);
noTone(BUZZER_PIN);
lcd.setCursor(10, 1);
lcd.print("Plein ");
}
delay(1000);
}