Arduino Rain Gauge Calibration

18,245

33

25

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.
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.

Recommendations

• Internet of Things Class

22,845 Enrolled

25 Discussions

Habe alles zusammengebaut und Sketch geladen. IDE lädt alles ohne Fehler. Auf dem seriellen Monitor wird nichts angezeigt. Reedkontakt mit LED geprüft = oK

Hello, Baut have to stand on 9600.It does not work in the serial monitor. Add two pictures, then everything is ok. What could be the problem? Despair.

Der Teil des Codes -

if (now.minute () == 0 && first == true) {
---- ----
---- ----
---- ----
}

sendet die Ausgabe nur am Ende jeder Minute an den seriellen Monitor. Wir sollten mindestens eine Minute oder länger auf die Ergebnisse warten.

Hallo, habe gewartet und mehrmals getestet,. Es erfolgt keine Veränderung und Anzeige am seriellen Monitor. Habe das Uno Board auf Funktionsfähigkeit über Blinkprogramm geprüft, läuft einwandfrei. Irgendetwas stimmt mit dem Sketch nicht.

If there are no complication errors, then (just a guess), I hope you set the baud rate in your serial monitor at 9600bps. . .

Baud rate is 9600, there is no display. What can I do?

This is great and this worked for me. can you please share code for wind direction if you have. It will be great. I am implementing cloud based Weather station with NodeMCU and Maplin weather station spare parts ( Wind speed, wind Direction and Rain Gauge ) .

Hi,

I had used my old weather station's spare parts together with DHT22, BMP180 and UVM30A to upload weather data to weather underground via a Ethernet shield. The code is below, but a few things to note first:

1. The code was copies from here, there and everywhere, form the internet.

2. A soft RTC updated via NTP was used and modified for my time zone (GMT+5.5).

3. The code is sloppy & dirty (and very old).

4. Calibrating the wind gauge is slightly tricky. At that time I did not have a hand held anemometer and so I had to go around my town with the anemometer outside my car saving data to a micro sdcard and do regression analysis later :)

----------------------------------------------------------------------------------------------------------------

//*******************************************************************************************
// Minimum Code to check the ethernet shield, arduino and connection to weather underground
// Arduino Uno Version 3, Ethernet Sheild, DHT22, NTP, Rain Gauge, UVM30A
// Working as on 27th May 2017
//*******************************************************************************************

#include // Library for I2C (A4 = SDA, A5 = SCL)
#include "RTClib.h" // Library for realtime clock
#include // DHT11 & DHT22 Library
#include // Including BMP180 library
#include // Elapsed Millisecond library
#include // SPI interface used by ethernet sheild
#include // Library for the Ethernet Sheild
#include // New from IDE 1.0
#include

byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; // setting mac address

#define RainPin 5 // The Rain input is connected to digital pin D5

// time servers for ntp
char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte pb[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets

// Weather Underground servers and account
//char SERVER[] = "weatherstation.wunderground.com"; // name address of WU
char SERVER[] = "rtupdate.wunderground.com"; // Realtime update server
char WEBPAGE[] = "GET /weatherstation/updateweatherstation.php?";
char ID[] = "Your Station ID";

IPAddress ip(192, 168, 0, 11); // I am using static IP in my home network

EthernetClient client; // Initialize the Ethernet client library

const unsigned long IDLE_TIMEOUT_MS = 1000; // Time to wait for the WunderGround server to respond
EthernetUDP Udp; // UDP for the time server

DHT dht(2, DHT22); // Initialize DHT22 sensor at Pin D2
SFE_BMP180 pressure; // Initialize an object for BMP180
RTC_Millis rtc; // Initialize an object for RTC

// ********************** VARIABLES **************************************************************
float Humidity, Temp_C1, Temp_F, dp_F; // variables for temperature, pressure of DHT22
double Temp_C2, P; // variables for temperature, pressure of BMP180

// Rain Variables
bool bucketPositionA = false; // one of the two positions of tipping-bucket
const double bucketAmount = 0.010246; // inches equivalent of ml to trip tipping-bucket
double dailyRain = 0;; // rain accumulated for the day
double hourlyRain = 0;; // rain accumulated for one hour
double dailyRain_till_LastHour = 0; // rain accumulated for the day till the last hour
bool rainToggle; // as we want readings of the (MHz) loops only at the 0th moment

bool actionToggle; // to upload data at stipulated times only

// UV Index
int UVindex;

void setup() {
Serial.begin(9600);
delay(4000);
Serial.print("Weather Station, 4th May 2017\n\n");

delay(60000);

rtc.begin(DateTime(__DATE__, __TIME__)); // Start the RTC

Ethernet.begin(mac, ip); // Start the Ethernet Shield
delay(4000); // Wait for Ethernet Shield
Udp.begin(8888); // Local Port is 8888
delay(2000); // Give some time
rtc.adjust(DateTime(ntp()+19800-2208988800UL)); // to IST (extra 19800 secs) - seventy years
DateTime now = rtc.now(); // Get the date & time
DateTimeNow();

// ***** Start the Sensors ****************************************************************
dht.begin(); // Start the DHT22 sensor

if (pressure.begin())Serial.println("BMP180 init success"); // Start the BMP180 sensor
else {
Serial.println("BMP180 init fail\n\n");
while(1); // Pause forever if error.
}
}

//******************************************************************************

void loop() {

DateTime now = rtc.now(); // Get the date & time
// adjust time every day at 00:00
if(now.hour() == 0 && now.minute() == 0)rtc.adjust(DateTime(ntp()+19800-2208988800UL));

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++ Rain Gauge ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// ++++++++++++++++++++++++ Count the bucket tips ++++++++++++++++++++++++++++++++
bucketPositionA=true;
dailyRain+=bucketAmount; // update the daily rain
}

bucketPositionA=false;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

hourlyRain = dailyRain - dailyRain_till_LastHour; // calculate the last hour's rain

if(now.minute() != 0) rainToggle = true; // after the first minute is over, be ready for next read
if(now.minute() == 0 && rainToggle == true){
dailyRain_till_LastHour = dailyRain; // update the rain till last hour for next calculation
rainToggle = false; // execute calculations only once per hour
}

if(now.hour()== 0) {
dailyRain = 0.0; // clear daily-rain at midnight
dailyRain_till_LastHour = 0.0; // we do not want negative rain at 01:00
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if(now.minute()%15 != 0) actionToggle = true; // After the actionToggle minute is over, be ready for next read
if(now.minute()%15 == 0 && actionToggle == true){ // Read other sensors and upload

//******** readings from DHT22 with debug *************************************
if (isnan(Humidity) || isnan(Temp_C1) || isnan(Temp_F)) { //
Serial.println("Failed to read from DHT sensor!"); //
return; //
} //
//*****************************************************************************
dp_F = dewPointFast(Temp_C1,Humidity); // Calculation of dew point

//******** UV Index ***********************************************************

UVindex = GetUVIndex(analogRead(0)); // Get the UVIndex at A0

if (client.connect(SERVER,80)) {
Serial.println("\n\nSending DATA ");

//*************************************************************************
client.print(WEBPAGE);
client.print("ID=");
client.print(ID);
client.print("&softwaretype=Arduino%20UNO%20Version%203");
//client.print("&action=updateraw"); // Standard update
client.print("&action=updateraw&realtime=1&rtfreq=2.5"); //Rapid Fire
client.print("&dateutc=");
client.print(now.year());
client.print("-");
client.print(now.month());
client.print("-");
client.print(now.day());
client.print("+");
client.print(now.hour());
client.print("%3A");
client.print(now.minute());
client.print("%3A");
client.print(now.second()+5);

client.print("&humidity=");
client.print(Humidity);
client.print("&tempf=");
client.print(Temp_F);
client.print("&dewptf=");
client.print(dp_F);

client.print("&rainin=");
client.print(hourlyRain);
client.print("&dailyrainin=");
client.print(dailyRain);

client.print("&UV=");
client.print(UVindex); // Gsens UVM30A uv sensor

client.print("&baromin=");
client.print(P/33.864);

client.print("&winddir=");
client.print(windDirection);
client.print("&windspeedmph=");
client.print(windspdmph_avg2m);
client.print("&windgustmph=");
client.print(maxwndspdmph);
//client.print("&windgustmph_10m=");
//client.print(windgustmph); // [mph past 10 minutes wind gust mph ]

//client.print(Wm2);

client.print(" HTTP/1.0\r\n");
client.print("Accept: text/html\r\n");
client.print("Host: ");
client.print(SERVER);
client.print("\r\n\r\n");
//*************************************************************************
}
else {
Serial.println(F("Connection Failed"));
delay(2000);
return;
}

while (client.connected()) {
if (client.available()) {
Serial.print(c);
}
}

client.stop(); // Stop/disconnect the ethernet Client

PrintSerial(); // Display reading onver the serial port

actionToggle = false;
} // end of action toggle
delay(10);
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++ End of Void Loop +++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++ NTP Function ++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

unsigned long ntp(){
unsigned long secsSince1900;
sendNTPpacket(timeServer); // send an NTP packet to a time server

// wait to see if a reply is available
delay(1000);
if (Udp.parsePacket()){

// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
return secsSince1900;
}
}

//-------------------------------------------------------------
// send an NTP request to the time server at the given address
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;

// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++ Date Time display +++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void DateTimeNow(){

DateTime now = rtc.now(); // Get the date and time

if(now.hour() < 10)Serial.print("0");
Serial.print(now.hour());
Serial.print(":");
if(now.minute() < 10)Serial.print("0");
Serial.print(now.minute());
Serial.print(":");
if(now.second() < 10)Serial.print("0");
Serial.println(now.second());
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++ Dew Point Calculations in Fahrenheit ++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity){
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
double Td = 32 + 1.8*(b * temp) / (a - temp);
return Td;
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++ Serial Monitor Display ++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void PrintSerial(){

Serial.print("\n\nTime :\t");
DateTimeNow();
Serial.print("\nHumidity: ");
Serial.print(Humidity);
Serial.print(" %,\t");
Serial.print("Dew Point: ");
Serial.print(dp_F);
Serial.print(" F,\t");
Serial.print("Temperature: ");
Serial.print(Temp_C1);
Serial.print(" C, ");
Serial.print(Temp_F);
Serial.println(" F\n");

Serial.print("Total Rain for the day:\t");
Serial.print(dailyRain,8); // the '8' ensures the required accuracy
Serial.print(" inches\t");
Serial.print("Rain during last hour: ");
Serial.print(hourlyRain,8);
Serial.println(" inches");
Serial.println();

Serial.print("UV Index: ");
Serial.print(UVindex);
Serial.println();
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++ UV Index ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int GetUVIndex(int uvVoltage){

int UVIndex = 0;

int voltage = (uvVoltage * (5.0 / 1023.0))*1000; //Voltage in miliVolts

if(voltage<50)
{
UVIndex = 0;
}else if (voltage>50 && voltage<=227)
{
UVIndex = 0;
}else if (voltage>227 && voltage<=318)
{
UVIndex = 1;
}
else if (voltage>318 && voltage<=408)
{
UVIndex = 2;
}else if (voltage>408 && voltage<=503)
{
UVIndex = 3;
}
else if (voltage>503 && voltage<=606)
{
UVIndex = 4;
}else if (voltage>606 && voltage<=696)
{
UVIndex = 5;
}else if (voltage>696 && voltage<=795)
{
UVIndex = 6;
}else if (voltage>795 && voltage<=881)
{
UVIndex = 7;
}
else if (voltage>881 && voltage<=976)
{
UVIndex = 8;
}
else if (voltage>976 && voltage<=1079)
{
UVIndex = 9;
}
else if (voltage>1079 && voltage<=1170)
{
UVIndex = 10;
}else if (voltage>1170)
{
UVIndex = 11;
}
return UVIndex;
}

Thanks for sharing the project.
i have some questions:
1- why the rtc doesn't show the same time as my computer?
2- if i want to save all the data i get from arduino and make a database in a file, is it better to make it inside arduino code? or save it in an EPROM for example? or make it by compute (the systems keeps sending the data to the computer, and the computer stocks the data)?

First: Sorry for the long, long delay ....... .......

Ans 1. The line

rtc.begin(DateTime(__DATE__, __TIME__));

in the setup part of the sketch sets the soft-RTC time to the same as that of the PC at the time of compilation. Consequently, if we start the arduino later, it should start with the same time as that at the time of compilation. I did not emphasize this earlier, my mistake. For logging purposes, this would a serious issue, and we would need a hardware based RTC like DS1703, etc. But for calibration purposes this should do (but not right still).

Ans 2. For using such a rain gauge and logging rain data, both will do (again do not wrongly assume me to be an expert). EEPROM has limited writes (100,000 times) and of course of finite capacity. Using a SD Card shield is also an option.

But if you plan to use it to monitor rain, keeping your PC on "all the time" and nearby a the rain gauge is not a good idea. Specially so, if your rain gauge happen to be remotely located.

Lastly, thank you for your first question, it has showed me that I should improve on this code and make a proper rain logger in future.

This is great, and seems to work for me. I assume you'd be able to change the code so that it could record total rainfall at a higher resolution? For example total for 15 minutes (or even more frequent!), as well as hourly and daily? Would this be an easy thing to add to the code?

2 replies

In fact this project was created as I wanted to repurpose a weather station rain and wind sensors with an Arduino. It worked fine, uploading data after every 15 minutes (to weather underground) untill a hailstorm totalled them.

Such Arduino codes are available all over the internet ( and I shall be glad to share mine too).

So, my issue on this has to do with the conversions on 2 parts. The first is this part:
"9 cc/55 sq.cm = 0.16363... cm = 1.6363... mm = 0.394 inches"
So as I do the calculations, 9 cc/55 sq.cm does equal 0.16363 cm which does equal 1.6363 mm. BUT, as I do the conversion to inches, I come up with 1.6363 mm = 0.06442 inches, not 0.394 inches.
Next is this:
"In the tipping bucket rain gauge, the bucket tips 4 times for 9 ml (or 0.394... inches of rain) and so a single tip is for (9/4) ml = 2.25ml (or 0.0161059413027953.. inches)"
So 9/4 is in fact 2.25, but if you say 9 ml = 0.394 inches of rain, if I take 0.394/4 =0.0985, not 0.0161059413027953 inches.
Can you explain how you came to these numbers?

Two points from my side:

1. Thank you for spotting the error. I have corrected it.

2.
Please accept my apologies too. I cant figure out, or explain, how on
earth I put in the strange number "0.394" instead of the 0.0161 which
you have suggested.

If you make a mistake and do not correct it, this is called a mistake.”— Confucius

Thank you again.

Nice to see you re-purpose the rain gauge. I have one in my parts bin for future use.

Thanks.

Thank you for taking an interest in this Instructable.

1. I used the adafruit library from github, the link is below.

In that page, there is a pink-horizontal-bar. Just below that to the right is the "Download ZIP" button. Click there to get the RTC library.

2. The Wire.h library as seen in https://www.arduino.cc/en/Reference/Wire
has been used to provide connection to the RTC using the two
connections SDA and SDC. It is called the I2C protocol. It reduces the
connecting wires specially if you have many I2C devices like LCD display
with I2C, RTC with I2C, etc. Any device that has pins labelled SDA and
SDC uses I2C protocol/procedure 'usually' and for using them the wire.h
library must be included in the sketch.

Do let me know if you need any further clarifications.

Abhijit