Introduction: Ultrasonic Rain Gauge: Raspebbery Pi Open Weather Station: Part 1
Commercial available IoT (Internet Of Things) Weather stations is expensive and not available every where (Like in South Africa). Extreme weather conditions hits us. SA is experiencing it hardest drought in decades, the earth is heating up and farmers struggle to produce profitable, with no technical or financial support of the government for commercial farmers.
There are a few Raspberry Pi weather stations around, like the one that the Raspberry Pi Foundation build for UK schools, bud it is not available for the general public. Lots of suitable sensors exist, some analog, some digital, some solid state, some with moving parts and some very expensive sensors like ultrasonic anemometers (wind speed and direction)
I decided building an open source, open hardware Weather Station, with parts general available in South Africa may be a very useful project and I will have lots of fun (and challenging headaches).
I decided to start with a solid state (no moving parts) rain gauge. The traditional tipping bucket did not impress me at that stage (even thought I never used one by then). So, I thought, rain is water and water conducts electricity. There are many analog resistive sensors where the resistance decrease when the sensor come in contact with water. I thought this will be a perfect solution. Unfortunately those sensors suffer from all kinds of anomalies like electrolysis and deoxidation and the readings from those sensors was unreliable. I even build my own stainless steel probes and a small circuit board with relays to create alternating direct current (constant 5 volt, but alternating the positive and negative poles) to eliminate electrolysis, but the readings was still unstable.
My latest choice is Ultrasonic Sound sensor. This sensor connected to the top of the gauge, can measure the distance to the water level. To my surprise this sensors was very accurate and very cheap (Less than 50 ZAR or 4 USD)
Step 1: Parts Needed (Step 1)
You will need the following
1) 1 Raspberry Pi (Any model, I am using a Pi 3)
2) 1 Bread Bord
3) Some jumper cables
4) A one Ohms resistor and a two (or 2.2) Ohms resistor
5) An old long cup to store the rain. I printed mine (soft copy available)
6) An old manual rain gauge capturing part (Or you can design your own and print it)
7) Measuring equipment to measure milliliters or a scale to weight water
8) The HC-SR04 Ultrasonic Sensor (South Africans can get them from Communica)
Step 2: Building Your Circuit (Step 2)
I found some very useful guide to help me build the circuit and to write the python scripts for this project. This scrip calculates distances and you will use it to calculate the distance between the sensor mounted at the top of your gauge tank and the water level
You can find it here:
https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi
Study it, build your circuit, connect it to your pi and play around with the python code. Make sure you build the voltage divider correct. I used a 2.2 ohms resistor between GPIO 24 and GND.
Step 3: Build Your Gauge (Step 3)
You can print your gauge, use an existing gauge or cup. The HC-SR04 sensor will be attach to the top of your gauge main tank. It is important to make sure it will stay dry at all times.
It is important to understand the measurement angle of your HC-SR04 sensor. You can not attach it to the top of a cone form traditional rain gauges. I normal cylindrical cup will do. Make sure it is wide enough for a proper sound wave to go down to the bottom. I think a 75 x 300 mm PVC pipe will do. To test if the signal is going through your cylinder and bounce back properly, measure the distance from the censor to the bottom of your cylinder with a ruler, compare that measurement with the distance you get from the sensor TOF (Time of flight) estimated distance to the bottom.
Step 4: Calculations and Calibration (Step 4)
What does 1 millimeter rain mean? One mm rain mean that if you had a cube of 1000mm X 1000mm X 1000mm or 1m X 1m X 1m, the cube will have a depth of 1 mm rain water if you left it outside when it rain. If you empty this rain in a 1 Liter bottle, it will full the bottle 100 % and the water will also measure 1kg. Different rain gauges have different catchment areas. If your catchment area of your gauge was 1m X 1m it is easy.
Also, 1 gram of water is conventional 1 ml
To calculate your rainfall in mm from your gauge you can do the following after weighting the rain water:
W is the rainfall weight in grams or mililiter
A is your catchment area in square mm
R is your total rainfall in mm
R = W x [(1000 x 1000)/A]
There are two possibilities in using the HC-SR04 to estimate W (You need W to Calculate R).
Method 1: Use plain Physics
Measure the distance from the HC-SR to the bottom of you gauge (You were doing it also in a previous step) with the sensor using the TOF (Time of Flight) calculations in the python script from https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi Call This CD (Cylinder Depth)
Measure the area of the inside bottom of your cylinder with anything suitable in square mm. Call this IA.
Now throw 2 ml water (or any suitable quantity) in your cylinder. Using our sensor, estimate the distance to the new water level in mm, Cal this Dist_To_Water).
The Water depth (WD) in mm is:
WD=CD - Dist_To_Water (Or Cylinder Depth Minus the Distance from the censor to the water level)
No the estimated Weight of the water is
W=WD x IA in ml or grams (Remember 1 ml water weights 1 gram)
Now you can estimate Rainfall (R) in mm with W x [(1000 x 1000)/A] as previously explained.
Method 2: Calibrate your meter with Statistics
Since the HC-SR04 is not perfect (errors may acquire), it seems like it is at least constant in measuring if your cylinder is suitable.
Build a linear model with sensor readings (or sensor distances) as dependent variable and injected weights of water as dependent variable.
Step 5: Software (Step 5)
Software for this project is still in development.
The python scripts at https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi should be usable.
Attach is some python applications useful (General Public License) developed by myself.
I plan to develop a web interface for the complete weather station later. Attach is some of my programs used to calibrate the meter and do sensor readings
Use the attach calibration script to calibrate the gauge statistically. Import the data in a spreadsheet to analyse.
Step 6: Still to Do (Step 6)
A Solenoid valve is needed to empty the tank when full (Close to the sensor)
The first few rain drops is not always measured correctly, especially if the gauge is not properly leveled. I am in process of developing a disdro meter to capture this drops correctly. The disdro my future next.
Ad a second ultrasonic sensor to measure the effect of temp on the TOF. I will soon post an update on this.
I found the following resource that may assist
https://www.researchgate.net/profile/Zheng_Guilin3/publication/258745832_An_Innovative_Principle_in_Self-Calibration_by_Dual_Ultrasonic_Sensor_and_Application_in_Rain_Gauge/links/540d53e00cf2f2b29a38392b/An-Innovative-Principle-in-Self-Calibration-by-Dual-Ultrasonic-Sensor-and-Application-in-Rain-Gauge.pdf