Brigadoon - An Occasional Corner on the Internet
Arduino Based Weather Station
Designed by Mark Little
When it is raining, the bucket may tip at any time, so if a computer is counting the bucket tips, as well as doing other activities such as reading other sensors or displaying results, the pulse from the bucket tip may be missed.
The most two most effective ways to ensure that a bucket tip is counted irrespective of the other functions being processed is to use a hardware counter or an interrupt to count the bucket tips.
Such an interrupt uses the hardware to detect the bucket tipping event and then forces a change to the current execution of the software. As a result, the interrupt code should be short to prevent unintended consequences to other functions.
Counting Bucket Tips Using An Interrupt
An External Interrupt is activated by the external pin INTn if the registers are set correctly. The interrupt can be configured in a number of ways to more appropriately detect a change on the pin. For example, a rising or falling edge, or a low level.
All the interrupt needs to do is increment a long integer counter and return, so the overhead of the operation is very low. This makes it the preferred option of the tipping rain gauge. The typical code for the interrupt call would be:
volatile long int rainfall_total;
const byte rainfall_pin = 2;
// Interrupt Routine
// Initial Set-Up Code
// Enable the Internal Pull-Up Resistor on Pin connected to Rain Gauge
// Set the Interrupt for the Tipping Bucket Rain Gauge Pulses
attachInterrupt(digitalPinToInterrupt(rainfall_pin), IncrementRain, FALLING);
// Main Program Loop
// put your main code here, to run repeatedly: