IoT

Arduino Water Tank Monitor

Under ground Water-tank or Well level monitor can be a challenge in summer times . I needed a solution in case a refill tanker is needed my IoT environment should alert in time.

Have already Arduino base system running different sensors. Main challenge was the location of water tank which is almost 30 meters away from my current setup. tried to look up the cable maximum length Arduino can support. Using the DC Cable Sizing Tool I calculated that 20 AWG wire will work covering the required distance of 30 meters. (To calculate and learn about the resistance of wires this link can be useful ) On voltmeter 4.98 Volts across the 30 meter coil of the normal 2 pair telephone wire (22 AWG). SR-04 works between 5 to 3.5 Volts and is perfect for this scenario. It transmit Ultrasonic waves and receives back the echo to calculate the distance.

Parts

Arduino UNO1
JSN-SR04 Ultrasonic Water Proof Sensor1
220 Ohm Resistor4
WiresAs needed
Parts Used

Schematic

Schematics

After installation of wires hooked up Arduino with A raspberry pi to get serial Data if needed to re calibrate Water tank depth. This also help to Polt the data using Python.

Code

int Echo = 10;  
int Trigger = 9;
long TimeSpan, Result;  
int depth=200; //define depth of tank in Result
int OneFourth = 4; 
int TwoFourth = 5;
int ThirdFourth = 6;
int FourFourth = 7;

void setup() {

Serial.begin (9600);
pinMode(Trigger, OUTPUT); //Trigger Pin
pinMode(OneFourth, OUTPUT);
pinMode(TwoFourth, OUTPUT);
pinMode(ThirdFourth, OUTPUT);
pinMode(FourFourth, OUTPUT);
pinMode(Echo, INPUT);  //Echo Pin
}

void loop()
{
//Trigger the Sound Pulse
digitalWrite(Trigger, HIGH);
delayMicroseconds(20);

digitalWrite(Trigger, LOW);

TimeSpan = pulseIn(Echo, HIGH);
delay(300);
// The speed of sound is 29.1 microsecond per centimeter. so resulting distance in Centimeters would be
Result = (TimeSpan/2) / 29.1;

// Print Depth to serial port
Serial.print(Result);
Serial.println();

if (Result >= (3*depth/4)) {
    digitalWrite(OneFourth, HIGH);
    digitalWrite(TwoFourth, HIGH);
    digitalWrite(ThirdFourth, HIGH);
    digitalWrite(FourFourth, HIGH);
  } 
else if(Result >= (2*depth/4)){
    digitalWrite(OneFourth, LOW);
    digitalWrite(TwoFourth, LOW);
    digitalWrite(ThirdFourth, HIGH);
    digitalWrite(FourFourth, HIGH);
  }
else if(Result >= (1*depth/4)){
    digitalWrite(OneFourth, LOW);
    digitalWrite(TwoFourth, LOW);
    digitalWrite(ThirdFourth, LOW);
    digitalWrite(FourFourth, HIGH);
  }
else {
    digitalWrite(OneFourth, LOW);
    digitalWrite(TwoFourth, LOW);
    digitalWrite(ThirdFourth, LOW);
    digitalWrite(FourFourth, LOW);
  }

}

above code simply divide the tank in 4 fractions and lights up LED as water level drops.