How to Hookup Hydreon Optical Rain Sensor to Arduino

Overview

We use the Hydreon RG-11 Optical rain sensor configured in tipping bucket mode to detect rain. Every time a predetermined amount of rain hits the sensor it will switch a relay. This switch is detected by the Arduino and can be used to count the amount of rain that has fallen.

Image

Hydreon RG-11 Optical Rain Sensor
Note: Images shown on this page are not to scale.

Hardware and Software Parts List

  • Arduino Board
  • Hydreon RG-11 Optical Rain Sensor (RG-11 Product Website)
  • 1 * 10K and 1 * 100 ohm resistor
  • Breadboard hookup wires
  • USB Cable to suite Arduino

Data Sheets


Circuit for hooking up Hydreon RG-11 Rain Sensor to Arduino

The rain sensor appears to the Arduino as a switch and is wired up the same as wiring up a switch to the Arduino. The RG-11 has either a NO (Normally Open) or NC (Normally Closed) output.

Hydreon RG-11 Hookup Circuit

We have connected to the RG-11 using the NO (Normally Open) outputs. When there is no rain detected the digital input on the micro controller (Arduino) will be pulled to 5V via the 10K resistor. If rain is detected then the RG-ll NO output will be closed and the digital input will go to ground.

The 100 ohm (100R) resistor is used to protect the micro controller input from damage if it is mis-configured and a dead short is created. This will limit the current flow and hopefully prevent any damage to the input.

Hookup Diagram for connecting the Hydreon RG-ll to a Arduino Board

Hydreon RG-11 Hookup Circuit

Software

The hookup and Arduino Sketch is for connecting a Hydreon RG-11 to digital pin 2.

We have configured the RG-11 for tipping bucket mode which means that it sends a pulse when a preset amount of rain hits the sensor. The dip switch mounted on the circuit board is used to set the mode of operation for the RG-11.

RG-11 Tipping Bucket Switch Settings

The sketch uses an interrupt handler to detect when a pulse is sent. When the input it is triggered it will execute the interrupt handler routine called rgisr on line 43. This routine increments the tipcount variable by 1. It is important that we keep the amount of code in the interrupt service routine as small as possible.


Sample Sketch

Hydreon RG-11 Sample Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define RG11_Pin 2// RG-11 is connected to digital pin 2
#define Bucket_Size 0.01// Bucket Tip Size as set by dip switch on sensor

volatile unsigned long tipCount;// bucket tip counter used in interrupt routine
volatile unsigned long ContactTime;// Timer to manage any contact bounce in interrupt routine

long lastcount;// Timer to manage any contact bounce in interrupt routine
float totalRainfall;// total amount of rainfall detected

void setup(){

lastcount = 0;
tipCount = 0;
totalRainfall = 0;

Serial.begin(9600);
Serial.println("Hydreon RG-11 Rain Sensor | cactus.io");
Serial.print("Bucket Size: "); Serial.print(Bucket_Size); Serial.println(" mm");

pinMode(RG11_pin, INPUT);
attachInterrupt(digitalPinToInterrupt(RG11_pin), rgisr, FALLING);
sei();// Enable Interrupts
}

void loop(){
// we only display the tip count when it has been incremented ny the sensor
cli();//Disable interrupts
if(tipCount != lastcount) {
lastcount = tipCount;
totalRainfall = tipCount * Bucket_Size;
Serial.print("Tip Count: "); Serial.print(tipCount);
Serial.print("\tTotal Rainfall: "); Serial.print(totalRainfall);
}

sei();//Enables interrupts
}

// Interrrupt handler routine that is triggered when the rg-11 detects rain
void rgisr() {

if((millis() - ContactTime) > 15 ) { // debounce of sensor signal
tipCount++;
ContactTime = millis();
}
}
// end of rg-11 rain detection interrupt handler

Sketch Console Output

Arduino Microchip MCP9808 Temperature Sensor Sketch

License