AS3935 lightning detection using Arduino Uno

Teodor Costachioiu
Feb 10, 2015 · 3 min read

Some time ago I bought an AS3935 lightning sensor breakout board from Tindie. After some time I needed another sensor for a new project, only to find that it has been discontinued.

This article is more than two years old and might contain obsolete information; it is still kept here for informational purposes.

After some googling around I found the Thunder click board manufactured by the Mikroelektronika. The Thunder Click is a breakout board in the mikroBUS form factor, a standardized interface from Mikroelektronika. For the Arduino fans, there is an adapter shield that can accommodate two microBUS devices. Both the Thunder Click and the Click shield are also available from the EU distributor TME.

In this example, the Thunder Click is installed on socket #1 of the adapter shield. The PWR_SEL bridge was set to 5V (originally all mikroBUS boards come set for 3.3V operation). The pin configuration is:

AS3935 CS — Arduino D10
AS3935 MOSI — Arduino D11
AS3935 MISO — Arduino D12
AS3935 SCK — Arduino D13
AS3935 INT — Arduino D2 (INT). Note this corresponds to Interrupt #0

If the Socket #2 is used, the CS line connects to Arduino Pin D9, and the INT pin connects to Arduino pin D3, corresponding to Interrupt #1 (see http://arduino.cc/en/Reference/attachInterrupt for reference). Don’t forget to change the code to reflect the new pin settings.

The code is based on the original library written by Raivis Rengelis available at https://github.com/raivisr/AS3935-Arduino-Library with some modifications that are explained below:

First, I added a line to display the value of the calibration register if the calibration is successful.
Second, I moved all the code to display the events inside the interrupt routine itself. The main loop code just displays “Waiting” so I know that the system is not stuck. Now all I have to do is wait for a thunderstorm 🙂

https://gist.github.com/Electronza/efae0a14f592c880e532cfadc81eb27a

The output of this program looks like this:

Tuning cap register is 7
Noise floor is: 5
Spike rejection is: 2
Watchdog threshold is: 2
Waiting…
Noise level too high, try adjusting noise floor
Waiting…

Waiting…
Disturber detected
Waiting…
Disturber detected
Waiting…
Waiting…
Lightning detected 27 kilometers away.
Storm overhead, watch out!
Waiting…

From time to time the sensor reports “Noise level too high”. A possible workaround and future work is to count the number of noise warnings in a given amount of time, and dynamically adjust the noise level using AS3935.setNoiseFloor() function until a compromise between noise warnings and sensitivity is reached.

Update: Normally Arduino disables all interrupt sources during the ISR routine, this is why they recommend keeping the ISR routine short. Delay() also uses interrupts, and it seems that in very rare situations this causes Arduino to hang. For the moment I consider this as being a minor inconvenience, but I have to see what happens during a summer thunderstorm when tens of interrupts per second will occur.

Originally published at https://electronza.com on February 10, 2015. Moved to Medium on April 23, 2020.

Electronza

DIY electronics projects and more

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store