/******************************** name: Water level sensor module with Arduino Uno and LED function: Measuring water level and sending status about the water level to serial monitor. If water level is between 0-5mm the red LED will be on and switch off when sensor is out of water and dry. ********************************/ //Email:info@acoptex.com //Website:www.acoptex.com /********************************/ // include libraries // no libraries needed for this project /********************************/ int sensorPin = A1; // select the input pin (must be analog) for the water level sensor module int ledPin = 8; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor /********************************/ void setup() { Serial.begin(9600); // initialize serial communications at 9600 bps pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { sensorValue = analogRead(sensorPin); // read the value from the sensor // send the message about water level to serial monitor if (sensorValue <= 0) { Serial.println("Water level: 0mm - Empty!"); } else if (sensorValue > 0 && sensorValue <= 223) { Serial.println("Water level: 0mm to 5mm"); digitalWrite(ledPin, HIGH); // turn the ledPin on } else if (sensorValue > 223 && sensorValue <= 251) { Serial.println("Water level: 5mm to 10mm"); } else if (sensorValue > 251 && sensorValue <= 277) { Serial.println("Water level: 10mm to 15mm"); } else if (sensorValue > 277 && sensorValue <= 294) { Serial.println("Water level: 15mm to 20mm"); } else if (sensorValue > 294 && sensorValue <= 311) { Serial.println("Water level: 20mm to 25mm"); } else if (sensorValue > 311 && sensorValue <= 314) { Serial.println("Water level: 25mm to 30mm"); } else if (sensorValue > 314 && sensorValue <= 323) { Serial.println("Water level: 30mm to 35mm"); } else if (sensorValue > 323) { Serial.println("Water level: 35mm to 40mm"); } delay(1000); //delay 1 second digitalWrite(ledPin, LOW); // turn the ledPin off - reset // the system when sensor out of the water and dry }