Water level measurement using ultrasonic-SR04 sensor and arduino

Water level measurement using ultrasonic-SR04 sensor and Arduino is all about the measuring water level using non-contact type measurement using ultrasonic HC-SR04 sensor module and Arduino-Uno board. I’ll explain how it works and how to interface with Arduino and circuit simulation using proteus.





Ultrasonic HC-SR04 :

Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work:

  1. Using IO trigger for at least 10us high level signal,
  2. The Module automatically sends eight 40 kHz and detect whether there is a pulse signal    back.
  3. IF the signal back, through high level , time of high output IO duration is the time from sending      ultrasonic to returning.
  Test distance = (high level time × velocity of sound (340M/S) / 2




Timing diagram:

The Timing diagram is shown below. You only need to supply a short 10uS pulse to the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in proportion .You can calculate the range through the time interval between sending trigger signal and receiving echo signal. 

Formula: us / 58 = centimeters or us / 148 =inch 
Or
Range = high level time * velocity (340M/S) / 2

We suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.


NOTE:

 The module is not suggested to connect directly to electric, if connected electric, the GND terminal should be connected the module first, otherwise, it will affect the normal work of the module.


  When tested objects, the range of area is not less than 0.5 square meters and the plane requests as smooth as possible, otherwise ,it will affect the Results of measuring.


Circuit diagram:




As shown in the image connect a ultrasonic distance sensor pin to Arduino-uno pin as Vcc to +5V, trigger to pin-8, echo to pin-2, ground to Ground.

Also connect the water level indicator LED to Arduino-Uno board as LED1 to pin-4, LED2 to pin-6, LED3 to pin-5 and LED4 to pin-3.This LED indicates how much water is remaining in water tank.
Connect relay to pin-9 of Arduino-Uno. Relay is use for control water pump ON/OFF while water tank is empty water pump is automatically ON and it’s automatically OFF after tank is full.

Rough diagram:

Put the ultrasonic distance sensor at top of the water tank as shown in image




Arduino Code:

const int trigPin1 = 8;
const int echoPin1 = 2;

void setup()
{
  // initialise serial communication:
  Serial.begin(9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
}

void loop()
{
   // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration1, inches, cm1,mm1;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.  // Give a short LOW pulse     beforehand to ensure a clean HIGH pulse:  // Default timeout is one second .
//  pinMode(trigPin1, OUTPUT);
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);

  // Read the signal from the sensor: a HIGH pulse whose   // duration is the time (in microseconds) from the sending   // of the ping to the reception of its echo off of an object.
 // pinMode(echoPin1, INPUT);
  duration1 = pulseIn(echoPin1, HIGH); // give high pin time in microsecond. // syntex : pulseIn(pin, value, timeout)
  cm1 = microsecondsToCentimeters(duration1);
  mm1 = microsecondsToMilimeters(duration1);
 // delay(100);

    Serial.print("cm1 : ");
    Serial.print(cm1); Serial.print(",");
    Serial.print("mm1 : ");
    Serial.print(mm1); Serial.print(",");
    Serial.println();
 
  delay(1000);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 28.5 / 2;
}
long microsecondsToMilimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimetre.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 2.900 / 2;
}

Tutorial Video:


                see more about this tutorial and simulation using ISIS - Proteus. if this tutorial helpful for you then like and subscribe to my you tube channel for more helpful tutorials thank you.


Post a Comment

0 Comments