AUTO SWITCH WATER PUMP BY SENSOR MPX5010DP

In this project I present the automatic switch on the pump with a pressure difference sensor. The main point of this algorithm is that the pump will turn on when the water level in the tank reaches a minimum level, when the level reaches the maximum level the pump will turn off. Level detection is based on the amount of hydrostatic pressure detected by the MPX5010DP sensor.
Minimum and maximum level values ​​can be set via pushbutton, these minimum and maximum values ​​will be stored in EEPROM.

water level controling MPX5010DP set button

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Pump%20switch%20MPX5010.zip

#include <avr/interrupt.h>
#include <avr/eeprom.h>
#define led 5
int addr1 = 1;
int addr2 = 9;//avoid to use address 2
int readValue1;
int readValue2;
int a;
int b;
const int buttonPin1 = 4; //down limit setting
int buttonState1 = 0;
const int buttonPin2 = 3; //upper limit setting
int buttonState2 = 0;
void setup()
{
Serial.begin(9600);
//pinMode(encoder_pin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
digitalWrite(buttonPin1, HIGH);
digitalWrite(buttonPin2, HIGH);
pinMode(led, OUTPUT);

}

void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == LOW) {
a = analogRead(A0);
while (!eeprom_is_ready());
cli();
if(eeprom_read_word((uint16_t*)addr1) != a) {
eeprom_write_word((uint16_t*)addr1, a);
}
sei();

}
else if (buttonState2 == LOW) {
a = analogRead(A0);
while (!eeprom_is_ready());
//cli();
if(eeprom_read_word((uint16_t*)addr2) != a) {
eeprom_write_word((uint16_t*)addr2, a);
}
sei();

}
else{

action();

}

}

void action(){
readValue1 = eeprom_read_word((uint16_t*)addr1);
readValue2 = eeprom_read_word((uint16_t*)addr2);
a = analogRead(A0);

if (a <= readValue1) {
digitalWrite(led, HIGH);//this output go to relay IN

}
if (a >= readValue2) {
digitalWrite(led, LOW);
}
Serial.print(readValue1);
Serial.print(” “);
Serial.print(readValue2);
Serial.print(” “);
Serial.println(a);

}