So I have this project working on an Arduino Uno, but owing to the need of more Digital Pins/Wifi hookup I am moving this to a Mega2560.
Code via Sparkfun's Hookup Guide:
/*
This example demonstrates how to detect lightning! It has a few basic
settings to help with rejecting noise or "disturbers" (false lightning events).
It uses the onboard interrupt hardware pin, so in addition to attaching to
it data lines you'll need to connnect to the interrupt pin labled "INT".
By: Elias Santistevan
SparkFun Electronics
Date: May, 2019
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
*/
#include <SPI.h>
#include <Wire.h>
#include "SparkFun_AS3935.h"
#define INDOOR 0x12
#define OUTDOOR 0xE
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
#define NOISE_INT 0x01
SparkFun_AS3935 lightning;
// Interrupt pin for lightning detection
const int lightningInt = 4;
int spiCS = 53; //SPI chip select pin
// This variable holds the number representing the lightning or non-lightning
// event issued by the lightning detector.
int intVal = 0;
int noise = 2; // Value between 1-7
int disturber = 2; // Value between 1-10
void setup()
{
// When lightning is detected the interrupt pin goes HIGH.
pinMode(lightningInt, INPUT);
Serial.begin(115200);
Serial.println("AS3935 Franklin Lightning Detector");
SPI.begin();
if( !lightning.beginSPI(spiCS) ){
Serial.println ("Lightning Detector did not start up, freezing!");
while(1);
}
else
Serial.println("Schmow-ZoW, Lightning Detector Ready!");
// The lightning detector defaults to an indoor setting at
// the cost of less sensitivity, if you plan on using this outdoors
// uncomment the following line:
//lightning.setIndoorOutdoor(OUTDOOR);
}
void loop()
{
// Hardware has alerted us to an event, now we read the interrupt register
if(digitalRead(lightningInt) == HIGH){
intVal = lightning.readInterruptReg();
if(intVal == NOISE_INT){
Serial.println("Noise.");
// Too much noise? Uncomment the code below, a higher number means better
// noise rejection.
//lightning.setNoiseLevel(noise);
}
else if(intVal == DISTURBER_INT){
Serial.println("Disturber.");
// Too many disturbers? Uncomment the code below, a higher number means better
// disturber rejection.
//lightning.watchdogThreshold(disturber);
}
else if(intVal == LIGHTNING_INT){
Serial.println("Lightning Strike Detected!");
// Lightning! Now how far away is it? Distance estimation takes into
// account any previously seen events in the last 15 seconds.
byte distance = lightning.distanceToStorm();
Serial.print("Approximately: ");
Serial.print(distance);
Serial.println("km away!");
}
}
delay(100); // Slow it down.
}
Sensor is seemingly detected, which is shown by Serial Monitor saying;
Serial.println("Schmow-ZoW, Lightning Detector Ready!");
And not
Serial.println ("Lightning Detector did not start up, freezing!");
On initilization.
But it doesn't register events, which on the Uno hookup I was able to achieve by clicking a lighter nearby the sensor.
Attached is the wiring of the Mega, which is the same except:
const int lightningInt = 2; - Uno
const int lightningInt = 4; - Mega
int spiCS = 10; - Uno
int spiCS = 53; - Mega
Digital 50 - Mega
Digital 12 - Uno
Digital 51 Mega
Digital 11 Uno
Digital 52 Mega
Digital 13 Uno
Digital 53 Mega
Digital 10 Uno