AS3935 Lightning Sensor

Hello Forum,

Has anyone here successfully used one of these lightning detectors? I've been playing with this for a while and set one up in the hopes of catching a few lightning strikes, but my setup goes through a wild electrical storm right overhead without reporting anything. If anyone out there have managed to get one of these working, I could use a tip or two.

There seems to be a number of different models out there, but most of them use the AS3935 chip. I have this one:

I have it connected to an UNO with the following connections:

  • 5V -> VCC
  • GND -> GND
  • SCL -> SCL
  • MOSI -> SDA
  • SI -> 5V (to force I2C)
  • IRQ -> 2
  • EN_V -> 5V
  • A0 -> 5V
  • A1 -> GND (forces address of 0x01)

This is the code I'm using:

#include <avr/wdt.h>
#include <SPI.h>
#include <Wire.h>
#include "SparkFun_AS3935.h"

#define AS3935_ADDR 0x01
#define INDOOR 0x12 
#define OUTDOOR 0xE
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
#define NOISE_INT 0x01

 SparkFun_AS3935 lightning(AS3935_ADDR);
// SparkFun_AS3935 lightning;


const int STRIKEINT = 2; 

int tries = 0;

long lastRestart, lastTest;

boolean failed = false;

byte noiseFloor = 2;
byte watchDogVal = 2;
byte spike = 2;
byte lightningThresh = 1; 
byte intVal = 0; 
byte distance;

void setup()
{
  wdt_enable(WDTO_2S);
  Wire.begin();
  pinMode(STRIKEINT, INPUT); 
  Serial.begin(19200); 
  Serial.println("BOOTING..."); 
  setupSensor();
}

void loop()
{
  wdt_reset();

  if (millis() - lastRestart > 300000)   // REFRESH SENSOR EVERY 5 MINUTES
  {
    setupSensor();
    lastRestart = millis();
//    testI2C();
  }


/*  if (millis() - lastTest > 20000)   // TEST
  {
    lastTest = millis();
    testI2C();
  }  */


  if (digitalRead(STRIKEINT) == HIGH)
  {
    intVal = lightning.readInterruptReg();
    
    if(intVal == NOISE_INT)
      Serial.println("Noise."); 
    
    else if(intVal == DISTURBER_INT)
      Serial.println("Disturber."); 

    else if(intVal == LIGHTNING_INT)
    {
      Serial.println("Lightning Strike Detected!"); 
      distance = lightning.distanceToStorm(); 
      Serial.print("Approximately: "); 
      Serial.print(distance); 
      Serial.println("km away!"); 
      long lightEnergy = lightning.lightningEnergy(); 
      Serial.print("Lightning Energy: "); 
      Serial.println(lightEnergy);
    }
    
 /*   if (intVal == NOISE_INT)  
    {
      Wire.beginTransmission(2);
      Wire.write("///");
      Wire.write("NSE*");   
      Wire.write("!");
      Wire.endTransmission();
    }
    
    if (intVal == DISTURBER_INT)  
    {
      Wire.beginTransmission(2);
      Wire.write("///");
      Wire.write("DIS*");   
      Wire.write("!");
      Wire.endTransmission();
    }  */
      
    if (intVal == LIGHTNING_INT) 
    { 
      Wire.beginTransmission(2);
      Wire.write("///"); 
      Wire.write("STR*");
      Wire.write(distance);
      Wire.write("!");
      Wire.endTransmission();
    }    
  }
}



void setupSensor()
{
   // SPI.begin();
 // while (!lightning.beginSPI(CS, 2000000) && tries < 10) 


  if (!lightning.begin())
  {
    tries++;
    failed = true;
    Serial.println (">>> Lightning Detector did not start up!"); 
    while(1);
  }  
  
  if (!failed)
    Serial.println(">>> Lightning Detector Ready");

  lightning.maskDisturber(false); 

  int maskVal = lightning.readMaskDisturber();
  Serial.print("Are disturbers being masked: "); 
  if (maskVal == 1)
    Serial.println("YES"); 
  else if (maskVal == 0)
    Serial.println("NO"); 


  lightning.setIndoorOutdoor(INDOOR); 

  int enviVal = lightning.readIndoorOutdoor();
  Serial.print("Are we set for indoor or outdoor: ");  
  if( enviVal == INDOOR )
    Serial.println("Indoor.");  
  else if( enviVal == OUTDOOR )
    Serial.println("Outdoor.");  
  else 
  {
    Serial.println(enviVal, BIN);
    Serial.println(F(">>> BAD RESPONSE, REBOOTING"));
    while(1);
  }

  lightning.setNoiseLevel(noiseFloor);  

  int noiseVal = lightning.readNoiseLevel();
  Serial.print("Noise Level is set at: ");
  Serial.println(noiseVal);


  lightning.watchdogThreshold(watchDogVal); 

  int watchVal = lightning.readWatchdogThreshold();
  Serial.print("Watchdog Threshold is set to: ");
  Serial.println(watchVal);


  lightning.spikeRejection(spike); 

  int spikeVal = lightning.readSpikeRejection();
  Serial.print("Spike Rejection is set to: ");
  Serial.println(spikeVal);


  lightning.lightningThreshold(lightningThresh); 

  uint8_t lightVal = lightning.readLightningThreshold();
  Serial.print("The number of strikes before interrupt is triggerd: "); 
  Serial.println(lightVal); 

  // When the distance to the storm is estimated, it takes into account other
  // lightning that was sensed in the past 15 minutes. If you want to reset
  // time, then you can call this function. 

//   lightning.clearStatistics(); 
 //  lightning.resetSettings();
}

This device seems to be sensitive to disturbance. Did you have a look at the datasheet and application notes from ams?

Especially the hardware design guide has a couple of points you can review and check with your setup.

Thanks. Looking at the hardware design guide I do have one potential problem, and that's the DC-DC step down converter that reduces the solar powered battery voltage (max 15V) down to 7.5V that goes to the arduino Vin. This unit is set up outside away from any interference (we are located about 15kms away from the closest grid.) But I have to wonder whether the small 20W solar panel may cause enough interference to mess with things. But then again, I've not recorded any strikes even at night time.

At the moment I'm testing another unit on my bench, connected to my laptop through USB, so I can watch the serial output during a storm. I wonder if this would cause enough interference to block out strikes.

Well, laptops like all PCs are full of stuff that create all kinds of noise. fan motors, DC-DC converters, fast processors, GPUs, high speed network cards, ... and you want to detect a lightning strike 40km away.

Check out the Demo kit documentation.

It looks like they use coin cells for the kit to eliminate any conducted interference.

They show a noise level warning on the kit created by placing the kit on a laptop. :slight_smile:

According to Figure 3, the DemoKit can be used in the office an arm length away from IT equipment.

You could give this lightning sensor a try made by a different company based on same chipset

As per the description there seems to be some noise detection and handling capability.

The AS3935 is a particularly tricky part to deal with because it is very sensitive to RF noise. I've been developing a Bluetooth Serial Controller for it so that it can be kept further from computers and monitors. Also, you really need the ability to generate fake lightning strikes to test everything. I have put the plans for both plus some thoughts on how the chip works on a web page: AS3935 Workbook

2 Likes