DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

Detecting Lightning with an Arduino


This post takes a look at interfacing the novel AS3935 lightning sensor with an Arduino.

The AS3935 works by detecting radio frequency emissions generated by lightning activity, and uses algorithms to distinguish these from man-made “disturbers” and to calculate the energy from strikes. From which it's able to then estimate the distance to the head of the storm over a 1–40km range.

The manufacturers, AMS, say that the AS3935 can be used “to protect both humans and equipment from harm by providing early warning of impending danger.” Suggesting that potential applications include use in hiking, at marine and sporting events, and with telecoms equipment, uninterruptible power supplies (UPS) and power conditioners etc.

Breakout board

The sensor is housed in a 4x4mm package and draws only 60uA in listening mode, and will issue an interrupt when lightning is detected and can be interfaced using I2C or SPI.

The compact MLPQ-16 packaging is great for building into an end user product, but is not particularly friendly for experimenters and prototyping with only access to simple tools. Fortunately, Tautic Electronics have produced a development board that includes the required antenna and passive components.

Arduino library

The comprehensive datasheet provided includes all the information required to write your own code to interface with the AS3935, but this has been made much easier for Arduino users thanks to a library from Raivis Rengelis. This includes functions for:

  • power up/down and reset

  • calibrating the antenna

  • getting/setting the noise floor

  • getting/setting the number of strikes before interrupt is raised

  • returning the source of the interrupt (noise, disturber or lightning)

  • returning the distance to the head of the storm

The library also comes with an example sketch.


The main loop for lightning detection is very simple and the output from running the sketch can be seen below.


Not surprisingly, this isn't particularly exciting. Nor will use of the sensor ever be unless a lightning storm is nearby!

Note that with Arduino boards other than a Mega 2560 it may be necessary to change some pin definitions. When using an Arduino Ethernet I chose to use pin 9 for SPI Chip Select since 10 is used by the Ethernet chip, and pin 2 was used for interrupts since this is int.0 on the board.

A useful design


Here in the UK we don't get lightning storms that often and for the best chance of catching one the detector really needs to be powered up 24/7.

In order to turn into a useful design I'll probably house the Arduino and shield in an enclosure so that I can forget about them without fear of damage. Using the example sketch to develop one that logs data to a platform such as Cosm, thereby enabling strikes and their intensity/distance to be graphed over time.

Andrew Back

Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.

14 Nov 2012, 10:47


February 16, 2014 23:01

Please can you help me?
When I try to run the code gives me the following:
'AS3935' does not name a type to
LightningDetector: 48: error: 'AS3935' does not name a type
LightningDetector.pde: In function 'void setup ()':
LightningDetector: 64: error: 'AS3935' was not declared in this scope
LightningDetector.pde: In function 'void loop ()':
LightningDetector: 102: error: 'AS3935' was not declared in this scope
LightningDetector.pde: In function 'void printAS3935Registers ()':
LightningDetector: 130: error: 'AS3935' was not declared in this scope
Can you help me?
Already used several versions of Arduino and the error is always the same

0 Votes

July 24, 2013 23:39

hi yall,

i will like to interfacing the IC AS3935 with the AT89C51AC2 from ATMEL using I2C BUS , could somebody help me with the Code ?

i'm not really into Programming.. and i really need some help.

thx in Advance


0 Votes

March 30, 2013 03:14

@aldebaran - I tried sending a message to you through the contact function here on designspark, but I'm not sure it is working. Sorry to hear of the trouble with the board - i'm more than happy to help please send me an email at jayson at tautic dot com with the detail you've collected on the issue. Best Regards, Jayson

0 Votes

March 8, 2013 20:37

Greetings everyone:
I purchased the The Franklin Lightning Sensor breakout board from these guys: ... sor-board/

As I wanted to use a PIC processor to control it, I wrote code to communicate with it using the compiler that came with my PIC development system. I chose the I2C interface as I ultimately intended to attach other sensors to that interface. I referred to all the data that I could find concerning the wiring, capabilities and protocol for that chip. That interface was rather difficult to understand from the confusing documentation provided by AMS. So I decided to use SPI as it is easier to debug via my logic analyzer. Tried everything but no luck. I checked all the wiring and power to make sure that it was correct and it was, so I don't believe that I have killed the chip.

I went looking for help and examples but all the code that I could find as an example is locked up in libraries. I wrote up the entire thing, complete with pictures of the wave forms and sent it of to the chip manufacture several weeks ago: ... sor/AS3935

No replies so far. So I tried to communicate with the tindie vendor of the breakout board and as far as I can find there is no way to communicate with them.

I am at an impasse at the moment as I cannot tell if I am doing something wrong, if the chip is dead or something else. Can anyone help on this?

Thanks in advance...

0 Votes

January 30, 2013 01:03

Just a note that Arduino UNO will work fine with the library and Tautic card.
With the USB UNO, I didn't have to change the library or example code. I just connected the pins as follows:

breakout pin arduino pin Uno

VDD 5V - Mega 2560
MOSI 51 11
MISO 50 12
SCLK 52 13
IRQ 2 2
CS 53 10

Then plugged it in and build & installed the example. Connected to it over USB serial and got the above mentioned output. I am in Florida, so plenty of lightning... even a chance of a storm in a day or two from now!

0 Votes

January 2, 2013 14:21


Do you think that is possible to use the AS3935 board with a arduino uno instead of a arduino mega ?

thank you very much.


0 Votes

November 16, 2012 18:03

link to AS3935 data -page Austria ... ing-Sensor

pdf manual can be downloaded. no free samples available from ams.
price per chip 3.55USD..

I consider to get one chip and make my own "breakout board" in conjunction
with Cypress PSoC3 Kit 030 , while i have no Arduino at hand.

greetz Markus

0 Votes

November 16, 2012 15:58

The link to the lightning board on tindie changed over night after an upgrade. You can now find them here: ... sor-board/

0 Votes