Lightning Sensor Arduino Shield

How cool would it be to have a sensor that warns you of lightning strikes within a 40km radius?  Maybe you need to be alerted to unplug an antenna or sensitive electrical equipment.  Maybe you want to know when to bring the kids/pets inside.  The possibilities are really endless.  My goal was to connect it to my arduino powered weather station, and that is what I did.

Parts Needed:

Instructions:

The pinout mappings depend on what arduino board you are using and if you are using I2C or SPI.  You should match the pins accordingly to your board’s specs.

MOD-1016Uno R3Leonardo
VDD5v5v
GNDGNDGND
MOSI11 or ICSP-4ICSP-4
MISO12 or ICSP-1ICSP-1
SCLK13 or ICSP-3ICSP-3
IRQ2 or 33, 2, 0, 1, or 7
CS1010

Wire-up the sensor module to the proto shield and solder it all together.  You can do the wiring however you want but I ran the wires on the bottom.  Then solder the headers onto the proto shield.  It should look something like this:

EJK_5183EJK_5184

Code:

I’m utilizing the AS3935 arduino library HERE written by raivisr.  Keep in mind that technically this library was written for a different AS3935 breakout board, but since it’s the same chip it should be fine.  Also, they are using a Mega so their documentation has different pinouts.  Use the example included with the library to get started.  You will need to change the following bits of code to get it to work:

Change:

AS3935 AS3935(SPItransfer,SS,2);

To:

int PIN_IRQ = 2;  // Your IRQ pin, mine is 2
int PIN_CS  = 10; // Your sensor's CS pin, mine is 10
AS3935 AS3935(SPItransfer,PIN_CS,PIN_IRQ);

The attachInterrupt() function requires the interrupt ID for the pin you are using.  This table identifies the interrupt value and the associated Arduino pins:

BoardInt.0int.1int.2int.3int.4int.5
Uno R3, Ethernet23----
Leonardo32017-
Mega2321201918

 

Change:

attachInterrupt(1,AS3935Irq,RISING);

To:

int myIRQ = 0 // You need to change this to your IRQ
attachInterrupt(myIRQ,AS3935Irq,RISING);

Comment out the calibration function and add our custom tune function instead:

//if(!AS3935.calibrate())
// Serial.println("Tuning out of range, check your wiring, ...");

AS3935.tune(4);  // The number I used here (4) came on the packaging

Add the following function to the AS3935.cpp library file:

void AS3935::tune(int tuneValue)
{
 registerWrite(AS3935_TUN_CAP,tuneValue);
 delay(2);
 powerUp();
}

And add the following to the “public” class in the AS3935.h library file:

void tune(int tuneValue);

Testing:

It’s time to begin testing the serial output from the sensor.  Open your serial console window in the arduino IDE and see what’s going on.  You should see this:

serial-output

Extending Use:

Some other ideas for how to extend the use of this shield…

  • Hook it in to your personal weather station
  • Connect an LCD screen or LED matrix
  • Send a tweet

 

 

  1. Eric – if I read your website then I must have better things to do than wasting time trying to figure things out – thanks for providing the 1st really straightforward explanation of the as3935/aurduino interface. Does the Protoshield interface with the UNO? Does the Arduino IDE include a C++ runtime? If you could send me the URL’s on to answer these questions I would be grateful – I am Arduino illiterate. Thanks very much and have a good day.

    Rich

  2. BUT DOES IT WORK? ACTUALLY PICKUP REAL LIGHTNING?

  3. I’ve created a modified library for the MOD-1016 and Arduino UNO. Check it out: https://github.com/elZati/AS3935_MOD-1016/

    It is based on the raivisr’s library and modifications are made according to this blog. Note the readme file, to use this you need to change the board’s configuration to use SPI!

    Tested with Arduino UNO and yes it works.

  4. Hi, Why you use SPI on the MOD1016 but you don’t solder the pad on the board (Remove the soldering on the cs pad for example)

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>