WATER DEPTH MEASUREMENT MPX5010DP WITH LCD

water depth meas MPX5010DPLCD

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/DEPTH%20MEAS%20MPX5010P.zip

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;
float h;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16,2); // initialize the lcd
lcd.home ();
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
h = (sensorValue-48.0403278832)/7.6673168807;
/*from calibration sensor value vs depth cm*/
Serial.print(“depth “);
Serial.print(h);
Serial.println(” cm”);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“depth = “);
lcd.setCursor(8, 0);
lcd.print(h);
//lcd.print(“”);
delay(1000); // delay in between reads for stability
}