Ultrasonic water level sensor arduino indicator

Ultrasonic water level indicator mainly consists of an HC-SR04 ultrasonic module, which is used for non-contact distance readings. An Ultrasonic water level sensing is a non-contact level measurement technique.

For measuring water level, place the ultrasonic module on top of a tank vertically downwards, so as to face the transducer towards the water.

water level measurement using ultrasonic sensor, arduino hc-sr04 water level indicator

When the wave travels from the medium of air to water, the majority of the transmitted ultrasonic waves get reflected back to the module. By calculating the travel time of waves to the water surface, the Arduino converts the module output to corresponding length units in centimetre.

In the program, the distance values are adjusted for a water tank of 1-metre height. The 1-metre height is divided into 3 reference levels of water at quarter, half and three-quarter depth of the tank (taken in centimetres).

The ultrasonic module is placed 20cm above from the maximum water level. Thus a 20cm is subtracted from the measured distance value. For water below the quarter level, only LED at pin 8 will be ON. And the LEDs on pin 9,10,11 gets ON, as the water level crosses the quarter, half and three-quarter heights respectively.arduino water tank level sensor circuit

Code

const int trig = 2, echo = 3;
long duration, Distanceincm;
void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
}

void loop() {
  digitalWrite(trig, HIGH);
  delay(15);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  // The ultrasonic module is placed 20cm above from 1m tank.
  Distanceincm = (duration / 58) - 20;
  if (Distanceincm < 25) {  // Above three quarter
    digitalWrite(11, HIGH);
  }
  else {
    digitalWrite(11, LOW);  // Below three quarter
  }
  //
  if (Distanceincm < 50) {  // Above half level
    digitalWrite(10, HIGH);
  }
  else {
    digitalWrite(10, LOW);  // Below half level
  }
  if (Distanceincm < 75) {
    digitalWrite(9, HIGH);  // Above quarter level
  }
  else {
    digitalWrite(9, LOW);   // Below quarter level
  }
  //Below quarter level, only LED at pin 8 will be ON.
}
1 Star2 Stars3 Stars4 Stars5 Stars Rate Us!
Loading...

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *