Saturday, October 27, 2018

Ultrasonic Water Level / Temp / Humidity Sensor

All this worked swimmingly and still does. The modules is ticking away perfectly.

Problem is I built a replica Prototype Unit to clean up the code and get some more sensors and setup a proper Python controller in the Pi but none of the Sketches would verify. I cant identify the issue but clearly it is a problem with the Libraries. The best approach under these circumstances is to go back to scratch and set up the system again. 

Problem 1. dht.h not a valid library. I removed all DHT Libraries and reinstalled the  zip file included in the tutorial.
Sketch now compiles.

Fixed. Just gradually rebuilt the other few libraries and now the Water Level Sketch works too.

Project will measure the level of water in my 300 Litre tank and the Temp Humidity in the Boltonwagen. 



AM2302 DHT22 Temperature And Humidity Sensor Module For Arduino SCM


Electrical properties:
Operating voltage: DC 5V
Total current work: 40mA
Acoustic emission frequency: 40khz
Farthest distance: 4.5m
Blind: 25cm

Resolution: about 0.5cm
Angle: 70 degrees
Working temperature: -10 ~ 70 ℃
Storage temperature: -20 ~ 80 ℃


+ 5V (positive power supply)                  RD
Trig (control side) RX                D 11     WH
Echo (the receiver) TX               D 12     GY
GND (negative)                                       BLK

Principle of Operation:

(1) using IO port TRIG trigger location, to the high level signal of at least 10us;
(2) module automatically sends 8 40KHz pulse, automatic detecting whether a signal return;
(3) a signal return, a high level is output through the IO port ECHO, the time duration of the high level is
ultrasonic from launch to return. The test distance = (high level time * speed of sound (340M/S)) /2;

Software & Refs :

Library for  Ultrasonic Sensor

Tank Dimensions:

W 2109 x D  185 x H 770 (Measured Dimension)   300 Litres


/* How to use the DHT-22 sensor with Arduino uno
 Project will measure the level of water in my 300 Litre tank and Temperature and humidity.
   More info:
   Dev: Michalis Vasilakis // Date: 1/7/2015 //

 Mark Bolton
 7 September 2018

 Two sketches are combined.   //water   and  //temp


#include <dht.h>        //temp
#include <NewPing.h>      //water
#include <MedianFilter.h>
#include <Wire.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 800 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

dht DHT;

#define DHT22_PIN 8     // DHT 22  (AM2302) - what pin we're connected to

float hum;  //Stores humidity value
float temp; //Stores temperature value

int tank_Depth = 18;                    // Tank Depth (cm)
int tank_Width = 211;                   // Tank Width (cm)
//int US_ROUNDTRIP_CM;                  // Tank Height (cm) from sensor.
int water_Volume;                       // Amount of water in the tank. (Litres)

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

MedianFilter filter(31,0);

void setup()

void loop()
    int chk = DHT.read22(DHT22_PIN);
  //Read data and store it to variables hum and temp
    hum = DHT.humidity;
    temp= DHT.temperature;

  delay(100);                          // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int o,uS =;   // Send ping, get ping time in microseconds (uS).;
  o = filter.out();
  //Print temp and humidity values to serial monitor
  Serial.print("Hum: ");
  Serial.print(" %, Temp: ");
  Serial.print(" C. ");

  //Print level and Volume to monitor
  Serial.print("Level: ");
  Serial.print( o / US_ROUNDTRIP_CM);
/* Convert ping time to distance in cm and print result (0 = outside set distance range)*/

/* calculate volume .001 to convert to Litres / cm. * D * W * H (77) - distance from surface of the water to the sensor. */
  water_Volume = 0.001 * tank_Depth * tank_Width *  77 - o / US_ROUNDTRIP_CM;
  Serial.print(" Vol: ");
  Serial.print(" L");

// CSV file
  Serial.print("  ");
  Serial.print( o / US_ROUNDTRIP_CM);


No comments:

Post a Comment