Hack a Rain Gauge - Project Stage 3

Initial Prototype

Home Basic Guides Projects Blog


The new reed switch needs to be in the same place as the old one.

I cut the 2 parts of this support from a sheet of perf board and secured them with hot glue.


As the replacement board is modelled on the old one it fits perfectly into the unit.


Once I was happy with the fit I fixed the reed switch to the board and soldered the hook-up wire in place.

The wires exit via the old battery compartment.


Here is the fritzing breadboard view.  

The ends of the reed switch are connected to Ground and Digital Pin 9.

So let’s get going a build a prototype

1 – Remove the existing electronic components – noting the position of the Reed switch.

2 – Make a replacement support to hold the Reed switch from perf board or similar.

3 – Solder the hook-up wire to the Reed switch and connect to the Arduino.

4 – Write / up-load the code and test the unit.

The code is given below alternatively download it from Github

Click here.   https://github.com/flowrc/Website-downloads/tree/master

The main thing to note is to activate the internal pull-up resistor on the INPUT pin for the Reed switch.  There are a number of ways of doing this.  For me the simplest is using the line of code


If you flip the bucket a couple of times you should see the counter in your serial monitor click-up, if not check the wiring.
Next Step


Arduino sketch to record the switching of the reed switch in the rain gauge

The sketch works by counting the number of times the reed switch changes status (HIGH or LOW)


const int REED = 9;              //The reed switch outputs to digital pin 9

int val = 0;                    //Current value of reed switch

int old_val = 0;                //Old value of reed switch

int REEDCOUNT = 0;              //This is the variable that hold the count of switching

void setup(){


 pinMode (REED, INPUT_PULLUP); //This activates the internal pull up resistor


void loop(){

 val = digitalRead(REED);      //Read the status of the Reed swtich

 if ((val == LOW) && (old_val == HIGH)){    //Check to see if the status has changed

   delay(10);                   // Delay put in to deal with any "bouncing" in the switch.

   REEDCOUNT = REEDCOUNT + 1;   //Add 1 to the count of bucket tips

   old_val = val;              //Make the old value equal to the current value

   Serial.print("Count = ");

   Serial.println(REEDCOUNT);  //Output the count to the serial monitor


 else {

   old_val = val;              //If the status hasn't changed then do nothing



© Flow RC June 2014

Disclaimer:  Flow RC cannot accept any liability for any mishaps that you may have if you attempt to copy these projects.  Please read our terms and conditions.

Please contact us at: feedback@flowrc.co.uk