#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//
const int echoPin= 11 ;
const int triggerPin=12;
long duration ;
int distance;
//
int mine;
int maxe;
//
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9,8 ,7 ,6 };
byte colPins[COLS] = {5,4,3 ,2 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("bouzelof ");
delay(2000);
lcd.clear();
//
pinMode(triggerPin, OUTPUT);
pinMode(echoPin, INPUT);
// get the first number from the keypad
lcd.setCursor(0,1);
// نقوم بادخال الحد الادنى وهو المسافة بين الحساس والماء
lcd.clear();
lcd.print("enter the min");
lcd.setCursor(0,1);
char key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
mine= mine * 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
//
lcd.clear();
lcd.print("enter the max");
// نقوم بادخال الحد الاعلى وهو المسافة الصغيرة بين الحساس والماء
lcd.setCursor(0,1);
key = keypad.waitForKey();
while (key != '#') {
if (key >= '0' && key <= '9') {
maxe=maxe* 10 + (key - '0');
lcd.print(key);
}
key = keypad.waitForKey();
}
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin,HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=duration*0.034/2;
lcd.clear();
//
if (distance>=mine) {
digitalWrite(10, HIGH);
}
if (distance<=maxe){
digitalWrite(10, LOW);
}
if(digitalRead(10)==HIGH ){
lcd.setCursor(0,1);
lcd.print("pompe: ON");
}if(digitalRead(10)==LOW ){
lcd.setCursor(0,1);
lcd.print("pompe: OFF");
}
delay(1000);
}