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. 



Sensors:

JSN-SR04T-2.0 

AM2302 DHT22 Temperature And Humidity Sensor Module For Arduino SCM

Specification:

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 ℃

 
Wiring:

 
+ 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

https://github.com/daPhoosa/MedianFilter


https://www.youtube.com/watch?v=wb0sTy_26XM&ytbChannel=null 

http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html#


https://www.banggood.com/DC-5V-Waterproof-Ultrasonic-Module-Distance-Measuring-Transducer-Sensor-p-1094462.html



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: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
   Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com

 Mark Bolton
 7 September 2018

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

  */
 
//Libraries

#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;

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

//Variables
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()
{
    Serial.begin(9600);
}

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 = sonar.ping();   // Send ping, get ping time in microseconds (uS).

  filter.in(uS);
  o = filter.out();
  
  //Print temp and humidity values to serial monitor
  Serial.print("Hum: ");
  Serial.print(hum);
  Serial.print(" %, Temp: ");
  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)*/
  Serial.print("cm.");

/* 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(water_Volume);
  Serial.print(" L");

// CSV file
  Serial.print("  ");
  Serial.print(hum);
  Serial.print(",");
  Serial.print(temp);
  Serial.print(",");
  Serial.print( o / US_ROUNDTRIP_CM);
  Serial.print(",");
  Serial.println(water_Volume);


}

No comments:

Post a Comment