Arduino Pocket Lightning Detector
Arduino Pocket Lightning Detector
Table of Contents
Step 2: Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
Author:raht
My name is Kevin Palivec. I'm a network engineer who lives in Texas. I love building useful stuff from scavenged parts
This project came about when, while I was searching around through the internet for sensors that I might like to try with an arduino as an interesting project. I also run a
video camera for our local school district's football stadium and it's not uncommon to have Lightning delays. I thought this project might have some use in that regard as
well. I have several Arduino nanos laying around and was itching to make something. In my searching I found the AS3935 Lightning detection sensor. Franklin as3935
(Here's a link to some data on it.) It's a low power lightning sensor that packs a lot of info into a small package.
Most Arduino lightning detection projects basically just tell you that something "lightning-like" occurred. This sensor actually watches for the particular Waveform of
lightning at 500Khz and gives a distance approximation! Kinda of a cool little gadget to have in your pocket next time it thunders! I immediately wanted to try one out!!
An arduino.
Most any Arduino will do. However if you're planning on your unit being portable. Obviously smaller is better.
-------------------------------------------------------------
You can find these from any number of places. Here are a couple of links to get you started. Expect to pay about $20
>Embeded Adventures
--------------------------------------------------------------
>Ebay
--------------------------------------------------------------
Ebay nokia 5110 (a note of warning. I've ordered several of these and the quality is all over the place. Some are perfect. some have contrast problems. You can usually
fix the contrast issues by pressing the metal frame down firm around the lcd)
--------------------------------------------------------------
--------------------------------------------------------------
Early on I decided I wanted this to have some kind of a graphical display and a way to set some simple configuration. I also decided to just hardwire all the parts together
so it would be stable when carried around in it's soon to be designed box. I also planned on it being battery powered and portable.
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
My first "throw together" prototype used a 16X2 LCD display but I soon realized the size limited the data I could display so I moved to a Nokia 5110 display Module. This
would allow more data onscreen at one time and opened up the possibility of a little "monitoring activity" animation. It would also allow me to create a little stylized
distance graphic. I needed some way to access the simple config menu and Decided to use a little Resistance button panel that allows the monitoring of several buttons
with only one analog input. Each button on the panel gives a different reading value and that value can be the basis for accessing differing routines and the Arduino code.
for interconnections of all the parts I used strips of ribbon cable to kind of help keep things clean and allow flexibility in placement of the parts inside whatever case I
eventually came up with.
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
Step 2: Assembly
Assembly is pretty straight forward. All the connections are direct and there's no need for electrical component parts like resistors, capacitors or transistors. it's all point to
point!
The Display will communicate with the Arduino via SPI. The lightning sensor communicates via I2C.
The Lightning sensor has the capability to utilize SPI or I2C. After some experimenting I found that for some reason having both connected via SPI was problematic. The
lightning detection was not reliable and there were noise issues between the display and the lightning sensor. Changing the Sensor over to I2C cleared up the problems.
My circuit uses an Arduino Nano the I2C pins are SDA(A4) and SCL(A5)
(different arduinos use different pins. Check yours to find out which)
Lightning Detector
A4 --------------> MOS/SDA
A5 ---------------> SCK/SCL
5V --------------- > SI (this pins selects what Communication type the chip uses. (+ = I2C, -=SPI)
( CS Not used)
D4 -------------------------> RST
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
D5 -------------------------> CE
D8 ---------------------------> DC
5V --------------------------> VCC
D6 --------------------------> Light (making this pin low turns on the back light)
Button Panel
5V -------------------> Vcc
A0 -------------------> OUT
Those are all the hardware connections. Reference the pseudo Schematic I included if you need help.
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
Step 3: Code and Icons
Now comes the part that makes it all work!
The AS3935 Sensor basicly just sits and listens for lightnig via the small induction antenna on the breakout board. When it detects something it thinks is lightning or noise
it triggers whats called an IRQ. This is a signal that is hard wired into the arduino that can cause it to stop and pay attention no matter what it's doing at the time.
When the Arduino sees the IRQ line change it stops whatever code it's running and jumps to a special bit of code that can read the data the sensor has stored about the
particular event it's detected and then display or act upon what it finds.
In our case the Arduino sits and happily (or unhappily, who knows how it feels about it..) moving a little cloud bitmap across the display. Over and over.... it also
momentarily looks to see if a button has ben pressed indicating the almighty user wants to change some settings.
If the Sensor pokes the arduino in the side with an IRQ. The arduino stops animating the little cloud and asks the sensor what it wants. The arduino then updates the
display to show what it's learned.
The sketch also includes some rudimentary config settings like whether we want to know the lightning distance in Miles or Kilometers or if we're inside or outside.
I've included a zip file that contains all the files I've created in relation to this project. it also contains the libraries for the lightning detector board. It has everything you'll
need to build this the same way I have.
The Nokia 5110 libraries are available in the Arduino IDE libraries manager. Just Search for adafruit GFX and LCD.
#include "I2C.h"
// include Playing With Fusion AXS3935 libraries
#include "PWFusion_AS3935_I2C.h"
int l=0;
int n=0;
int lsDist=0;
int mapDist=0;
int m=0;
int dist=0;
int tt=0;
// prototypes
void AS3935_ISR();
//--- data that builds the onscreen icons
PWF_AS3935_I2C lightning0((uint8_t)IRQ_PIN, (uint8_t)SI_PIN, (uint8_t)AS3935_ADD);
const unsigned char PROGMEM lightning_bmp[32] = {
0x01, 0xE0, 0x02, 0x20, 0x0C, 0x18, 0x12, 0x24, 0x21, 0x06, 0x10, 0x02, 0x1F, 0xFC, 0x01, 0xF0,
0x01, 0xC0, 0x03, 0x80, 0x07, 0xF8, 0x00, 0xF0, 0x00, 0xC0, 0x01, 0x80, 0x01, 0x00, 0x01, 0x00
};
const unsigned char PROGMEM cloud[32] = {
0x01, 0xE0, 0x02, 0x20, 0x0C, 0x18, 0x12, 0x24, 0x21, 0x06, 0x10, 0x02, 0x1F, 0xFC, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char PROGMEM lightning[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x01, 0xF0,
0x01, 0xC0, 0x03, 0x80, 0x07, 0xF8, 0x00, 0xF0, 0x00, 0xC0, 0x01, 0x80, 0x01, 0x00, 0x01, 0x00
};
int read_buttons()
{
adc_key_in = analogRead(0); // read the value from Button Panel. Values returned if a button gets pressed and which one it was....
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
display.setCursor(0,0);
display.setTextSize(1);
display.println("Indoor");
display.setCursor(0,20);
display.println("Operation");
display.display();
delay(1000);
menu();
}
if (read_buttons() == 3){
lightning0.AS3935_SetOutdoors();
dist=1;
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(1);
display.println("Outdoor");
display.setCursor(0,20);
display.println("Operation");
display.display();
delay(1000);
menu();
}
}
return;
}
void setup()
{
pinMode(6,OUTPUT);
Serial.begin(115200);
display.begin();
// init done
// setup for the the I2C library: (enable pullups, set speed to 400kHz)
I2c.begin();
I2c.pullup(true);
I2c.setSpeed(1);
delay(2);
// enable interrupt (hook IRQ pin to Arduino Uno/Mega interrupt input: 0 -> pin 2, 1 -> pin 3 )
attachInterrupt(0, AS3935_ISR, RISING);
lightning0.AS3935_PrintAllRegs();
AS3935_ISR_Trig = 0; // clear trigger
//------- this just gets played over and over..... and over...... and o......
void loop()
{
display.clearDisplay();
analogWrite(6,60); //---turn on the backlight
//----- build the screen
display.setCursor(0,0);
display.println("LastStrike");
display.setCursor(0,8);
display.println("Dist: "+ String(lsDist));
display.setCursor(50,8);
//--- if we pick miles, do this
if (mi==1){ display.println(" Mi");}
//otherwise assume we want to do this....
else { display.println(" Km");}
display.setCursor(0,17);
display.println("0");
display.setCursor(72,17);
//if miles--- 40 km = aaprox 25 miles
if(mi==1){
display.println("25");
}
else{
//--- otherwise just scale it for 40 km
display.println("40");
}
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
display.setCursor(0,39);
display.println("Strikes: ");
display.setCursor(48,39);
display.println(String(l));
display.setCursor(64,39);
//-- place an indication that we're set to inside in the lower right corner of the display
if (dist==1){display.println("Out");}
else{
//-- or Show were set for outdoors
display.println("In");}
//--draw the distance scale
display.drawLine( 0, 37, 84, 37, BLACK);
//display.fillCircle(mapDist,35,2,BLACK);
if (l==0)
//-- we begin with no strikes detected
display.setCursor(9,24);
display.println("No Strikes");
if (l>0)
//-if theres a strike. place a little zap at the distance it is...
display.drawBitmap(mapDist, 22, lightning, 16, 16, 1);
if (mapDist>20){
display.setCursor(9,24);
display.println("Far Ligntning");
}
display.display();
if(0 == AS3935_ISR_Trig){
// Serial.println(read_buttons());
animateCloud();
//Serial.println(read_buttons());
if (read_buttons() !=5){
menu();
};
// reset interrupt flag
AS3935_ISR_Trig = 0;
// this is irq handler for AS3935 interrupts, has to return void and take no arguments
// always make code in interrupt handlers fast and short
void AS3935_ISR()
{
AS3935_ISR_Trig = 1;
}
//---flash the display routine
void flash(){
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
for (int y=1;y<5;y++){
digitalWrite(6,LOW);
display.invertDisplay(true);
delay(100);
digitalWrite(6,HIGH);
display.invertDisplay(false);
delay(100);
}
}
//--make that cloud go baby!!
void animateCloud(){
display.drawBitmap(m,15, cloud, 16, 16, 1);
display.display();
if(m>=80){m=0;}
m++;
delay(200);
}
File Downloads
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
LightningDetector_files.zip (2 MB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'LightningDetector_files.zip']
Step 4: Designing and Printing a Case
Next came the fun of designing a case to hold my little creation.
Not the most beautiful thing in the world. But it's functional.
In order to design a case I needed to know the dimensions of the parts involved. Namely the LCD display and the button panel.
The measurements for the Nokia 5110 were easily obtained. The button panel however... that was a different story! I ended up measuring... printing... re-measuring...
printing... until I was pretty happy with the fit.
I've included the results in the form if a diagram in the hopes it saves someone else some time!
The case I designed wont win any design awards. It's simple, functional and, slightly translucent! I plan on adding some led's later so the case will glow or flash when a
lightning strike is detected. Why not? I have plenty of pins left on the Arduino! I might also add an SDcard slot to log data! Or you could do that! The possibilities are
endless!
Back to the case... basicly it's a box. just a box with holes for the buttons and the display. It'll hold the guts and a 9V or AA battery pack.
For starters I'll just hot glue all the parts in their places to see if it all fits and works reliably.
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/
Step 5: Testing and Use
Now for the Real part! Seeing it work in the field... now if We'd only get some thunderstorms!
I've included some videos of the detector starting up and the setting of the limited configuration parameters.
If by the time I publish this Instructable I haven't had any storms to test it with. I'll upload some videos later.!
BTW.. please excuse the music on the one demo video. Someone was talking to me over the desk when
I was shooting it and I thought I'd spare you the conversation! =)
Related Instructables
Simple, No
Halloween Code Lightning
Lightning! The Trigger/Flash Fire detection Autonomous Arduino PIR
Haunt Hack by Lightning Slave Trigger using Arduino Fire Fighter Motion Sensor
imarunner2 Detector for From Cheap and flame Robot by Based Security
Raspberry Pi Sensor by sensor by nishad111 System by
Weather Station benster TechPonder sezgingul
by
SwitchDocLabs
Advertisements
Comments
http://www.instructables.com/id/Arduino-Pocket-Lightning-Detector/