FireBeetle 2 ESP32-S3(N4) + DFRobot Gravity: Lightning Sensor

userHead pewu 2024-05-27 23:58:29 111 Views3 Replies



Do you have any experience in connecting FireBeetle 2 ESP32-S3(N4) to DFRobot Gravity: Lightning Sensor? Unfortunately, I try various combinations, but the detector does not respond even to interference. I run the code in the Arduino IDE. The code comes as below. I have tried various combinations of SDA, SCL, IRQ, but the detector does not respond. On the board I use the pins described as SDA and SCL. Despite this, it didn't work. Does the DFRobot_AS3935_I2C.h library not work with the microcontroller?




* @file DFRobot_AS3935_lightning_sensor_detailed.ino
* @brief SEN0290 Lightning Sensor
* @n This sensor can detect lightning and display the distance and intensity of the lightning within 40 km
* @n It can be set as indoor or outdoor mode.
* @n The module has three I2C, these addresses are:
* @n  AS3935_ADD1  0x01   A0 = 1  A1 = 0
* @n  AS3935_ADD2  0x02   A0 = 0  A1 = 1
* @n  AS3935_ADD3  0x03   A0 = 1  A1 = 1
* @copyright   Copyright (c) 2010 DFRobot Co.Ltd (
* @license     The MIT License (MIT)
* @author [TangJie]([email protected])
* @version  V1.0.2
* @date  2019-09-28
* @url

#include "DFRobot_AS3935_I2C.h"

volatile int8_t AS3935IsrTrig = 0;

#if defined(ESP32) || defined(ESP8266)
#define IRQ_PIN       0 
#define IRQ_PIN       2

// Antenna tuning capcitance (must be integer multiple of 8, 8 - 120 pf)
#define AS3935_CAPACITANCE   96

// I2C address
#define AS3935_I2C_ADDR       AS3935_ADD3

void AS3935_ISR();

DFRobot_AS3935_I2C  lightning0((uint8_t)IRQ_PIN);

void setup()

 Serial.println("DFRobot AS3935 lightning sensor begin!");


 while (lightning0.begin() != 0){

 // Configure sensor
 //set indoors or outdoors models

 //disturber detection

 #if defined(ESP32) || defined(ESP8266)
 attachInterrupt(/*Interrupt No*/0,AS3935_ISR,RISING);
 //set capacitance
 Serial.println("AS3935 manual cal complete");
// Enable interrupt (connect IRQ pin IRQ_PIN: 2, default)
//  Connect the IRQ and GND pin to the oscilloscope.
//  uncomment the following sentences to fine tune the antenna for better performance.
//  This will dispaly the antenna's resonance frequency/16 on IRQ pin (The resonance frequency will be divided by 16 on this pin)
//  Tuning AS3935_CAPACITANCE to make the frequency within 500/16 kHz ± 3.5%
//  lightning0.setLcoFdiv(0);
//  lightning0.setIRQOutputSource(3);

// Set the noise level,more than 7 will use the default value:2
 //uint8_t noiseLv = lightning0.getNoiseFloorLvl();

//used to modify WDTH,alues should only be between 0x00 and 0x0F (0 and 7)
 //uint8_t wtdgThreshold = lightning0.getWatchdogThreshold();

 //used to modify SREJ (spike rejection),values should only be between 0x00 and 0x0F (0 and 7)
 //uint8_t spikeRejection = lightning0.getSpikeRejection();

void loop()
 // It does nothing until an interrupt is detected on the IRQ pin.
 while (AS3935IsrTrig == 0) {delay(1);}
 // Reset interrupt flag
 AS3935IsrTrig = 0;
 // Get interrupt source
 uint8_t intSrc = lightning0.getInterruptSrc();
 if (intSrc == 1){
   // Get rid of non-distance data
   uint8_t lightningDistKm = lightning0.getLightningDistKm();
   Serial.println("Lightning occurs!");
   Serial.print("Distance: ");
   Serial.println(" km");

   // Get lightning energy intensity
   uint32_t lightningEnergyVal = lightning0.getStrikeEnergyRaw();
   Serial.print("Intensity: ");
 }else if (intSrc == 2){
   Serial.println("Disturber discovered!");
 }else if (intSrc == 3){
   Serial.println("Noise level too high!");
 //View register data

//IRQ handler for AS3935 interrupts
#if defined(ESP32) || defined(ESP8266)
void IRAM_ATTR AS3935_ISR()
void AS3935_ISR()
 AS3935IsrTrig = 1;



2024-06-08 04:52:03



Thank you for Your reply.


After connecting according to the sent diagram, the sensor does not react even to interference or noise. The sensor is functional because it works when connected to Arduino. However, I need to connect the sensor to the FireBeelte microcontroller.


1. Connecting the DFRobot Gravity Storm Sensor to the FireBeetle 2 ESP32-S3-U


 Pin Connections Based on the provided images and source code, below is the pin connection diagram for the storm sensor to the microcontroller:

- Connect the sensor's VCC (PWR) to 3.3V on the FireBeetle board.- Connect the sensor's GND to GND on the FireBeetle board.- Connect the sensor's SCL to the SCL pin (marked as T1 / ADC1_0 on the board diagram).- Connect the sensor's SDA to the SDA pin (marked as T2 / ADC1_1 on the board diagram).- Connect the sensor's IRQ to pin 0 on the FireBeetle board (marked as 0/D9 on the board diagram). Pin Definitions: The IRQ_PIN defined in the code as 0 corresponds to the pin marked as 0/D9 on the microcontroller board.The I2C pins (SCL and SDA) are already identified as T1 and T2 respectively on the board diagram.





userHeadPic pewu
2024-05-30 17:29:29

If you are using this code, you must connect IO2 of ESP32-S3 to IRQ. Since you did not define esp32, the code will go into else at the beginning of the code macro definition.


Also, can you share a screenshot of the serial monitor so that we can check if there is any setting problem.

userHeadPic Yeez_B
pewu wrote:

I slightly incorrectly gave a detailed description in response to my own post ;) Everything is described there, how I connect it.

2024-06-10 03:50:10
1 Replies