You are on page 1of 1

const int analogPin = A0; // if water level sensor module attached to analog pin

A0 of Arduino Uno
//const int digitalPin = 7; // if water level sensor module attached to digital
pin 7 of Arduino Uno

int thresholdValue = 200;//you can adjust the threshold value

const int relayPin = 6;//5v relay module attached to digital pin 6 of Arduino Uno
/********************************/
void setup() {
Serial.begin(9600); // initialize serial communications at 9600 bps
pinMode(relayPin, OUTPUT);//sets the relayPin as OUTPUT
digitalWrite(relayPin, HIGH);
}

void loop() {
int analogValue = analogRead(analogPin);//analog value from soil moisture sensor
// int digitalValue = digitalRead(digitalPin);//digital value from soil moisture
sensor
Serial.print("Sensor value: ");// send the value from the sensor to serial
monitor
Serial.print(analogValue);// send the value from the sensor to serial monitor
Serial.print(" ;");
// Serial.print("Sensor status:");
// Serial.println(digitalValue);// send the value from the sensor to serial
monitor

if (analogValue >= thresholdValue) {


Serial.print(" - Water level is HIGH");
digitalWrite(relayPin, LOW);
Serial.println(" - Pump is on");
}
else {
Serial.print(" - Water level is LOW");
digitalWrite(relayPin, HIGH);
Serial.println(" - Pump is off");
/*

if (digitalValue = 1) {
Serial.println(" - Alarm!!! Water level is high");
}
else {
Serial.println(" - Water level is low");
}
*/
}
delay(200); //sets delay for 200 ms
}

You might also like