Thundermon - A Lightning Detector

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Shardan
Normal user
Posts: 1105
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Thundermon - A Lightning Detector

#1 Post by Shardan » 23 May 2019, 20:43

There are some lightning detector chips on the market. Most used is the AS3935, which is a highly sensitive "Franklin detector".
The algorithm implemented into this chip allows for checking distances of lightnings, eliminating false positives etc.

So why making another, less exact lightning detector?

First, the AS3935 itself is badly availlable. I found one single dealer here who has it on stock.
Second, this chip is really expensive. Even ready made breakout boards start at 15 EUR at Ali.
Third, the chip is very small and difficult to solder so you will have to use a breakout board making cases more difficult.

Last but not least it needs a special function library. An algorithm for automatic calibration and some more
complex things are necessary. What I've found in several forums didn't look too well and has a lot of issues reported

I searched for other solutions and found some schematics based on a TA7642 - a super simple AM radio chip.
(See http://www.elektronik-labor.de/Projekte ... ner10.html)

If you ever used an oldfashioned AM radio while a thunderstorm is around you might remember the "crackling" sound every lightning
produces when listening. It's not difficult to detect these "crackles" using an ATtiny processor.

Another nice point is the small coil antenna used compared to "mighty" ferrite rods some examples use, this making smaller boxes possible.
I've tested a not too big ferrite rod too I got accidentally from a surplus dealer here in Germany. (See photo).
.
Thundermon_PCB.jpg
Thundermon_PCB.jpg (299.51 KiB) Viewed 4507 times
Thundermon boards with small coil antenna and with a ferrite rod antenna

It works on lower frequency, 139 kHz compared to 400kHz with the small coil. This rod makes the detector too sensitive so adapting
the firmware is necessary.
In general, lower frequencies give higher sensivities as the maximum field strength of lighnings is around 10 kHz.
The TA7642 limits the lowest frequency to around 100 kHz so 120..150 kHz is a good choice if you want high sensivity.
Anyways, for home control this doesn't make sense. Tests with the ferite rod shown in the picture allowed to detect
a thunderstorm at over 100 km distance - together with high sensivity to false pulses from the environment around.
Do you really want your home control take action, closing blinds for example, if a thunderstorm is 100 km away?

Anyways, due to first tests the 9 x 12 mm ferrite coil gives reliable results for a range of 20..30 km around.
That's a good value for home control so the following text focuses to the small antenna coil.

What this device can and can't do

This device is not able to detect exact distance reliably. A "fat" lightning far away and a weak lightning near by looks more or less same for this sensor.
The only criteria for distance is the number of pulses received as a near lightning causes more pulses getting through the trigger level.

Depending on sensivity settings it is able to detect thunderstorms on distances up to 25 km, maybe more.

The device counts lightning pulses. Depending on the counter, the time between pulses and number of pulses three levels (far,
near, danger) are shown using LEDs. Detection of pulses gives a 10ms flashing of the "Lightning" LED too.

How does it work?


The firmware is based on the work of Martin B., B. Kainka et al. at http://www.elektronik-labor.de
Many changes were made like adapting to another ATtiny type, serial sensivity setting, adapting for use with ESP and more.



The detector uses an ATtiny 2313A CPU. This chip is cheap and provides a lot of IO ports.

The sensivity of the TA7642 is determined by the Vcc voltage the chip is supplied with. So it is simple to control sensivity
of the detector using PWM and a low pass filter. This is done automatically after starting the detector.
While adjustment runs, the "Init" LED is lit.

Sensivity is raised step by step until the ATtiny is triggered by the "noise floor" we have around nowadays.
Then two sensivity level settings are calculated with 62,5% and 50% of the noise floor.

When idling the detector runs on the 62,5% level. If a certain number of pulses are counted the level goes down
to 50% so the sensor is not flooded by nearby lighnings giving better detection of far/near/danger levels..

The calculated sensivity levels are lowered by 10 by default to give a very low sensivity level basically.
Two eprom bytes keep a value of 10, they are added back to the values so we have the normal sensivity
level.

This looks confusing at first sight, doesn't it? Why subtracting and adding back?

Simple reason: It's easy to change the EPROM values to adjust sensivity to your needs.
This way no hassling with negative binary values or changing the binary itself is necessary.


****** Serial Setting is early alpha and not thoroughly tested yet! ******

Usually it should not be necessary to set other sensivity values.

Changing these values is done via a serial port on the board.
Serial send and receive can be switched on and off independently via jumper settings.

Use the programmers used for flashing the ESP together with a terminal program like HTerm or realterm by just sending two hexadecimal bytes to the serial port.

Be carefull, it's easy to make the receiver too sensitive, detecting the internal noise from the ATtiny or devices around permanently or on
the other side, make it deaf and detecting nearly nothing.

Default value is 10 (0x0A). It can be lowered to 0 making the device nearly completely deaf. It's possible to set values somewhat high, up
to vaues of 30 - this is definitely not recommended. A value of 20 (0x14) showed being the maximum level that can be used in areas with low
pollution from electric devices. That says it's already too high for most areas. Values above 30 are resetted to the default value by the firmware.

Always connect the programmer before starting serial setting!
The ATTiny will accept an open input setting the values at once to completely useless values.

Shorting the "En_Ser" pins for a moment start receiving from serial (2400Baud, 8n1). Two leds light up to show the "Receiving" state.
Now send two hexadecimal bytes (lower sensivity level first) with new values. LEDs show the "received" status, then a "stored" status for
0,5 seconds each. Then leds start blinking showing the device needs a reset now.
Your standard flash cable for the ESP does the job (level shifter built in).

The serial can be used to read the internal values from the circuit too. This is activated by plugging a jumper on the "En_Tx" pin headers.
Incomming pulses use interrupts, this would break the serial transfer. So interrupts are inactive while sending data. This makes the device slow
and it will miss pulses. This function should be used for diagnosis only!

Of course, setting sensivity with an ISP programmer is possible (and easier) using software like Atmel Studio, BasCom etc.
I assumed the ESP programmer is at hand so the serial setting part was included.

What does the firmware?

First step is adjusting sensivity as described above, then the detection loop starts running.

The pulse counter runs for 1000ms. If more then one pulse is detected, the counter value is added to a "level" variable.
A "decay" value is calculated from level and the "level" value is lowered by "decay" with every cycle.
This gives good suppression of false positives", pulses from swithing electric devices and such.
These false pulses are shown by a LED blink, but do not trigger the warning levels.

If the level raises above one of three defined thresholds the LEDs and outputs are driven dependently.
This way the detector gives the "far","near" and "danger" warnings.

By design it takes a while until the LED's step back to lower levels.

Why is no ESP-8266 on the board?

Generally it's possible, there is enough space left. I had a basically working prototype for testing - it does not work.
The ESP has a noticeable "noise floor" on this short distance of 2...3 cm. So the lightning detector will permanently
detect the ESP or auto calibration makes it completely "deaf" detecting nothing.

This is a general probem with this detector!

The detector must be placed away from ANY other device, mains power cabling etc. Even an ESP device on near distance
will collect too much false positives and trigger warn levels.

Medium and long wavelengths are nearly unused today and nobody notices the massive pollution of these frequencies comming
from all our daily used devices, power supplies, LED drivers etc.

It took me quite long time until I noticed that testing in my home office with many devices from computers and screens down to wall
plug type power supplies made any test completely useless, nothing worked out. You can check this with an oldfashioned radio
using AM (medium and long wave length). Inside your house you'll receive noise, noise and noise..

Just a hint for testing: Use batteries (3x 1.5V battery or 4x NiMH battery 1,2V) and go outside...
A good hint is the time the "Init" LED is lit. If it goes off after about a second or two, a too high noise floor is most likely. It can
take up to 10 seconds in a quiet area until the "Init" LED goes off.

The antenna direction must be adjusted a bit. It should be positioned in right angle to the direction thunderstorms arrive usually at your
place. and in a way it blanks out as much noise as possible. It's possible to tune down the antenna's frequency, on the
board a "Cx" capacitor pad is provided for that. 270...1000 pF are suitable values. Sometimes this might give better results.

The antenna coil is set on "long legs" intentionally so it can be bent into a sufficient position. (see photo).
.
Thundermon_Box.jpg
Thundermon_Box.jpg (188.69 KiB) Viewed 4507 times
.

Connecting to ESP

The detector has just one input: Reset. It can be used to trigger a reset from the ESP, usually with a pulse of 300...500 ms length.
This is usefull to recalibrate sensivity daily at a time of low noise floor, at 3am or 4am for example.
The reset is decoupled by a transistor, an ESP can drive it without issues with voltage levels.

The outputs are using transistors with "Open Collector" outputs so the voltage used here is independent from the 5V for the ATTiny.
All activity LEDs (Lightning, far, near, danger) have an equivalent open collector output on the pin header.
Simply use the standard "Switch" input of the ESPEasy settings.
As you have to use a cable of 1.5 m or more to get the lightning detector away from the ESP I'd prefer external pullup resistors
of 4.7K..10K over using internal pullup.

I've used a 2m shielded ethernet cable for testing. Make sure the shield itself is connected to ground only on one side!
The device needs about 10 mA with LED on (6.5mA idle) so the thin wires do not result in any issues.

The "Lightning" signal is optional. I'm using it for a small led in another box and for a (honestly quite useless) counter on the ESP.

Testing

Basic testing the device is easy. A piezo lighter next to the coil should give a "blink" of the "Lightning" LED.
I've made a very small PCB with an ATTiny giving a bundle of 10 pulses every second for triggering levels and such.

Anyways real testing needs a real thunderstorm. Luckily we had a thunderstorm these days here so I could run a real test on the device.
The "www.lightningmaps.org" real time lightning map was used as a reference showing the detector works. A thunderstorm 20 km away
was reliably detected with default sensivity setting shown as "Far", with the thunderstorm getting nearer, LEDs changed to "Near"
and "Danger" at last.

Future use
As the rain sensor shown in an earlier posting has shown to work quite well up to now I've created a weatherstation device integrating
luminoisty (TSL2561), a BME280 (Optional BMP180/280 and SI7021/SHT21 together) for humidity, temperature and air pressure
and the rain sensor shown in earlier posting here: viewtopic.php?f=2&t=6540
All parts are mounted together on one PCB in an IP65 box and a sintered metal capsule for the humidity/air pressure sensor(s).
On the PCB a connector for the Thundermon Lightning Sensor is implemented so it can be connected and placed at some distance
to the weatherstation.
Last edited by Shardan on 20 Jul 2019, 18:32, edited 2 times in total.
Regards
Shardan

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

Re: Thundermon - A Lightning Detector **EXPERIMENTAL*

#2 Post by grovkillen » 23 May 2019, 22:59

Truly amazing Shard! Love it.
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: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: Thundermon - A Lightning Detector **EXPERIMENTAL*

#3 Post by Shardan » 29 May 2019, 20:45

Update

Meanwhile the serial part is tested and working nicely.
Now I need some more thunderstorms.... :)
Regards
Shardan

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

Re: Thundermon - A Lightning Detector

#4 Post by Shardan » 20 Jul 2019, 18:33

Some thundersturms later...

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

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests