Advertisement
andretafta

Turbidity Sensor Arduino LCD i2c

Jun 9th, 2024 (edited)
341
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. <thetecheonics@gmail.com>
  7. Youtube- https://www.youtube.com/c/THETECHEONICS
  8. See <http://www.techeonics.com> for details.
  9.  
  10. * ****************************************************/
  11. #include <LiquidCrystal_I2C.h>
  12.  
  13. LiquidCrystal_I2C lcd(0x27, 2, 16);
  14.  
  15. int sensorPin = A0; //A0 FOR ARDUINO/ 36 FOR ESP
  16.  
  17. void setup()
  18. {
  19.   Serial.begin(9600);
  20.   // initialize LCD
  21.   lcd.begin();
  22.   // turn on LCD backlight                      
  23.   lcd.backlight();
  24. }
  25. void loop() {
  26.   int sensorValue = analogRead(sensorPin);
  27.   Serial.println(sensorValue);
  28.   int turbidity = map(sensorValue, 0, 750, 100, 0);
  29.   delay(100);
  30.  
  31.   if (turbidity < 20) {
  32.     lcd.setCursor(0, 0);
  33.     lcd.print("Status: Jernih");
  34.     Serial.print(" its CLEAR ");
  35.   }
  36.   if ((turbidity > 20) && (turbidity < 50)) {
  37.     lcd.setCursor(0, 0);
  38.     lcd.print("Status: Keruh");
  39.     Serial.print(" its CLOUDY ");
  40.   }
  41.   if (turbidity > 50) {
  42.     lcd.setCursor(0, 0);
  43.     lcd.print("Status: Kotor");
  44.     Serial.print(" its DIRTY ");
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement