I need could need some help/advice to get my rain gauge to show correct values, as per today my rain gauge shows to low values. The rain gauge that I use is this one: Rain gauge
I use Domoticz V 3.8153 with Mysensors V2.1.1 and have bucket size 0,3. Anyone that have experience with this rain gauge and what bucket size to use for correct values or is there something with my code that creates problems?
This it my sketch that I am usning:
// Enable and select radio type attached
#define MY_RADIO_NRF24
#define MY_NODE_ID 5
#include "ThresholdUtil.h"
#include <math.h>
#include <Time.h>
#include <MySensors.h>
#include "DHT.h"
#include <Wire.h>
DHT dht;
#define DHT 0
#define BUCKET_PIN 3 // The Arduino pin to which the bucket is attached. We need an interrupt pin (2 or 3 on the Uno and the Pro Mini)
#define SKETCH_INFO "Rain,Temp&Hum" // The name of the sketch as presented to the gateway
#define SKETCH_VERSION "1.0" // The version of the sketch as presented to the gateway
#define CHILD_ID_RAIN_LOG 4 // The child id of the rain gauge
#define MS_WAIT 100 // short delay used to give the NRF24L01+ antenna some time to recover from the last data sending
#define bucketSize 0.3 // I've used a MI-SOL Rain Guage which has a bucket size of 0.3 mm
#define CHILD_ID_TEMP 5
#define DHT_TEMP 6
#define CHILD_ID_HUMIDITY 7
#define DHT_HUM 9
#define DHT_DATA_PIN 5
MyMessage msgHum( CHILD_ID_HUMIDITY, V_HUM );
MyMessage msgTemp( CHILD_ID_TEMP, V_TEMP );
MyMessage msgRain( CHILD_ID_RAIN_LOG, V_RAIN );
MyMessage lastCounterMsg( CHILD_ID_RAIN_LOG, V_VAR1 );
float hwRainVolume = 0; // Current rainvolume calculated in hardware.
unsigned long hwPulseCounter = 0; // Pulsecount recieved from GW
boolean pcReceived = false; // If we have recieved the pulscount from GW or not
unsigned long lastTipTime = millis(); // TS of when the bucket tip has been detected for the last time
volatile unsigned long wasTippedCounter; // Queue for storing the tipped counter as been set by the interrupt handler.
byte lastHour; // Stores the hour used for checking if time needs to be synchronized
void presentation() {
// Send the sketch version information to the gateway
sendSketchInfo( SKETCH_INFO, SKETCH_VERSION );
wait( MS_WAIT );
present( CHILD_ID_HUMIDITY, S_HUM, "Outside Humidity" );
wait( MS_WAIT );
present( CHILD_ID_TEMP, S_TEMP, "Outside Temperature" );
wait( MS_WAIT );
present( CHILD_ID_RAIN_LOG, S_RAIN, "Rain fall" );
wait( MS_WAIT );
unsigned long functionTimeout = millis();
while ( pcReceived == false && millis() - functionTimeout < 30000UL ) {
request( CHILD_ID_RAIN_LOG, V_VAR1);
Serial.println(F("Getting pulse count"));
Serial.println(F("."));
wait( 1000 );
}
attachInterrupt( digitalPinToInterrupt( BUCKET_PIN ), sensorTipped, LOW ); //FALLING ); // depending on location of the hall effect sensor may need CHANGE, LOW or HIGE
}
void setup() {
Serial.begin( 115200 );
pinMode( BUCKET_PIN, INPUT_PULLUP );
registerThresholdedSensor( CHILD_ID_TEMP, DHT_TEMP, TEMPERATURE_SENSOR, 0.5, 60, 8 ); // Change of value +/-0,5 , every 60 seconds report, and force report every 8 minutes
registerThresholdedSensor( CHILD_ID_HUMIDITY, DHT_HUM, HUMIDTY_SENSOR, 1.0, 60, 8 ); // Change of value +/- 1, every 60 seconds report, and force report every 8 minutes
dht.setup( DHT_DATA_PIN ); // data pin 8
delay( dht.getMinimumSamplingPeriod() );
unsigned long functionTimeout = millis();
while ( timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL ) {
requestTime();
Serial.println(F("Getting Time"));
Serial.println(F("."));
wait( 1000 );
}
lastHour = hour();
}
/**
Sends the value of the rain gauge to the Gateway.
*/
void sendRainVolumeData() {
float hwRainVolume = hwPulseCounter * bucketSize;
Serial.print( "Tipped " );
Serial.print( hwPulseCounter );
Serial.println( " times." );
Serial.print( "Rain fall is " );
Serial.print( hwRainVolume, 1 );
Serial.println( " mm." );
send( msgRain.set( (float)hwRainVolume, 1 ) );
wait( MS_WAIT );
send( lastCounterMsg.set( hwPulseCounter ) );
wait( MS_WAIT );
}
void loop() {
if ( wasTippedCounter != hwPulseCounter ) {
hwPulseCounter = wasTippedCounter;
sendRainVolumeData();
}
byte currentHour = hour();
if (currentHour != lastHour) {
Serial.println( "Resyncing hour" );
requestTime(); // sync the time every hour
wait( MS_WAIT );
lastHour = currentHour;
sendRainVolumeData(); // Send heart beat
}
checkThresholdedSensors( readSensorValue, updatedSensorValue );
}
void sensorTipped() {
unsigned long thisTipTime = millis();
if (thisTipTime - lastTipTime > 100UL) {
wasTippedCounter++;
}
lastTipTime = thisTipTime;
}
float dhtHumidity;
void readSensorValue( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ) {
switch ( aSensorId ) {
case DHT_TEMP:
if ( aType == TEMPERATURE_SENSOR ) {
*value = dht.getTemperature();
}
break;
case DHT_HUM:
if ( aType == HUMIDTY_SENSOR ) {
*value = dht.getHumidity();
}
break;
}
}
void updatedSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) {
switch ( child_id ) {
case CHILD_ID_TEMP:
Serial.print( "Temperatur " );
Serial.print( value, 0 );
Serial.print( "C" );
send( msgTemp.set( value, 1 ) );
wait( MS_WAIT );
break;
case CHILD_ID_HUMIDITY:
Serial.print( "HUMIDITY " );
Serial.print( value, 0 );
Serial.print( "%" );
send( msgHum.set( value, 1 ) );
wait( MS_WAIT );
break;
}
}
void receiveTime(unsigned long time) {
Serial.println( F("Time received..."));
setTime(time);
char theTime[6];
sprintf(theTime, "%d:%2d", hour(), minute());
Serial.println(theTime);
}
void receive(const MyMessage &message) {
if ( message.sensor == CHILD_ID_RAIN_LOG && message.type == V_VAR1) { // We only expect pulse count values from the gateway
hwPulseCounter = message.getULong();
wasTippedCounter = hwPulseCounter;
pcReceived = true;
Serial.print("Received last pulse count from gw: ");
Serial.println(hwPulseCounter);
}
}