Weather Sensor

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Weather Sensor

#1 Post by Shardan » 23 Jun 2019, 17:06

Hello all,

as I had a working rain sensor already ( viewtopic.php?f=2&t=6540 )
it was self-evident to integrate the rain sensor into a weather sensor.
Another long pending project was integrated too: A lightning detector.

What's in the box:
- Temperature, Humidity, Air Pressure (BME280)
- Luminosity (TSL2561 Breakout)
- Rain Sensor
- Lightning Detection
Weatherstn.jpg (297.38 KiB) Viewed 14794 times
Weather Sensor Boards
The boards shown:
Top left: The sensor surface for the rain sensor, including heating and temperature sensor on backside.
Top right: The lightning detedtor.
Down: The main sensor board with the ESP-07S and the rain sensor.
Right: The small PCB for the BME280

The whole box needs a 9V power supply with at least around 1,5A.
I've successfully tested the box with Meanwell GS12E09-P1I (1,33A) and GST18E09 (2A).
As usual: Please avoid cheap power supplies!

Why is the lightning detoctor on a separate board?

The detector is based on an AM radio circuit to detect the electromagnetic pulses emitted by lightnings.
Some prototypes of the lightning detector including the ESP showed, that the ESP produces enough
electromagnetic waves to interfere with the lightning sensor.
The sensor should be placed away from all electric installation, switching power supplies and
devices with switching power supplies inside (says nearly any electronic device nowadays...).
So best solution is putting it into a sepoarate box and place it away from other devices and the sensor box.
Weatherstn - InBox_open.jpg
Weatherstn - InBox_open.jpg (213.58 KiB) Viewed 14794 times
Mounted into boxes
The pic showes the PCB's mounted into IP65 waterproof boxes.
You can see the heating resistors and the temperature sensor (DS18B20) on the back side of the rain sensor.
The TSL2561 was placed on a "long leg" female pin header to get it near the cover.
The small PCB inside the case is the antenna for the ESP, an external socket for a rubber antenna
can be used if necessary.

The BME280 PCB was placed into an external sensor shell that keeps water off.
It is not possible to use the DS18B20 for temperature metering as it gets heated from the
electronic and the sun shining on the rain sensor. So the DSB is in a separate shell to
place it in the shadow behind the sensor.

The rain sensor is a capacitive sensor. As i don't trust the UV resilience of the solder resist
the sensor surface was covered with an additional layer of PU varnish.
For functional description of the rain sensor see viewtopic.php?f=2&t=6540

As said the lightning sensor is based on an AM radio circuit TA7642. It provides a very simple AM radio.
I know there is a specialized "Franklin detector" chip on the market, the AS3935.
Why not using it? The chip itself is very difficult to handle with home soldering tools and badly availlable.
It would be possible to use a breakout board instead. Both solutions are expensive. On top they would need
a completely new plugin for ESPeasy... the library is somewhat big and following some forum posts it is
not really stable.
So another solution was searched and found. If you ever used an old medium or long wave radio while
a thunderstorm is around you might remember the loud "crackling" noise from the speaker caused
by lightnings. In a nutshell that's the basic principle of the sensor.
I've used a firmware based on the work of B. Kainka et al at and changed it
to use another ATTiny giving more IO's. So setting sensivity levels and reading some internal values
via RS232 is possible.
At startup the sensor rises the sensivity of the AM circuit until the noise floor from devices around
triggers the input of the ATtiny CPU. Then the sensivity is lowered to a value that allows detecting
the "crackles" from a thunderstorm.
Some tests with real thunderstorms around showed that lightnings in a distance of 25...30 km
are reliably detected. That's a nice radius as it makes no sense to close blinds automatically if
a thunderstorm is 100 km away. Anyways it can be set to higher sensivity with an ESP Programmer
and a terminal program, but that leads to very early warnings and possibly false positives.

The Attiny firmware does filtering to get rid of pulses from wall switches and other electric devices.
It counts pulses and accumulate the countings, decaying the value down slowly. So several
pulses within a given time have to occur to trigger the outpputs.

Known problems:

The sensor can't differ between a weak lightning nearby or a strong lightning far away.
The AS3935 is said to be able, but in real world that needs several exact timed sensors
in different places... makes things expensive and for home control it seems to be overkill.

Do not test the sensor in your office... Nowadays medim and long wavelengths are nearly out of use.
So no one notices the electromagnetic noises around. Try with a small AM radio near a wall plug type
power supply and other devices, you will see. It took me quite a while to find out why nothing worked
with testing samples on my desktop.....

Both the rain and lightning sensors have a three level output with "drizzle, rainy, wet" for rain
and "Far, near, danger" for lightnings. As the ESP-07S doesn't provide enough GPIO's a PCF8574
was used for these "slow" signals.

The BME280 and TSL2561 are standard sensors as usual.

Rules were used to get some things to work.
On boot both ATTinys are reset. A reset (Recalibrating the lightning senisvity) can be send
anytime with a short pulse on GPIO15, as it is done at ESP bootup.
Dummy variables are used to sum up some values. So if you don't need any single sensor output
just use one dummy variable giving rainlevel and lightning level in a value of 0 (nothing) to 3 (max).
Another rule drives the sensor heating. When idle it is usually switched off to save energy.
If the rain sensor surface gets wet heating is set on. Also it's set on if the temperature of
the surface drops below 10°C to avoid frost or snow freezing on the surface.
At higher temperatures in summer time the sensor surface can reach more then 40° easily.
In this case the heating will never start, makes not much sense then.

Additional GPIOs are broken out on my prototype so even more sensors could be added
(If the task list will expand over 12 tasks some day... :) ).

I've changed some things in the PCB layout since the prototype was made.
A diode was added to give reverse voltage protection.. Better a 0,02 EUR diode dies
then a whole board (Don't ask....). The ISP programming jumper (White pins down left on mainboard
has shown to be obsolete and was removed.

You may have noticed a missing part on top left on the man PCB.
In case the lightning sensor gets influences from the power supply a small buck converter
(B0505S) can be placed here isolating the lightning detector supply from the other circuit.
Up to now with two prototypes it wasn't necessary but who knows..

In future layouts one point will be changed... I'll make the ADC-input availlable too so
a "windmill" type wind speed sensor can be added too,

Seems it's nearly complete then :)

Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Weather Sensor

#2 Post by Shardan » 20 Jul 2019, 18:32

Some thundersturms later...

Now I can say that the thunderstorm detector as well as the rain sensor are working reliably.

User avatar
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden

Re: Weather Sensor

#3 Post by grovkillen » 20 Jul 2019, 21:44

Ah! Good stuff! Want one when you get to start selling ;)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop:
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: Weather Sensor

#4 Post by happytm » 05 Sep 2019, 02:15

Nice job.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 9 guests