Advertisement
andretafta

Turbidity Sensor Arduino LCD i2c

Jun 9th, 2024 (edited)
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************
  2. * Techeonics
  3. * Turbidity module mjkdz
  4. * @author - Gaurav Kumar (Techeonics)
  5.  
  6. Youtube- https://www.youtube.com/c/THETECHEONICS
  7. See <http://www.techeonics.com> for details.
  8.  
  9. * ****************************************************/
  10. #include <LiquidCrystal_I2C.h>
  11.  
  12. LiquidCrystal_I2C lcd(0x27, 2, 16);
  13.  
  14. int sensorPin = A0; //A0 FOR ARDUINO/ 36 FOR ESP
  15.  
  16. void setup()
  17. {
  18.   Serial.begin(9600);
  19.   // initialize LCD
  20.   lcd.begin();
  21.   // turn on LCD backlight                      
  22.   lcd.backlight();
  23. }
  24. void loop() {
  25.   int sensorValue = analogRead(sensorPin);
  26.   Serial.println(sensorValue);
  27.   int turbidity = map(sensorValue, 0, 750, 100, 0);
  28.   delay(100);
  29.  
  30.   if (turbidity < 20) {
  31.     lcd.setCursor(0, 0);
  32.     lcd.print("Status: Jernih");
  33.     Serial.print(" its CLEAR ");
  34.   }
  35.   if ((turbidity > 20) && (turbidity < 50)) {
  36.     lcd.setCursor(0, 0);
  37.     lcd.print("Status: Keruh");
  38.     Serial.print(" its CLOUDY ");
  39.   }
  40.   if (turbidity > 50) {
  41.     lcd.setCursor(0, 0);
  42.     lcd.print("Status: Kotor");
  43.     Serial.print(" its DIRTY ");
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement