Tipping bucket rain gauge -> Pulse counter

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
JR01
Normal user
Posts: 241
Joined: 14 Feb 2016, 21:04
Location: South Africa
Contact:

Tipping bucket rain gauge -> Pulse counter

#1 Post by JR01 » 21 Mar 2016, 20:13

Hi, I bought a tipping bucket rain gauge from eBay, see link a) below. After studying the web for designs, some comes up for Arduino, but only one for esp8266, and none using the pulse counter. Benlo has a project, see link b) below, but it is not with the pulse counter, I am using his idea for a onto coupler, but cannot get counting to work with it.

/attachment removed - and corrected to show correct circuit, see post further down with correct circuit.../

When I rock the tipping bucket, and measure the volts before I connect to GPIO2, I get zero volts normal, and spiking 2.x volts as the tipping bucket engages the reed switch with the magnet passing over it. But if I attach GPIO2, and measure from same point to GND, I get about 3.12v, jumping to 3.2 volts as the tipping bucket engages the reed switch.

Q1: Do you think this application will work for pulse counter on ESP Easy?
Q2: What do you think I am doing wrong?

a) eBay tipping bucket: http://www.ebay.com/itm/1-unit-Spare-pa ... SwfZ1WanMB
b) Benlo project: http://benlo.com/esp8266/esp8266Projects.html#rain
Last edited by JR01 on 23 Mar 2016, 06:29, edited 4 times in total.
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay . Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rai gauge -> Pulse counter

#2 Post by Drum » 22 Mar 2016, 15:46

I am not an EE but the first thing I can see when comparing the 2 schematics, it appears you have pins 4 and 5 reversed on the optocoupler and It appears you have 3.3 V flowing to GPIO2 where the original schematic shows the GPIO flowing to Ground (arrows in the optocoupler) from the original write up. "The ESP8266 is programmed to fire an interrupt when the GPIO input transitions from high to low."

I would try putting pin 5 in your schematic to GPIO2 and Pin 4 to ground, as in the original schematic, but I don't know how ESPEasy is configured to count pulses. More changes may be necessary.

It may be possible to change the pin settings to work the way you have it in the schematic, in the "hardware" page, but I do not know. I believe the default state for GPIO2 is pulled high via internal pullup, which may be what you are seeing on your meter, and it goes up when you trigger as it appears you are sending 3.3v through.

JR01
Normal user
Posts: 241
Joined: 14 Feb 2016, 21:04
Location: South Africa
Contact:

Re: Tipping bucket rain gauge -> Pulse counter

#3 Post by JR01 » 22 Mar 2016, 19:43

Drum wrote:I would try putting pin 5 in your schematic to GPIO2 and Pin 4 to ground
This worked! Thank you. (missed that one....)
So, below is the corrected circuit for anybody looking for similar design. I set this up with MQTT, which send the counts out every 5min of rain 'tips' measured, then in node-red on RaspberryPi I catch the message, multiply the counts with 0.2794 to bring it to mm's of rain, then send off the mm's rained in that reported period to Thingspeak, works great!
Rain gauge tipping bucket sensor with optocoupler for ESP8266.png
Rain gauge tipping bucket sensor with optocoupler for ESP8266.png (119.54 KiB) Viewed 11013 times
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay . Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#4 Post by Drum » 29 Mar 2016, 11:35

Thank you! This has been on my list since I started with ESP8266, but knowing someone has been able to make it work in ESPeasy is reason enough to order parts.
Now I just need to get MQTT and Node Red working.

Unfortunately work keeps getting in the way of the fun stuff...
;)

adrianmihalko
Normal user
Posts: 51
Joined: 15 Sep 2016, 00:20

Re: Tipping bucket rain gauge -> Pulse counter

#5 Post by adrianmihalko » 06 Nov 2016, 23:11

It would be great to run from batteries. Anybody did thing like this? How long can it run from batteries?

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#6 Post by Drum » 07 Nov 2016, 03:13

With 4 AA batteries I can get 3 to 4 days without using deep sleep with other sensors. I have not tried on this setup because deep sleep is not possible. The current plan is to power it from a wallwart with a good sized battery backup. You could do solar if you need it to, but it would need a larger battery and solar panel depending on where you live. Winter is pretty rainy, so trying to get enough power out of cloudy skies to keep it running 24/7 is difficult.

meaple
Normal user
Posts: 1
Joined: 15 Feb 2017, 12:17

Re: Tipping bucket rain gauge -> Pulse counter

#7 Post by meaple » 15 Feb 2017, 12:22

Hi, I know that this is quite old thread. I was wondering what optocoupler could be used (I know it says EL4N25 417) but I'm struggling to find/buy one.
I'm not electronical engineer, so not sure.

for future reference how to choose correct optocoupler for simple solutions similar to this? What I need to look for etc.

Can ie EL4N25 229 or 949 replace 417?

JR01
Normal user
Posts: 241
Joined: 14 Feb 2016, 21:04
Location: South Africa
Contact:

Re: Tipping bucket rain gauge -> Pulse counter

#8 Post by JR01 » 15 Feb 2017, 17:27

Was trying to find specs on the 229, but could not find (quick search). Could you source / send a link to the spec sheet ?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay . Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#9 Post by whatsupskip » 02 Mar 2018, 06:46

adrianmihalko wrote:
06 Nov 2016, 23:11
It would be great to run from batteries. Anybody did thing like this? How long can it run from batteries?
The only practical way to run this off batteries would with another very low power microcontroller that stays on all the time to do the counting. Then once every minute or longer the better, the ESP8266 wakes up, collects the count and sends the data.

JR01
Normal user
Posts: 241
Joined: 14 Feb 2016, 21:04
Location: South Africa
Contact:

Re: Tipping bucket rain gauge -> Pulse counter

#10 Post by JR01 » 02 Mar 2018, 20:03

Something like an stm32 arm cortex, or is that too large aleady?
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay . Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#11 Post by whatsupskip » 05 Mar 2018, 00:04

I have been thinking about this circuit a bit more. I don't really see why there needs to be an opto isolator. Sure it provides a level of protection, but it is supposed to be providing protection from induced voltage/current from the magnet moving past the reed switch. Now I haven't put a oscilloscope across the bucket to test it, but I would have though the currents induced would be very small. Think about it, it only loop of wire and the weak magnet is only moving past it slowly. Also given how the loop is wired, I think it is largely going to cancel the current out.

I need to do some more testing with my bucket and the configuration of ESP Easy to see if I have it working correctly.

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#12 Post by whatsupskip » 05 Mar 2018, 11:12

OK, I believe I have made some progress with this. It appears to be working with the following settings:

Circuit: Reed switch (bucket wire) between ground and D5. (Should work for many other GPIO)

ESP Easy Firmware settings:
Version: 2.0-20180227 (Dev)
Device: Generic Pulse Counter
Name: Rain
Enabled: Yes

Sensor
1st GPIO: GPIO-14 (D5)
Debounce (msec): 150 (250ms may be too long for heavy rain)
Counter Type: Delta
Mode Type: Change

I haven't yet understood what the "Time" value is, but it is irrelevant for my set up.

Now has anyone actually have a definitive answer for the volume per count of the generic rain bucket?
I have seen differing values 0.279mm and 0.1 inches (which would be 0.254mm). I had previously estimated it to be 0.3mm.
I suspect I will have to determine it from the actual formula.

tage
Normal user
Posts: 3
Joined: 28 Apr 2018, 20:36

Re: Tipping bucket rain gauge -> Pulse counter

#13 Post by tage » 28 Apr 2018, 20:47

Hi.
I have connect one rain gauge to my wemos D1 and use generic pulse counter but im wondering how you guys do when need to reboot or if the esp lost power and reboot by it self.
All values are back to zero and that is no good for virtual rain sensor in domoticz .
Usual the 433mhz weather station comes back up as a new device and possible to replace the old one but with this it keep sending value to the same virtual rain sensor in domoticz.

/ tage

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#14 Post by whatsupskip » 28 Apr 2018, 23:34

I normally save to a database via NodeRed or EMONCMS.

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#15 Post by Drum » 29 Apr 2018, 10:30

I am using adafruit feather boards for things which need to run all the time. They are small and have a good lipo system integrated. They also have a good variety of add-on boards I can order from mouser for less than amazon. They are a little more expensive but I have never had problems with adafruit designed products. Right now I am playing with a 2.4 inch 320 x 240 tft touchscreen and waiting for the 3.5 inch version to be shipped.

What temp/humitity sensor are you using? I have not been able to find one that will not corrode from the condensation. Even after coating the board the sensors just do not last more than a few months. :cry:

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#16 Post by whatsupskip » 29 Apr 2018, 23:54

Drum wrote:
29 Apr 2018, 10:30
What temp/humidity sensor are you using? I have not been able to find one that will not corrode from the condensation. Even after coating the board the sensors just do not last more than a few months. :cry:
What sort of enclosure are housing the sensors in?

What sort of climate are your sensors in? (I assume quite humid)

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#17 Post by Drum » 30 Apr 2018, 15:57

whatsupskip wrote:
29 Apr 2018, 23:54

What sort of enclosure are housing the sensors in?

What sort of climate are your sensors in? (I assume quite humid)
They are outside, inside a small plastic bottle with 2 small holes for some air flow, which is inside a plastic solar shield which is about 2 meters above the ground in my garden. In live just outside Siena, Italy and we do see a fair amount of fog and dew, but the cheap 433mhz temp and humidity outdoor sending unit which was in the same area had no problems at all. It has far more holes, which are larger and closer to the sensor and circuit board. The sensor on that looks like a SHT11 or something like it. It does not have any markings.

I am going to order some SHT11 sensors to see if they do any better. I also have a problem with Ikea solar lights, some (silver and white candle like things) are pretty well sealed from water (rain) but not humidity and they have rust issues on the switch and eventually the legs on the LEDs. But at 7 euro each you can't really expect them to last forever.

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#18 Post by whatsupskip » 01 May 2018, 00:32

Drum wrote:
29 Apr 2018, 10:30
Even after coating the board the sensors just do not last more than a few months. :cry:
What have you been coating the sensor boards with?

I wonder if it is the connectors under the sensor that are actually corroding rather than the sensor itself failing.

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#19 Post by Drum » 01 May 2018, 12:28

Hard to say exactly what the coating is I can check the bottle but it is supposed to be a conformational coating.

I need to lok at the board again but it is a bmp280 which is not rated for 100% humidity which I think I am getting when dropping air temps cause condensation.

tage
Normal user
Posts: 3
Joined: 28 Apr 2018, 20:36

Re: Tipping bucket rain gauge -> Pulse counter

#20 Post by tage » 13 May 2018, 13:33

the counter is not working good. it is counting even if no rain. My guess is the cable is to long and make noises or something (5 meters).
i have try to put it as a switch and that seems to work (on/off) but then i loose the counter and need to find a way to make it count and put it in domoticz..

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#21 Post by Drum » 14 May 2018, 10:49

Can you post a schematic? I suspect a short or maybe wind tripping it, but without knowing more it is impossible to know. The Optocupler should eliminate any noise issue I would think. It takes more than a little noise to trigger it, it takes 5V. Someone with more electrical engineering experience could tell you if noise could make it look like it is pulling it to ground, I have some doubts but I am not an EE.

I have tested this using a generic rain bucket without the optocupler, but only only indoors with very short cables, mostly for configuring Node-red and database. Never had any problems.

I have never seen an explanation for the optocupler, protection or noise, but I suspect it is there for a reason. Someone said they could not find one. The 4N25 (EL is probably the manufacturer) is available, Mouser has several, I expect Digi-key does as well. It also comes up on aliexpress and e-bay, although they are not as reliable in my experience. Just check the data sheets and make sure the specs are what you need.

tage
Normal user
Posts: 3
Joined: 28 Apr 2018, 20:36

Re: Tipping bucket rain gauge -> Pulse counter

#22 Post by tage » 14 May 2018, 13:54

there is not mutch schematic. Between ground and gpio 0 (d8 on wemos d1)
Generic - Pulse counter, counter type : delta/total, mode type : rising.
tried diffrent Debounce Time (mSec): but cant find any diffrent. right now it is set to 5000 .
i have also try to set it as Switch input - Switch and when use that it never got strange activity only shows when the bucket it tipping.

Drum
Normal user
Posts: 296
Joined: 07 Feb 2016, 11:56

Re: Tipping bucket rain gauge -> Pulse counter

#23 Post by Drum » 14 May 2018, 15:09

If I understand correctly, you have a 15 meter wire from a GPIO on the wemos going to the rain bucket and another from the other terminal on the rain bucket to wemos ground?

Which rain bucket are you using?

1. GPIO 0 is used for programming so probably not a good idea to use for this application. Try GPIO 12, 13 or 14 they do not have any internal use.
2. Check the Hardware tab for the GPIO you use. I am not sure how it should be set, but try different settings to see what works best.
3. Using an optocupular next to the ESP essentially takes the 30 meters away. You can use the 5V from the wemos power to drive the rain bucket/optocupler loop (see schematic earlier in the thread).

Starting with what has been tested and works is generally a good place to start. ;)

Zodiac69
Normal user
Posts: 34
Joined: 13 Jun 2016, 17:20

Re: Tipping bucket rain gauge -> Pulse counter

#24 Post by Zodiac69 » 25 Jul 2018, 10:00

You could just use a DS2423 as a counter and get ESPEasy to wake up every x min. to read the counter.
Battery backed and low power.
https://www.maximintegrated.com/en/prod ... S2423.html

Zodiac69
Normal user
Posts: 34
Joined: 13 Jun 2016, 17:20

Re: Tipping bucket rain gauge -> Pulse counter

#25 Post by Zodiac69 » 15 Aug 2018, 15:49

As the DS2423 is no longer manufactured, you can follow this link and make your own 1-Wire device.
Here is the source code on a DS2423 "Clone" - https://www.tm3d.de/elektronik-projekte ... it-avr-alt

It is in German, but i am sure you can use Goole translate and get the hang of it.

Vic20
Normal user
Posts: 18
Joined: 29 May 2018, 11:51

Re: Tipping bucket rain gauge -> Pulse counter

#26 Post by Vic20 » 27 Aug 2018, 20:26

With a similar challenge to the OP, I thought I'd pick up on this thread.

I plan to use a good old CMOS Binary counter to count the bucket tips while the ESP8266 sleeps. The CD4520 is my chosen device which has a quiescent current drain of just 2.5uA.

With a small RC debounce circuit on the reed switch actuated Clock input, here's my proving prototype for this plan in action...

https://youtu.be/XmtVZqeBoqc

I plan to have the binary count (5 or six bits should be sufficient for anything up to a monsoon over 10 minutes) read by a PCF8574 I/O expander. Then (and this is the bit I am currently a little unsure of) in ESP Easy, read each 'bit' as a switch and calculate the count within a rule (1's plus 2's plus 4's plus 8's etc) Unless there's a simpler way!? When this is gathered and sent to the controller (thingspeak initially) a spare I/O on the expander can be sent high to reset the counter prior to the ESP going to sleep.

I have cut down an 8266/32 double sided breadboard to match the board that fits inside the rain gauge and added the reed switch in the same relative position...

Image
(This is the reverse side)

I reckon, with SMD passives, I can get all the components on this board along with a TP4056 Solar charge control board to fit everything including a LIPO battery inside the rain gauge with a Solar panel outside to make it an all in one standalone device. There looks like there is also enough room at the fat end of the PCB housing to fit a BME280 Pressure/Temp/Humidity sensor in there also to complete a full (ish) weather station!

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Tipping bucket rain gauge -> Pulse counter

#27 Post by toffel969 » 29 Aug 2018, 09:57

Vic20 wrote:
27 Aug 2018, 20:26
With a similar challenge to the OP, I thought I'd pick up on this thread.

I plan to use a good old CMOS Binary counter to count the bucket tips while the ESP8266 sleeps. The CD4520 is my chosen device which has a quiescent current drain of just 2.5uA.

With a small RC debounce circuit on the reed switch actuated Clock input, here's my proving prototype for this plan in action...

https://youtu.be/XmtVZqeBoqc

I plan to have the binary count (5 or six bits should be sufficient for anything up to a monsoon over 10 minutes) read by a PCF8574 I/O expander. Then (and this is the bit I am currently a little unsure of) in ESP Easy, read each 'bit' as a switch and calculate the count within a rule (1's plus 2's plus 4's plus 8's etc) Unless there's a simpler way!? When this is gathered and sent to the controller (thingspeak initially) a spare I/O on the expander can be sent high to reset the counter prior to the ESP going to sleep.

I have cut down an 8266/32 double sided breadboard to match the board that fits inside the rain gauge and added the reed switch in the same relative position...

Image
(This is the reverse side)

I reckon, with SMD passives, I can get all the components on this board along with a TP4056 Solar charge control board to fit everything including a LIPO battery inside the rain gauge with a Solar panel outside to make it an all in one standalone device. There looks like there is also enough room at the fat end of the PCB housing to fit a BME280 Pressure/Temp/Humidity sensor in there also to complete a full (ish) weather station!
Have you thought of using a Attiny?
Let the Attiny do the counting and use serial communication to set a Dummy device in ESP Easy. I think you could then also make the ESP sleep and only wake it before serial communication. You can only send commands from Attiny to ESP, not the other way round, but that shouldnt be required for your project
http://www.ernstc.dk/arduino/tinycom.html
https://arduino.stackexchange.com/quest ... lock-speed

I think your approach is difficult to achieve in ESP Easy. You would either need to write your own plugin, or try to write the 8 bits into 2xQuadruple Dummy devices, then use rules to do the calculation.
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Vic20
Normal user
Posts: 18
Joined: 29 May 2018, 11:51

Re: Tipping bucket rain gauge -> Pulse counter

#28 Post by Vic20 » 29 Aug 2018, 15:08

Have you thought of using a Attiny?
Never heard of it to be honest! Quite a lot thirstier in current consumption by the looks of it too..And another learning curve!

If this current design doesn't work under ESP-Easy then it'll be back to using C under the Arduino IDE!

whatsupskip
Normal user
Posts: 98
Joined: 28 Feb 2018, 07:40

Re: Tipping bucket rain gauge -> Pulse counter

#29 Post by whatsupskip » 30 Aug 2018, 23:58

Vic20 wrote:
27 Aug 2018, 20:26
There looks like there is also enough room at the fat end of the PCB housing to fit a BME280 Pressure/Temp/Humidity sensor in there also to complete a full (ish) weather station!
Nice concept except any temperature/humidity sensor will need significant shading to be at all accurate when the sun is out. This of course doesn't go well with the whole rain gauge structure.

Also I would be a bit concerned about building all the advanced circuit you have proposed without testing along the way.

Also be careful with charging batteries where they might become hot from solar radiation. Depends on your climate, but direct sunlight is very strong where I live.

Vic20
Normal user
Posts: 18
Joined: 29 May 2018, 11:51

Re: Tipping bucket rain gauge -> Pulse counter

#30 Post by Vic20 » 02 Sep 2018, 01:54

Hi Whatsupskip,

Construction is well under way. I've phased this so that testng can be done as it progresses. First the mount pins for the charger board and the 3.3v LDO regulator and capacitors beneath. The whole power supply side can then be tested first
IMG_20180901_142142.jpg
IMG_20180901_142142.jpg (63.57 KiB) Viewed 5738 times
There's also the resistor bridge across the battery pins for monitoring the voltage on the ADC
IMG_20180901_142115.jpg
IMG_20180901_142115.jpg (129.62 KiB) Viewed 5738 times

Next, I wired the supply rails and installed the IC's , I was able to check the counter IC was working correctly. I then linked all the count outputs to the PCF8574 inputs. The BME was then placed on some pins and I have taken out the I2C lines to be read on a Nodemcu, thus able to check a large majority of the circuit without even installing an ESP on the breadboard yet!
IMG_20180901_142040.jpg
IMG_20180901_142040.jpg (84.49 KiB) Viewed 5738 times
IMG_20180901_121434.jpg
IMG_20180901_121434.jpg (147.37 KiB) Viewed 5738 times


Not looking too bad eh? Yes I get your point about the temperatures and humidity will, though useful for internal status need to be disregarded when the sun is out but they'll be fine in the rain and I only really need the pressure reading anyway. There's plenty of free GPIOs for the option to hang a DSB18B20 out of the unit.

The counter and I/O expander all seems to be working.
Capture.JPG
Capture.JPG (121.04 KiB) Viewed 5738 times
I'll cover the Devices and Rule in a later post. I'll plan to use a high pulsing GPIO on the ESP to reset the CD4520 before the ESP goes to sleep (hopefully after a succesful thingspeak controller update if that's possible so no counts are lost)


As for the battery getting hot, I'll ensure that side will be largely shielded by the solar panel. There is natural ventilation inside the unit and I'll probably paint it white to protect it from UV anyway. It's not a production unit after all!

Vic20
Normal user
Posts: 18
Joined: 29 May 2018, 11:51

Re: Tipping bucket rain gauge -> Pulse counter

#31 Post by Vic20 » 14 Oct 2018, 16:51

Update: Due to THIS problem I could not use ESP-Easy to continue my project until that was resolved unfortunately.

I therefore decided to use the Arduino IDE and C++ to get it working...

On Wake of the ESP, A "pcf8574.read8()" instruction reads in the count from the Binary counter as decimal which I can multiply by the bucket volume to get the amount of rain over the ten minute period that the ESP was asleep.

The unit sends it's data to Thingspeak and returns to sleep in around ten seconds. A mathworks routine in Thingspeak produces another chart of total rain over the last 24 hours.

It has ran uninterrupted for over a week now on an ex nokia BL5 battery core and a small 6v Solar panel.

I will also get it to send me a Telegram message when it is 'Chucking it down' , a rain rate over a pre defined amount in 10 mins to be determined from evaluation ..just for fun.

ESP-Easy just wasn't that Easy ...though I do miss the ease of reconfiguration/reprogramming that brings.



Capture.JPG
Capture.JPG (18.68 KiB) Viewed 5167 times

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests