Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Sketch for Lightning Sensor

Sketch for Lightning Sensor

Scheduled Pinned Locked Moved Development
58 Posts 14 Posters 31.6k Views 11 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SparkmanS Offline
    SparkmanS Offline
    Sparkman
    Hero Member
    wrote on last edited by
    #35

    @alexsh1 @scalz

    I'm running my sketch with I2C now, rather than SPI. I found the sensor would lock up occassionally, so recently converted it and am still testing it. I have mine running at 5v now as well instead of 3.3v, but it works fine with either.

    I'll post an updated sketch (and wiring diagram) soon. I based both the spi and i2c sketches on the examples found here: http://playingwithfusion.com/productview.php?pdid=22&catid=1001.

    Cheers
    Al

    alexsh1A 1 Reply Last reply
    0
    • SparkmanS Sparkman

      @alexsh1 @scalz

      I'm running my sketch with I2C now, rather than SPI. I found the sensor would lock up occassionally, so recently converted it and am still testing it. I have mine running at 5v now as well instead of 3.3v, but it works fine with either.

      I'll post an updated sketch (and wiring diagram) soon. I based both the spi and i2c sketches on the examples found here: http://playingwithfusion.com/productview.php?pdid=22&catid=1001.

      Cheers
      Al

      alexsh1A Offline
      alexsh1A Offline
      alexsh1
      wrote on last edited by
      #36

      @Sparkman Thanks. Your sketch is very much appreciated. I'll have to adopt it anyway as I have a different manufacture and there is a certain process I have to follow to get it initiated (posted above).

      1 Reply Last reply
      0
      • alexsh1A Offline
        alexsh1A Offline
        alexsh1
        wrote on last edited by alexsh1
        #37

        Absolutely delighted with the module I have received today by post. The weather is sh@t tonight (lightning, rain etc.) which means that I can test it:

        Welcome to the MOD-1016 (AS3935) Lightning Sensor test sketch!
        TUNE	IN/OUT	NOISEFLOOR
        6	10010	5
        
        after interrupt
        DISTURBER DETECTED
        DISTURBER DETECTED
        DISTURBER DETECTED
        DISTURBER DETECTED
        DISTURBER DETECTED
        LIGHTNING DETECTED
        Lightning ~27km away
        
        DISTURBER DETECTED
        DISTURBER DETECTED
        LIGHTNING DETECTED
        Lightning ~17km away
        
        DISTURBER DETECTED
        LIGHTNING DETECTED
        Lightning ~10km away
        

        I calibrated the sensor and put a reasonable "noise floor". Now I have to convert it into MySensors and hook up to the ceech board outside.

        @Sparkman I have my sensor running at 3.3V

        alexsh1A 1 Reply Last reply
        0
        • alexsh1A alexsh1

          Absolutely delighted with the module I have received today by post. The weather is sh@t tonight (lightning, rain etc.) which means that I can test it:

          Welcome to the MOD-1016 (AS3935) Lightning Sensor test sketch!
          TUNE	IN/OUT	NOISEFLOOR
          6	10010	5
          
          after interrupt
          DISTURBER DETECTED
          DISTURBER DETECTED
          DISTURBER DETECTED
          DISTURBER DETECTED
          DISTURBER DETECTED
          LIGHTNING DETECTED
          Lightning ~27km away
          
          DISTURBER DETECTED
          DISTURBER DETECTED
          LIGHTNING DETECTED
          Lightning ~17km away
          
          DISTURBER DETECTED
          LIGHTNING DETECTED
          Lightning ~10km away
          

          I calibrated the sensor and put a reasonable "noise floor". Now I have to convert it into MySensors and hook up to the ceech board outside.

          @Sparkman I have my sensor running at 3.3V

          alexsh1A Offline
          alexsh1A Offline
          alexsh1
          wrote on last edited by
          #38

          BTW, I am not sure the sensor is similar to what you guys have.

          0_1466633381738_2016-06-22 09.54.18.jpg

          SparkmanS K 2 Replies Last reply
          0
          • alexsh1A alexsh1

            BTW, I am not sure the sensor is similar to what you guys have.

            0_1466633381738_2016-06-22 09.54.18.jpg

            SparkmanS Offline
            SparkmanS Offline
            Sparkman
            Hero Member
            wrote on last edited by
            #39

            @alexsh1 It looks to be a different breakout board, but for the same chip. So I would expect them to work basically the same.

            Cheers
            Al

            alexsh1A 1 Reply Last reply
            0
            • SparkmanS Sparkman

              @alexsh1 It looks to be a different breakout board, but for the same chip. So I would expect them to work basically the same.

              Cheers
              Al

              alexsh1A Offline
              alexsh1A Offline
              alexsh1
              wrote on last edited by
              #40

              @Sparkman it is a different board made (or designed) by a UK company.

              We are having a real British summer over here :-)))

              LIGHTNING DETECTED
              Lightning ~20km away
              
              LIGHTNING DETECTED
              Lightning ~20km away
              
              LIGHTNING DETECTED
              Lightning ~6km away
              
              LIGHTNING DETECTED
              Lightning ~6km away
              
              LIGHTNING DETECTED
              Lightning ~6km away
              
              LIGHTNING DETECTED
              Lightning ~6km away
              
              LIGHTNING DETECTED
              Lightning ~6km away
              
              LIGHTNING DETECTED
              Lightning ~5km away
              
              NeverDieN 1 Reply Last reply
              0
              • alexsh1A alexsh1

                @Sparkman it is a different board made (or designed) by a UK company.

                We are having a real British summer over here :-)))

                LIGHTNING DETECTED
                Lightning ~20km away
                
                LIGHTNING DETECTED
                Lightning ~20km away
                
                LIGHTNING DETECTED
                Lightning ~6km away
                
                LIGHTNING DETECTED
                Lightning ~6km away
                
                LIGHTNING DETECTED
                Lightning ~6km away
                
                LIGHTNING DETECTED
                Lightning ~6km away
                
                LIGHTNING DETECTED
                Lightning ~6km away
                
                LIGHTNING DETECTED
                Lightning ~5km away
                
                NeverDieN Offline
                NeverDieN Offline
                NeverDie
                Hero Member
                wrote on last edited by
                #41

                @alexsh1
                There doesn't appear to be audio input to this board, nor a microphone on the board. So, how does it estimate the distance to the lightening?

                SparkmanS 1 Reply Last reply
                0
                • NeverDieN NeverDie

                  @alexsh1
                  There doesn't appear to be audio input to this board, nor a microphone on the board. So, how does it estimate the distance to the lightening?

                  SparkmanS Offline
                  SparkmanS Offline
                  Sparkman
                  Hero Member
                  wrote on last edited by
                  #42

                  @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                  Cheers
                  Al

                  NeverDieN 1 Reply Last reply
                  0
                  • SparkmanS Sparkman

                    @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                    Cheers
                    Al

                    NeverDieN Offline
                    NeverDieN Offline
                    NeverDie
                    Hero Member
                    wrote on last edited by
                    #43

                    @Sparkman said:

                    @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                    Cheers
                    Al

                    Any impression yet as to how accurate its distance estimates are?

                    SparkmanS alexsh1A 2 Replies Last reply
                    0
                    • NeverDieN NeverDie

                      @Sparkman said:

                      @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                      Cheers
                      Al

                      Any impression yet as to how accurate its distance estimates are?

                      SparkmanS Offline
                      SparkmanS Offline
                      Sparkman
                      Hero Member
                      wrote on last edited by
                      #44

                      @NeverDie No, as we've had very little lightning since I started using it.

                      1 Reply Last reply
                      0
                      • NeverDieN NeverDie

                        @Sparkman said:

                        @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                        Cheers
                        Al

                        Any impression yet as to how accurate its distance estimates are?

                        alexsh1A Offline
                        alexsh1A Offline
                        alexsh1
                        wrote on last edited by
                        #45

                        @NeverDie Al, was quicker replying to your question. :-)
                        yes, I think it is accurate for my needs - if a lightning detected at, say, 10km+/- 1km this is ok. How accurate do you want it to be?

                        This is a great technology

                        NeverDieN 1 Reply Last reply
                        0
                        • alexsh1A alexsh1

                          @NeverDie Al, was quicker replying to your question. :-)
                          yes, I think it is accurate for my needs - if a lightning detected at, say, 10km+/- 1km this is ok. How accurate do you want it to be?

                          This is a great technology

                          NeverDieN Offline
                          NeverDieN Offline
                          NeverDie
                          Hero Member
                          wrote on last edited by NeverDie
                          #46

                          @alexsh1 said:

                          @NeverDie Al, was quicker replying to your question. :-)
                          How accurate do you want it to be?

                          I'm not sure, but more accurate than lightningmaps.com or it's a no-go. I've played with lightningmaps.com during a few thunderstorms, and although it's great for getting a general idea of lightning strike rate and density, I was surprised that it seems to miss a lot of detections entirely that both my eyes and ears have confirmed. e.g. some strikes that were big enough to rattle the windows didn't show up at all on lightningmaps. Some of the others were detected, but the map plot of the strike was wrong by maybe 10 miles or so.

                          alexsh1A 1 Reply Last reply
                          0
                          • NeverDieN NeverDie

                            @alexsh1 said:

                            @NeverDie Al, was quicker replying to your question. :-)
                            How accurate do you want it to be?

                            I'm not sure, but more accurate than lightningmaps.com or it's a no-go. I've played with lightningmaps.com during a few thunderstorms, and although it's great for getting a general idea of lightning strike rate and density, I was surprised that it seems to miss a lot of detections entirely that both my eyes and ears have confirmed. e.g. some strikes that were big enough to rattle the windows didn't show up at all on lightningmaps. Some of the others were detected, but the map plot of the strike was wrong by maybe 10 miles or so.

                            alexsh1A Offline
                            alexsh1A Offline
                            alexsh1
                            wrote on last edited by
                            #47

                            @NeverDie I have not tested this sensor long enough, but recently we have had torrential rain, lightning, etc - you can see some data I published above. The sensor did not miss a single one. There are a few parameters you can alter (noise floor). One has to setup it correctly. I have not started looking into converting the sketch for MySensors yet

                            1 Reply Last reply
                            0
                            • alexsh1A Offline
                              alexsh1A Offline
                              alexsh1
                              wrote on last edited by alexsh1
                              #48

                              I have adopted the MOD-1016 module (https://www.embeddedadventures.com/datasheets/MOD-1016_hw_v8_doc_v4.pdf) for MySensors if anyone is interested:

                              /*
                              
                              Copyright (c) 2016, Embedded Adventures
                              All rights reserved.
                              
                              Contact us at source [at] embeddedadventures.com
                              www.embeddedadventures.com
                              
                              Redistribution and use in source and binary forms, with or without
                              modification, are permitted provided that the following conditions are met:
                              
                              - Redistributions of source code must retain the above copyright notice,
                                this list of conditions and the following disclaimer.
                              
                              - Redistributions in binary form must reproduce the above copyright
                                notice, this list of conditions and the following disclaimer in the
                                documentation and/or other materials provided with the distribution.
                              
                              - Neither the name of Embedded Adventures nor the names of its contributors
                                may be used to endorse or promote products derived from this software
                                without specific prior written permission.
                               
                              THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
                              AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                              IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                              ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
                              LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                              CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                              SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                              INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
                              CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
                              ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
                              THE POSSIBILITY OF SUCH DAMAGE.
                              
                              */
                              
                              // Enable debug prints to serial monitor
                              #define MY_DEBUG 
                              
                              // Enable and select radio type attached
                              #define MY_RADIO_NRF24
                              //#define MY_RADIO_RFM69
                              #define MY_NODE_ID 15
                              
                              #include <Wire.h>
                              #include <MySensors.h>
                              #include <AS3935.h> // AS3935 MOD-1016 by Embedded Adventures
                              
                              volatile bool detected = false;
                              
                              
                               //-----------------IMPORTANT--------------------
                               //---------------CHANGE SETTINGS HERE-----------
                              #define IRQ_pin 2
                              
                              #define AS3935_TUNE_CAPS     6 // <-- SET THIS VALUE TO THE NUMBER LISTED ON YOUR BOARD 
                              #define AS3935_INDOORS       1 // AS3935_INDOORS=1 indoors, AS3935_INDOORS=0 outdoors
                              #define AS3935_NOISE_FLOOR   6
                              #define AS3935_ENABLE_DISTURBERS 1 // 0 or 1      
                              
                              #define CHILD_ID_DISTANCE 1
                              #define CHILD_ID_INTENSITY 2
                              MyMessage msgDist(CHILD_ID_DISTANCE, V_DISTANCE);
                              MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1);
                              
                              void setup()  
                              { 
                                Serial.begin(115200);
                                while (!Serial) {}
                                Serial.println("MOD-1016 (AS3935) Lightning Sensor");
                                Serial.println("beginning boot procedure....");
                                
                                Wire.begin();
                                mod1016.init(IRQ_pin);
                               
                               //-----------------IMPORTANT--------------------
                               //---------------CHANGE SETTINGS HERE-----------
                                //Tune Caps, Set AFE, Set Noise Floor
                                //autoTuneCaps(IRQ_pin);
                                mod1016.setTuneCaps(AS3935_TUNE_CAPS);
                              delay(2);
                              #if AS3935_INDOORS == 1
                                mod1016.setIndoors();
                                #else
                                mod1016.setOutdoors();
                              #endif
                              delay(2);
                              mod1016.setNoiseFloor(AS3935_NOISE_FLOOR);
                              delay(2);
                              #if AS3935_ENABLE_DISTURBERS == 1
                                mod1016.enableDisturbers();
                              #else
                                mod1016.disableDisturbers();
                              #endif
                              //mod1016.calibrateRCO();
                              delay(2);
                                Serial.println("TUNE\tIN/OUT\tNOISEFLOOR");
                                Serial.print(mod1016.getTuneCaps(), HEX);
                                Serial.print("\t");
                                Serial.print(mod1016.getAFE(), BIN);
                                Serial.print("\t");
                                Serial.println(mod1016.getNoiseFloor(), HEX);
                                Serial.print("\n");
                              
                                pinMode(IRQ_pin, INPUT);
                                attachInterrupt(digitalPinToInterrupt(IRQ_pin), alert, RISING);
                                Serial.println("after interrupt");
                                  // delay execution to allow chip to stabilize.
                                delay(1000);
                              
                              }
                              
                              void presentation()  {
                                // Send the sketch version information to the gateway and Controller
                                sendSketchInfo("Lightning Sensor MOD-1016", "1.0");
                              
                                // Register all sensors to gw (they will be created as child devices)
                                present(CHILD_ID_DISTANCE, S_DISTANCE);
                                present(CHILD_ID_INTENSITY, S_CUSTOM);
                              }
                              
                              void loop() {
                                if (detected) {
                                  translateIRQ(mod1016.getIRQ());
                                  detected = false;
                                }
                              }
                              
                              void alert() {
                                detected = true;
                              }
                              
                              void translateIRQ(uns8 irq) {
                                switch(irq) {
                                    case 1:
                                      Serial.println("Noise detected");
                                      break;
                                    case 4:
                                      Serial.println("Disturber detected");
                                      break;
                                    case 8: 
                                      Serial.println("Lightning detected!");
                                      printandsendToGW();
                                      break;
                              
                                }
                              }
                              
                              void printandsendToGW() {
                                int distance = mod1016.calculateDistance();
                                unsigned int lightning_intensity = mod1016.getIntensity();
                                if (distance == -1)
                                  Serial.println("Lightning out of range");
                                else if (distance == 1)
                                  Serial.println("Distance not in table");
                                else if (distance == 0)
                                  Serial.println("Lightning overhead");
                                else {
                                  Serial.print("Lightning ~");
                                  Serial.print(distance);
                                  Serial.println("km away\n");
                                  Serial.print("Lightning Intensity: ");
                                  Serial.println(lightning_intensity);  
                                  send(msgDist.set(distance));
                                  send(msgInt.set(lightning_intensity));
                                }
                              }
                              

                              You have to change the sketch according to your module settings

                              skywatchS 1 Reply Last reply
                              2
                              • skywatchS Offline
                                skywatchS Offline
                                skywatch
                                wrote on last edited by skywatch
                                #49

                                I ordered one form embedded adventures on 27/7 - Now it is 3/9 and still nothing.
                                Waiting to hear from them....
                                That's the whole truth.

                                alexsh1A 1 Reply Last reply
                                0
                                • skywatchS skywatch

                                  I ordered one form embedded adventures on 27/7 - Now it is 3/9 and still nothing.
                                  Waiting to hear from them....
                                  That's the whole truth.

                                  alexsh1A Offline
                                  alexsh1A Offline
                                  alexsh1
                                  wrote on last edited by
                                  #50

                                  @skywatch give them a call or send a e-mail. Maybe your order was lost in post. Happens.
                                  My order arrived in 2 days from Embedded Adventures

                                  1 Reply Last reply
                                  0
                                  • skywatchS Offline
                                    skywatchS Offline
                                    skywatch
                                    wrote on last edited by
                                    #51

                                    OK - finally got board, seems the problem was in the warehouse. I got email to say it had been sent and it never did. At least I can try it out soon and see how it compares to the current lightning sensors I use.

                                    NeverDieN 1 Reply Last reply
                                    0
                                    • alexsh1A alexsh1

                                      I have adopted the MOD-1016 module (https://www.embeddedadventures.com/datasheets/MOD-1016_hw_v8_doc_v4.pdf) for MySensors if anyone is interested:

                                      /*
                                      
                                      Copyright (c) 2016, Embedded Adventures
                                      All rights reserved.
                                      
                                      Contact us at source [at] embeddedadventures.com
                                      www.embeddedadventures.com
                                      
                                      Redistribution and use in source and binary forms, with or without
                                      modification, are permitted provided that the following conditions are met:
                                      
                                      - Redistributions of source code must retain the above copyright notice,
                                        this list of conditions and the following disclaimer.
                                      
                                      - Redistributions in binary form must reproduce the above copyright
                                        notice, this list of conditions and the following disclaimer in the
                                        documentation and/or other materials provided with the distribution.
                                      
                                      - Neither the name of Embedded Adventures nor the names of its contributors
                                        may be used to endorse or promote products derived from this software
                                        without specific prior written permission.
                                       
                                      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
                                      AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                                      IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                                      ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
                                      LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                                      CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                                      SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                                      INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
                                      CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
                                      ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
                                      THE POSSIBILITY OF SUCH DAMAGE.
                                      
                                      */
                                      
                                      // Enable debug prints to serial monitor
                                      #define MY_DEBUG 
                                      
                                      // Enable and select radio type attached
                                      #define MY_RADIO_NRF24
                                      //#define MY_RADIO_RFM69
                                      #define MY_NODE_ID 15
                                      
                                      #include <Wire.h>
                                      #include <MySensors.h>
                                      #include <AS3935.h> // AS3935 MOD-1016 by Embedded Adventures
                                      
                                      volatile bool detected = false;
                                      
                                      
                                       //-----------------IMPORTANT--------------------
                                       //---------------CHANGE SETTINGS HERE-----------
                                      #define IRQ_pin 2
                                      
                                      #define AS3935_TUNE_CAPS     6 // <-- SET THIS VALUE TO THE NUMBER LISTED ON YOUR BOARD 
                                      #define AS3935_INDOORS       1 // AS3935_INDOORS=1 indoors, AS3935_INDOORS=0 outdoors
                                      #define AS3935_NOISE_FLOOR   6
                                      #define AS3935_ENABLE_DISTURBERS 1 // 0 or 1      
                                      
                                      #define CHILD_ID_DISTANCE 1
                                      #define CHILD_ID_INTENSITY 2
                                      MyMessage msgDist(CHILD_ID_DISTANCE, V_DISTANCE);
                                      MyMessage msgInt(CHILD_ID_INTENSITY, V_VAR1);
                                      
                                      void setup()  
                                      { 
                                        Serial.begin(115200);
                                        while (!Serial) {}
                                        Serial.println("MOD-1016 (AS3935) Lightning Sensor");
                                        Serial.println("beginning boot procedure....");
                                        
                                        Wire.begin();
                                        mod1016.init(IRQ_pin);
                                       
                                       //-----------------IMPORTANT--------------------
                                       //---------------CHANGE SETTINGS HERE-----------
                                        //Tune Caps, Set AFE, Set Noise Floor
                                        //autoTuneCaps(IRQ_pin);
                                        mod1016.setTuneCaps(AS3935_TUNE_CAPS);
                                      delay(2);
                                      #if AS3935_INDOORS == 1
                                        mod1016.setIndoors();
                                        #else
                                        mod1016.setOutdoors();
                                      #endif
                                      delay(2);
                                      mod1016.setNoiseFloor(AS3935_NOISE_FLOOR);
                                      delay(2);
                                      #if AS3935_ENABLE_DISTURBERS == 1
                                        mod1016.enableDisturbers();
                                      #else
                                        mod1016.disableDisturbers();
                                      #endif
                                      //mod1016.calibrateRCO();
                                      delay(2);
                                        Serial.println("TUNE\tIN/OUT\tNOISEFLOOR");
                                        Serial.print(mod1016.getTuneCaps(), HEX);
                                        Serial.print("\t");
                                        Serial.print(mod1016.getAFE(), BIN);
                                        Serial.print("\t");
                                        Serial.println(mod1016.getNoiseFloor(), HEX);
                                        Serial.print("\n");
                                      
                                        pinMode(IRQ_pin, INPUT);
                                        attachInterrupt(digitalPinToInterrupt(IRQ_pin), alert, RISING);
                                        Serial.println("after interrupt");
                                          // delay execution to allow chip to stabilize.
                                        delay(1000);
                                      
                                      }
                                      
                                      void presentation()  {
                                        // Send the sketch version information to the gateway and Controller
                                        sendSketchInfo("Lightning Sensor MOD-1016", "1.0");
                                      
                                        // Register all sensors to gw (they will be created as child devices)
                                        present(CHILD_ID_DISTANCE, S_DISTANCE);
                                        present(CHILD_ID_INTENSITY, S_CUSTOM);
                                      }
                                      
                                      void loop() {
                                        if (detected) {
                                          translateIRQ(mod1016.getIRQ());
                                          detected = false;
                                        }
                                      }
                                      
                                      void alert() {
                                        detected = true;
                                      }
                                      
                                      void translateIRQ(uns8 irq) {
                                        switch(irq) {
                                            case 1:
                                              Serial.println("Noise detected");
                                              break;
                                            case 4:
                                              Serial.println("Disturber detected");
                                              break;
                                            case 8: 
                                              Serial.println("Lightning detected!");
                                              printandsendToGW();
                                              break;
                                      
                                        }
                                      }
                                      
                                      void printandsendToGW() {
                                        int distance = mod1016.calculateDistance();
                                        unsigned int lightning_intensity = mod1016.getIntensity();
                                        if (distance == -1)
                                          Serial.println("Lightning out of range");
                                        else if (distance == 1)
                                          Serial.println("Distance not in table");
                                        else if (distance == 0)
                                          Serial.println("Lightning overhead");
                                        else {
                                          Serial.print("Lightning ~");
                                          Serial.print(distance);
                                          Serial.println("km away\n");
                                          Serial.print("Lightning Intensity: ");
                                          Serial.println(lightning_intensity);  
                                          send(msgDist.set(distance));
                                          send(msgInt.set(lightning_intensity));
                                        }
                                      }
                                      

                                      You have to change the sketch according to your module settings

                                      skywatchS Offline
                                      skywatchS Offline
                                      skywatch
                                      wrote on last edited by
                                      #52

                                      @alexsh1
                                      Is your example using I2C or SPI? I can't make it out.
                                      I'd guess I2C, but want to make sure first.....

                                      Thank you

                                      1 Reply Last reply
                                      0
                                      • skywatchS skywatch

                                        OK - finally got board, seems the problem was in the warehouse. I got email to say it had been sent and it never did. At least I can try it out soon and see how it compares to the current lightning sensors I use.

                                        NeverDieN Offline
                                        NeverDieN Offline
                                        NeverDie
                                        Hero Member
                                        wrote on last edited by NeverDie
                                        #53

                                        @skywatch said in Sketch for Lightning Sensor:

                                        see how it compares to the current lightning sensors I use.

                                        Please do let us know how it compares and which one you like the best.

                                        skywatchS 1 Reply Last reply
                                        0
                                        • NeverDieN NeverDie

                                          @skywatch said in Sketch for Lightning Sensor:

                                          see how it compares to the current lightning sensors I use.

                                          Please do let us know how it compares and which one you like the best.

                                          skywatchS Offline
                                          skywatchS Offline
                                          skywatch
                                          wrote on last edited by
                                          #54

                                          @neverdie Last night was the first lightning to test it out - 3 storm cells went through with hail and lightning, but nothing from the sensor :(

                                          So today I have rewired it, made some changes to the program and if we get lightning tonight I might have some news :)

                                          Nca78N 1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          5

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular