Arduino Rain Gauge Calibration

Introduction: Arduino Rain Gauge Calibration

About: Recovering Physicist.

Introduction:

In this Instructable we 'construct' a rain gauge with Arduino and calibrate it to report daily and hourly rainfall. The rain collector I am using is a re-purposed rain gauge of the tipping bucket type. It came from a damaged personal weather station. However there are a lot of great Instructables on how to make one from scratch.

This Instructable is a part of a weather station I am making and is a documentation of my learning process disguised as a tutorial:)

Characteristics of the Rain Gauge:

  • measurements of daily and hourly rainfall is in inches for easy upload to Weather Underground.
  • debouncing code for the magnetic switch is not included to keep the code simple.
  • being more of a tutorial the finished product is more of a prototype of a prototype.

Step 1: Some Theory

Rainfall is reported/measured in millimeters or inches which has the dimension of length. It is indicative of how high, every portion of rain area got the rain, if the rain water had not dissipated and drained away. So, a 1.63 mm of rainfall would mean that if I had a flat leveled tank of any shape the rain water collected would be of a height 1.63 mm from the tanks bottom.

All rain gauges have a rainfall catchment area and a rainfall amount measurement. The catchment area is the region over which the rain is collected. The measuring object would be some kind of volume measurement for a liquid.

So the rainfall in mm or inches would be

rainfall height = volume of rain collected / catchment area

In my rain collector, the length and breadth were 11 cm by 5 cm respectively giving a catchment area of 55 sq.cm. So a collection of 9 milliliters of rain would mean 9 cc/55 sq.cm = 0.16363... cm = 1.6363... mm = 0.064 inches.

In the tipping bucket rain gauge, the bucket tips 4 times for 9 ml (or 0.064... inches of rain) and so a single tip is for (9/4) ml = 2.25ml (or 0.0161.. inches). If we take hourly readings (24 readings per day before resets) keeping three significant digit accuracy is decent enough.

Thus, at each bucket tip/tumble, the code accesses it as 1 on-off-on sequence or one click. Yes, we have reported 0.0161 inches of rain. To repeat, from the Arduino point of view

one click = 0.0161 inches of rain

Note 1: I prefer the International System of Units, but Weather Underground prefers the Imperial/US units and so this conversion into inches.

Note 2: If calculations are not your cup of tea, head over to Volume of Rainfall which provides perfect help for such matters.

Step 2: Parts for This Project

Most of the parts were lying around and a fair listing (for formality) is

  1. Arduino Uno (or any other compatible)
  2. Rain Gauge from old damaged weather station.
  3. Breadboard.
  4. RJ11 to connect my Rain Gauge to the breadboard.
  5. 10K or higher resistor to act as a pull up resistor. I have used 15K.
  6. 2 pieces of male-to-female jumper wires
  7. 2 male-to-male jumper wire.
  8. USB Cable; A Male to B Male

Tools:

  • Syringe (12 ml capacity was used).

Step 3: The Rain Collector

The photos of my rain collector should make thing clear to many. Anyway, the rain that falls on its catchment area gets channeled to one of the two tipping-buckets inside it. The two tipping-buckets are connected like a see-saw and as the rain water weight ( 0.0161 inches of rain for mine ) tips one bucket down it gets emptied and the other buckets goes up and positions itself to collect the next rain water. The tipping motion moves a magnet over a 'magnetic-switch' and the circuit gets electrically connected.

Step 4: Circuit

To make the circuit

  1. Connect digital pin #2 of Arduino to one end of the resistor.
  2. Connect the other end of the resistor to the Ground pin (GND).
  3. Connect one end of the RJ11 jack to the digital pin #2 of Arduino.
  4. Connect the other end of the RJ11 jack to the +5V pin of Arduino (5V).
  5. Plug the rain gauge to the RJ11.

The circuit is complete. Jumper wires and breadboard make the connections easier to make.

To complete the project connect the Arduino to the PC using the USB cable and load the sketch provided below.

Step 5: The Code

The sketch RainGauge.ino (embedded at the end of this step) is well commented and so I shall point out three sections only.

One part counts the number of tipping-bucket tips.

if(bucketPositionA==false && digitalRead(RainPin) == HIGH){
	...
	...
}

Another part checks time and computes the rain amount

if(now.minute()==0 && first == true){
	hourlyRain = dailyRain - dailyRain_till_LastHour;
	......
	......

and another part clears the rain for the day, at midnight.

if(now.hour() == 0){
	dailyRain = 0;
	.....

Step 6: Calibration & Testing

Disconnect the Rain Collector from the rest of the circuit and perform the following steps.

  1. Fill up the syringe with water. I fill mine with 10 ml.
  2. Keep the Rain Collector on a level surface and pour out the water from the syringe bit by bit.
  3. I keep a count of the tipping buckets. Four tips were enough for me, and drained 9 ml from the syringe. According to calculations (see theory section) I got the amount of 0.0161 inches of rain per tip.
  4. I include this information into my code in the beginning.
const double bucketAmount = 0.0161;

That's all to it. For more accuracy, one can include more digits like 0.01610595. Of course your calculated numbers are expected to vary if your Rain Collector is not identical to mine.

For testing purposes

  1. Connect the Rain Collector to the RJ11 socket.
  2. Connect the Arduino to the PC using the USB cable.
  3. Open the serial monitor.
  4. Pour previously measured amounts of water and observe the output when the hour completes.
  5. Do not pour any water but wait for the next hour to complete. The hourly rain must be zero in this case.
  6. Keep the PC with the connected circuit powered overnight and see if the daily rain and hourly rain get reset to zero at midnight. For this step, one can also change the PC's clock to a suitable value (to watch the outputs on the serial monitor live).

Step 7: Afterthoughts & Acknowledgements

The resolution of the rainfall readings in my case is 0.0161 inches and cannot be made more accurate. Practical circumstances may decrease the accuracy further. Weather measurements do not have the accuracy of quantum mechanics.

Part of the code was borrowed from Lazy Old Geek's Instructable.

2 People Made This Project!

Recommendations

  • Fruits and Veggies Speed Challenge

    Fruits and Veggies Speed Challenge
  • Digital Fabrication Student Design Challenge

    Digital Fabrication Student Design Challenge
  • Tinkercad to Fusion 360 Challenge

    Tinkercad to Fusion 360 Challenge

45 Comments

0
derekdeclercq
derekdeclercq

1 year ago

My tipping rain bucket seems to generate ticks when its not raining. Mounted level etc, but registers 5 to 10 times on dry days. Cable is about 10m long, not sure if that might cause it? Some weak correlation to wind but not strong and sometimes happen with no wind. Not sure if I should look for mechanical or electrical problem

0
MarkM88
MarkM88

Reply 3 days ago

I am seeing the same problem.... What was your solution??

0
laurent777
laurent777

Question 8 months ago

Excellent work! I had to install it for a client and you saved me! By any chance, did you also work with the other parts of the kit: the wind vane and the anemometer? I can see 4 wires from the RJ11 but not sure how to plug them.
Thanks again

0
psdtz
psdtz

1 year ago

Thank you for your instruction!

Some supplements:
You need to install the adafruit RTCLib library via arduino library manager (https://www.arduino.cc/en/guide/libraries) or manually (https://github.com/adafruit/RTClib) to compile the code. Alternatively you could use a (real) real time clock module. This is a bit more difficult. Perhaps you could add this important "library"-step in your instructable.

You could also add an other resistor (100 Ohm) in series to the reed switch to give it a longer life.

0
italex33
italex33

2 years ago

I posted a question, but I deleted it since I figured out the solution, so this post will make more sense. Here it goes, my rain bucket has the same dimension as the example posted here: 11cm by 5cm = 55 sq cm, and 10 ml give me 6 tips or clicks, so 10/55 = (0.1818 sq cm X 10 = 1.8181ml), convert it to inches(1.8181ml/25.4) I get 0.0715 inches, these inches divided by 6 ( 0.0715/6) the result is: 0.0119 inches of rain per tip/click, am I right?

The solution was found after analyzing DanB339 post.

By the way, I adapted your code to the Particle Photon environment, the code works just fine.

Thanks a lot , and keep up the good hobbies.

Here are a couple pictures showing the entire Personal Weather Station (PWS) that's also feeding weather data to Wunderground.

PWS1.jpegPWS2.jpeg
0
haybolat
haybolat

Reply 1 year ago

Hello, my rain gauge is 19.1 ml in 12 buckets. How can I calculate this in square meters? I would be glad if you could help.

0
Abhijit Borah
Abhijit Borah

Reply 2 years ago

Awesome to see your solar powered weather station and thank you for your kind words.
Your 0.0119 inches of rain per tip/click is correct. Yet it is different from my 0.0161 inches/click. We are differing by about 26%. This has come from the fact you got 6 tips for 10 ml while I got 4 tips for 9 ml. Not same. So I have to make sure that my 4 tips for 9 ml is correct or not. Sadly, I do not have the rain collector anymore. However all this has pointed that we need to repeat our calibration observations with great great care. One way would be to use more liquid and observe for more bucket tips.

Your query has made me a wiser person, thank you.

0
bradhnz
bradhnz

Question 2 years ago on Step 1

Hello, great piece of code and reusing old parts.
How would I change this code to get 10 minute totals.
Also what is the 5v used for as mine works with just a ground and pin 2?

Thanks again.
Brad

0
Abhijit Borah
Abhijit Borah

Answer 2 years ago

"Also what is the 5v used for as mine works with just a ground and pin 2?"

- When the magnetic switch is connected, it is "sure to read" 5 volts.
(https://www.instructables.com/id/How-to-use-a-Push...)

Below is the code to watch the rain in 10 minute intervals (Not tested, only compiled).
---------------------------------------------------------------------------------------------------------------

/*
description: Basic Rain Gauge with arduino with serial monitoring
Reports the daily-rain and rain-in-last-1o-minutes in inches
acknowledgement: part of the code copied and modified from
https://www.instructables.com/id/Arduino-Weather-S...
liscence: GNU GPL. https://www.gnu.org/licenses/gpl.html
*/

#include "RTClib.h"
#include <Wire.h>
#define RainPin 2 // The Rain input is connected to digital pin 2 on the arduino


bool bucketPositionA = false; // one of the two positions of tipping-bucket
const double bucketAmount = 0.01610595; // inches equivalent of ml to trip tipping-bucket
double dailyRain = 0.0; // rain accumulated for the day
double rain_Last_10_mins = 0.0;
double dailyRain_till_Last_10_mins = 0.0;

RTC_Millis rtc; // software RTC time


void setup(void) {
Serial.begin(9600); // start the serial port at 9600 bauds
rtc.begin(DateTime(__DATE__, __TIME__)); // start the RTC
pinMode(RainPin, INPUT); // set the Rain Pin as input.
delay(4000); // i'm slow in starting the seiral monitor (not necessary)
Serial.println("Ready!!!"); // not necessary too
}


void loop(void){
DateTime now = rtc.now();

// ++++++++++++++++++++++++ Count the bucket tips ++++++++++++++++++++++++++++++++
if ((bucketPositionA==false)&&(digitalRead(RainPin)==HIGH)){
bucketPositionA=true;
dailyRain+=bucketAmount; // update the daily rain
}

if ((bucketPositionA==true)&&(digitalRead(RainPin)==LOW)){
bucketPositionA=false;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if(now.second()== 0 && now.minute()%10==0){ // execute only in 10 minute intervals

rain_Last_10_mins = dailyRain - dailyRain_till_Last_10_mins; // calculate the last 10 minutes rain
dailyRain_till_Last_10_mins = dailyRain; // record the last 10 minutes rain for next calculation

// fancy display for humans to comprehend
Serial.println();
Serial.print(now.hour());
Serial.print(":");
Serial.print(now.minute());
Serial.print(": Total Rain for the day = ");
Serial.print(dailyRain,8); // the '8' ensures the required accuracy
Serial.println(" inches");
Serial.println();
Serial.print(" : Rain in last 10 minutes = ");
Serial.print(rain_Last_10_mins,8);
Serial.println(" inches");
Serial.println();
}

if(now.hour()== 0) {
dailyRain = 0.0; // clear daily-rain at midnight
rain_Last_10_mins = 0.0; // we do not want negative rain at 00:10
}
} // end of loop

0
formicrop
formicrop

Reply 1 year ago

Hi, Abhijit Borah! Thanks for this, I'll be able to use this code for our project.
But "Rain in last 10 minutes" is always 0 and the values every 10 mins just adds up into "Total Rain for the day". Can you help me to determine where the problem is? Thank you!!!

0
bradhnz
bradhnz

Reply 2 years ago

Thanks Abhijit. That works fine.
I would like to input this into asksensors through my ethernet hat. Is this something you have looked at?

0
Abhijit Borah
Abhijit Borah

Reply 2 years ago

"I would like to input this into . . " - Thank you, thank you. Please go ahead!

0
GenaroOliviero
GenaroOliviero

Question 1 year ago on Step 2

Nice weather rain gauge, but I use a selfmade hardware gauge with Hall sensor and magnet inside with 3 wires from the hall sensor + - and high and low wire is this also possible with this software or should I look anything else on instructables

0
Abhijit Borah
Abhijit Borah

Answer 1 year ago

I have not used Hall sensors so far.
Maybe if you check the output with a multi-meter first to check if it is 5v or 3.3v. The Arduino "looks" for high (5 volts) in the rain-pin.

The code (its old and needs revision) should run if the concerned libraries are present.

0
GenaroOliviero
GenaroOliviero

Reply 1 year ago

OK thanks Abhijit Borah I go to take my multimeter and look for 5Volt

0
GenaroOliviero
GenaroOliviero

Reply 1 year ago

My DIY rain gauge hardware many ours labour

IMG_20210101_190619158.jpg
0
hope.paradise94
hope.paradise94

Question 2 years ago

Hi ad, I have a wrong thing when I verify this code. Can you help me to solve this? :(

Untitled.png
0
Abhijit Borah
Abhijit Borah

Answer 2 years ago

Difficult to guess without having a look at the code. I could not duplicate your situation. Can it be a typo some where? Anyway I have send the code to your email.

2020-04-09 11_12_56-Untitled - Notepad.jpg
0
hope.paradise94
hope.paradise94

2 years ago on Step 5

Hi. Thanks so much for this project. It is helpful for me. But I can't use your library you defined "RTClib.h". So If you can, can you give me the library as soon as posible. Thanks. :D