Forest Guard: A LoRa Based Decentralized Edge-AI Mesh Network for Forest Monitoring
Protecting Forests Where the Internet Cannot Reach
Forests are the lungs of our planet, yet they remain vulnerable to poaching, illegal logging, and devastating wildfires. Remote regions are often unmonitored because they lack infrastructure, no cellular coverage, no internet, and no reliable power. Traditional solutions depend on towers, GSM networks, or satellite links, all of which are either unreliable or prohibitively expensive in deep forest zones.
Forest Guard redefines forest monitoring with a self-sustaining, decentralized, and intelligent mesh network that brings security where no traditional network can.
What Makes Forest Guard Different?
Instead of relying on costly connectivity, our system builds a solar-powered sensor mesh using LoRa Meshtastic. Each node is intelligent at the edge, capable of running AI models locally to detect events like gunshots via an onboard microphone and Edge Impulse classification. Coupled with environmental sensors and a smoke detector, the system can issue real-time alerts about fire outbreaks or human intrusion.
When an anomaly is detected, the alert propagates through the LoRa mesh to a gateway node, which syncs with the cloud when internet is available. The data is visualized on a web-based dashboard, showing sensor activity, live alerts, and precise node locations on a map.
This means no single point of failure, no dependency on fragile infrastructure, and the ability to scale across vast landscapes with just low-power radios and the sun.
Why It Matters
- Early Fire Detection - Prevent small sparks from becoming catastrophic forest fires.
- Anti-Poaching & Logging Defense - Gunshot detection provides actionable intelligence for rangers.
- Sustainable Design - Fully solar-powered nodes with custom PCBs for durability.
- Decentralized & Resilient - Operates even without internet; data flows peer-to-peer until a gateway is reached.
- Community & Conservation Impact - Helps safeguard biodiversity, human settlements, and natural heritage.
This ensures ruggedness, consistent quality, and rapid deployment of multiple nodes, transforming our prototype into a scalable, field-ready system.
The Big Picture
Forest Guard isn’t just a hardware project; it’s a blueprint for protecting forests worldwide. By combining edge AI, mesh networking, and sustainable power, we deliver a system that communities, conservationists, and governments can deploy today to build a safer, greener tomorrow.




MyLists | DigiKey - Forest Guard Supplies
Components For 1x Node Unit:
- 1x Custom Node PCB
- 1x Gravity: Multifunctional Environmental sensor
- 1x Gravity: GNSS Sensor
- 1x Fermion: I2S MEMS Microphone
- 1x Fermion: MEMS Smoke Detection Sensor
- 1x RP2040 LoRa with Type C adapter
- 1x Li-Po Battery
- 1x 70x70mm Solar Panel
- 8x M3x10mm Screws











Components For 1x Gateway Unit:
- 1x Arduino Uno R4 WiFi
- 1x Fermion: 3.5” 480x320 TFT LCD Display
- 1x RP2040 LoRa
- 1x Li-Po Battery
- 1x Micro Push Switch
- 4x M2x5mm Screws
- 1x 3V Buzzer




Tools
- 3D Printer (for enclosures and mounting parts)
- Soldering Kit (iron, solder wire, flux, wick)
- Screwdriver Kit (for M2/M3 hardware)
Step 1: PCB Design

Designing the Forest Guard PCB was the very first milestone in this project.
I am not a professional PCB designer, but with hands-on experience in electronics and by studying references from existing ESP32-S3 development boards, I created a custom PCB in EasyEDA that integrates:
- ESP32-S3 as the main controller
- Battery management and charging circuit
- Type-C USB for programming/power
- Headers for plugging in LoRa module and sensors
The PCB design files (Gerber + BOM) are available on my GitHub repository:
👉 Forest-Guard GitHub Repository
To bring this design to life, I got 5× PCBs fabricated and 2× fully assembled boards (with SMD assembly for ESP32-S3, battery & power management, Type-C, etc.) manufactured by NextPCB. The sensors and LoRa modules are later mounted as through-hole or header components.
This combination gave me the flexibility to test multiple prototypes, while the assembled PCBs saved me time and ensured professional quality soldering of fine-pitch SMD parts.








Step 2: Meshtastic Setup on RP2040 LoRa
We’ll flash the Meshtastic firmware onto the RP2040 LoRa modules and configure them for UART communication.
⚠️ Important Safety Note:
Always connect the antenna before powering on the LoRa module to prevent damage.




1. Flashing Meshtastic Firmware
- Go to Meshtastic Downloads.
- Click Go to Flasher.
- Select Target Device: RP2040 LoRa.
- Choose a version → click Flash → then Continue.
- Download the .UF2 firmware file.


2. Upload Firmware to RP2040
- Press and hold the BOOT button on the module.
- While holding BOOT, connect the USB Type-C cable to your PC.
- A new drive named RP2 will appear.
- Copy the downloaded .UF2 file into the RP2 drive.
- Once copied, press the RESET button.
- The device will reboot with the new firmware.




3. Connect to Meshtastic Client
- Open Meshtastic Client.
- Click New Connection.
- Select Serial.
- Click New Device → choose the COM port where your module is connected.
- You should now see the Meshtastic Node Page.




4. Configure LoRa Region
- Go to Config → LoRa.
- Set the Region according to your country’s LoRa regulations.

5. Configure Serial UART
- Go to Module Config → Serial.
- Enable Serial Output.
- Set pins:
- Receive Pin (RX): 8
- Transmit Pin (TX): 9
- Save by clicking the top-right save button.


This configures the module to communicate via UART with external devices.
6. Repeat for All Modules
Repeat the above steps for every LoRa module you plan to use in your project.
Step 3: PCB Assembly

With the custom PCB manufactured, the next step is to carefully solder the sensor modules and communication hardware onto the board.
Components to Solder
- Gravity: Multifunctional Environmental Sensor
- Fermion I²S MEMS Microphone
- Fermion MEMS Smoke Detection Sensor
- RP2040 LoRa Module with Type-C Adapter
Prepare the Workspace
- Use a clean, static-free surface.
- Preheat your soldering iron to around 350 °C (for leaded solder) or 370–380 °C (for lead-free).
- Have tweezers and flux ready to handle small pins.
Solder Components One by One
- Begin with the smallest modules (sensors) first MEMS microphone and Smoke sensor..
- Than carefully align the Environmental sensor and solder the I²C pins.
- Finally, solder the LoRa module.
- Double-check pin alignment before applying solder. Incorrect orientation can damage the modules.
Continuity Testing
- After soldering each module, use a multimeter in continuity mode.
- Probe between the module pin and the corresponding PCB pad/trace.
- A beep or zero-resistance confirms proper connectivity.







Step 4: Node CAD Design and 3D Printing
To make the Forest Guard Node truly field ready, I designed a custom enclosure in Fusion 360. This was done by first importing all the standard components and then exporting the PCB’s 3D model from EasyEDA into Fusion 360, ensuring that every cutout and mount point lined up perfectly.
Enclosure Features
The Node enclosure is made up of multiple parts:
- Housing - Holds the custom PCB, with cutouts for the Type-C port, push switch, and top-mounted LoRa antenna. A large center cutout allows light from the onboard RGB LED to pass through.
- Diffuser - A dedicated piece that diffuses the RGB LED light, making it visible in the field without being harsh.
- Cover - Designed to mount the solar panel on top and provide space for the GNSS sensor.
- Mount & Clip Set - Allows the node to be attached securely to trees, walls, or other structures.
The enclosure is secured with 12× M3 screws, giving it the feel and robustness of a professional product enclosure.






3D Printing
I printed the parts on a Bambu Labs P1S 3D printer:
- Housing and cover were printed in light gray PLA for durability and aesthetics.
- Diffuser was printed in pure white PLA to achieve soft light diffusion from the RGB LED.
Files for You
- STL files - Ready-to-print files for direct 3D printing.
- Fusion 360 design file - For anyone who wants to modify or customize the design further.
Forest Guard Tx Fusion 360 File



Step 5: Diffuser and Light Visor Assembly
To make the RGB LED indicator and environmental sensor light input effective, we add a diffuser and a light visor to the node housing. This ensures the LED glow is soft and visible in the field, while the environmental sensor gets accurate light readings without interference.
Parts Needed
- Housing
- Diffuser
- Small piece of clear plastic (cut from packaging or acrylic sheet)
- Quick glue (super glue or instant adhesive)
Attach the Diffuser
- Apply a thin line of quick glue around the Diffuser cutout in the housing.
- Carefully snap the diffuser into place as shown (it should align flush with the cutout).
- Hold gently for a few seconds until the glue sets.






Install the Clear Plastic Visor
- Locate the cutout for the Environmental Sensor light input.
- Apply a small amount of quick glue around the edges of this cutout.
- Place the clear plastic piece over the opening. This acts as a protective window and ensures correct light transmission for the sensor.


Step 6: Solar Wire Soldering
- Cut two wires, each about 10 cm long (one red, one black).
- Solder the red wire to the + pad on the back of the battery connector.
- Solder the black wire to the – pad.



Step 7: Housing Assembly
- Take the assembled PCB, housing, battery, and the LoRa antenna.
- First, connect the antenna to the LoRa module.
- ⚠️ Never power on without the antenna connected.
- Connect the battery to the PCB.
- Place the PCB inside the housing, aligning the Type-C port with the cutout.
- Secure the PCB using 4× M3 screws.
- Unscrew the antenna, pass it through the top housing hole, and screw it back in place.
- Finally, use double-sided tape to fix the battery to the back of the PCB.










Step 8: Solar Pannel Assembly
- Take the solar panel, cover, and quick glue.
- Align the solar panel with the cutout on the cover and snap it into place.
- From the back side of the cover, locate the four holes.
- Apply a small amount of quick glue into each hole to secure the panel firmly.
- Let it sit for a few minutes to allow the glue to set fully.




Step 9: Cover Assembly
- Take the cover and the GNSS sensor module.
- Connect the GNSS antenna to the GNSS module.
- Place the module over the mounting holes on the cover.
- Secure the module using 4× M3 screws.
- Use double-sided tape to secure the antenna on the cover so it stays in place.






Step 10: Final Connections
Take the Housing Assembly and the Cover Assembly.
Use the 4-pin connector that came with the GNSS sensor:
- Cut the connector in half using a cutter.
- Plug one side into the GNSS sensor.
- Strip the wires on the other side and solder them to the PCB as follows:
- Red to 3V3
- Black to GND
- Green to SDA
- Blue to SCL
Now connect the solar wires coming from the PCB to the solar panel:
- Black to –
- Red to +
Double-check all connections before powering on.







Step 11: Final Assembly
- Take the assembled housing and the assembled cover.
- Carefully align the cover on top of the housing.
- ⚠️ Make sure no wires get pinched during this step.
- Once aligned, snap the cover into place.
- Use 4× M3 screws to securely fasten the cover to the housing.
Now your Forest Guard Node is fully assembled and ready for field testing!



Step 12: Pre-Requisite to Program Node (Edge Impulse)

Before uploading the final Node firmware, we need to prepare the machine learning (ML) model that runs locally on the ESP32-S3. This is done using Edge Impulse, a powerful platform for developing and deploying ML models directly to embedded devices.
What is Edge Impulse?
Edge Impulse is an edge AI development platform that makes it simple to:
- Collect and label sensor data (audio, vibration, environmental, camera, etc.).
- Train ML models using classical algorithms or neural networks.
- Optimize models for low-power microcontrollers like ESP32, RP2040, and STM32.
- Generate ready-to-use Arduino libraries that can be imported directly into your Node firmware.
This enables us to bring AI directly to the forest, without needing internet access or cloud inference — the model runs entirely on the Node itself.
Audio Classification for Gunshot Detection
For this project, we focus on audio classification using the onboard MEMS microphone:
- Data Collection
- Record short audio clips of gunshots and background forest sounds (wind, birds, insects, etc.).
- Upload these samples into your Edge Impulse project.
- Feature Extraction
- Edge Impulse automatically converts raw audio into spectrograms (MFCCs), which represent the frequency patterns of the sound.
- This allows the model to detect unique signatures of gunshot sounds compared to other noises.
- Model Training
- A classification model is trained to output labels like:
- "gunshot"
- "background"
- The model learns the difference in frequency and amplitude patterns.
- A classification model is trained to output labels like:
- Deployment
- Once trained and tested, export the model as an Arduino library.
- Include this library in your Node code.
- The ESP32-S3 runs the inference on its second core, ensuring real-time classification without blocking sensor updates or LoRa communication.
Why This Matters
This setup means that every Node becomes an intelligent sentinel:
- Capable of hearing gunshots in the forest.
- Making real-time decisions without cloud dependency.
- Sending alerts through the LoRa mesh instantly.
And importantly, this is just the beginning — with Edge Impulse, you can retrain the model on other audio events like chainsaws (illegal logging) or calls of endangered animals, making the Forest Guard system highly adaptable and future-proof.
Create Edge Impulse Project


To train and deploy your ML model, you first need to set up a project in Edge Impulse Studio.
Create a Project
- Open Edge Impulse Studio.
- Login with your account credentials.
- Click on “Create New Project”.
- Give your project a meaningful name, e.g., Forest Guard Gunshot Detector.

Get Your Project Key
- After the project is created, go to Dashboard → Keys.
- Locate your Project API Key.
- Copy this key and keep it handy — you’ll need it in the Flask tool and Node code to connect data and models to Edge Impulse.

Step 13: Challenge to Collect Data
One of the biggest hurdles when working with Edge Impulse is data collection, especially for audio and image inputs. While numeric sensor streams (like temperature or humidity) can be pushed directly via serial, Edge Impulse currently doesn’t allow us to easily stream raw audio or image frames from the ESP32 to their platform in the same fast-forward way.
This means we normally have to:
- Log data to an SD card.
- Remove the card.
- Copy files to the computer.
- Upload them manually to Edge Impulse.
This process quickly becomes tedious when collecting hundreds of samples.
My Solution: Flask Data Uploader
To make this seamless, I built a Flask-based desktop tool that bridges the ESP32 and Edge Impulse:
- ESP32 Data Firmware
- First, flash a simple Arduino sketch onto the ESP32 that streams audio (from the microphone) or images (from a camera) over Serial USB.
- Flask App
- On the PC side, run my Flask tool.
- It listens to the ESP32’s serial port and captures the incoming raw data.
- Using your Edge Impulse API key, the tool automatically uploads this data into your project.
- Benefits
- No need for SD cards or manual file transfers.
- Data is organized and labeled as it’s uploaded.
- Faster iteration when training models with new samples.
Step 14: ESP32 Audio Serial Code
Before we can collect and upload audio samples into Edge Impulse, we need the ESP32-S3 to stream raw microphone data over Serial USB. This is done by flashing a small Arduino sketch that continuously records from the I²S microphone and sends the audio buffer to the PC.
Install the ESP32 Board Package (Board Manager)
- Open Arduino IDE → File → Preferences.
- In Additional Boards Manager URLs, add:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json- Click OK.
- Go to Tools → Board → Boards Manager….
- Search “ESP32” and install esp32 by Espressif Systems (latest).


Tip: After install, restart Arduino IDE if the boards list doesn’t refresh.
- Open the provided esp32_audio_serial.ino sketch into Arduino IDE.
- This code initializes the microphone, records a buffer, and streams it line-by-line over Serial.
- Inside the sketch, you’ll see a configurable parameter:
constexpr int SECONDS_TO_GRAB = 10;Change this value if you want longer or shorter recordings.
Default is 10 seconds per sample.
- Go to Tools → Board → ESP32 → DFRobot FireBeetle 2 ESP32-S3.
- Connect your ESP32-S3 to the PC with USB-C.
- Under Tools → Port, choose the correct COM port.
- Under Tools → USB CDC On Boot → Enable
- Click Upload to flash the code onto your ESP32-S3.


Step 15: Run Flask Tool
Now that your ESP32-S3 is streaming microphone data over Serial, let’s use the Flask Data Tool to capture it and upload directly into your Edge Impulse project.
Setup the Flask Tool
- Download the project repository:
- 👉 Forest-Guard GitHub Repository
- Open the Edge Impulse Data Tool folder.
- Run the Flask app:
python app.py(File path: Edge Impulse Data Tool/app.py)

Access the Web Interface
- Once the server is running, open your browser and go to:
- http://127.0.0.1:5000/
- You will see the data collection dashboard.

Collect Audio Data
- Select COM Port → Choose the port where your ESP32 is connected.
- Paste API Key → Enter your Edge Impulse project API key (from Step 14).
- Choose Mode → Select whether this sample is for training or testing.
- Enter Label → e.g., gunshot or background.
- Select Data Type → Choose Audio.
- Click Capture → Recording will begin.
- The Node LED will glow green while audio is being recorded.
- Once the LED turns off, the captured audio file is automatically uploaded to your Edge Impulse project.
You should now see your labeled audio samples appear inside the Edge Impulse Studio → Data Acquisition tab. From here, you can repeat the process to build up your dataset of gunshots and background noise.

Step 16: Collect Data
Now that the Flask tool is ready and connected to Edge Impulse, it’s time to build our training dataset. A good dataset is the most important factor for achieving a reliable classification model.

Collect Background Noise Data
- Set the label flag to Noise.
- Start recording samples in different environments:
- Indoors → quiet rooms, fan noise, people talking.
- Outdoors → wind, birds, insects, cars, etc.
- Collect at least 120 seconds of audio in each scenario.
- The more variety, the better the model can tell background noise apart from gunshots.

Collect Gunshot Data
- Set the label flag to Gun.
- Play different gunshot audio samples (different calibers, environments, echo levels).
- Record up to 120 seconds of audio in total.
Using multiple gunshot sound samples with slightly different characteristics helps the model generalize better to real-world scenarios.

To make sure the model is reliable:
- Split your dataset 80:20 → 80% for training, 20% for testing.
- Edge Impulse automatically suggests the split, but you can also move samples manually if needed.
Tips for Better Results
- Collect data at different volumes and distances.
- Try to balance the number of Noise and Gunshot samples.
- Keep background data diverse — this prevents false positives.
Step 17: Split Data
Right now, each recorded audio sample is 10 seconds long. For better accuracy, we need to split these into smaller 1-second samples that can be used as training features in Edge Impulse.
Splitting Process in Edge Impulse
- In Edge Impulse Studio, go to the Data Acquisition tab.
- Find one of your 10-second audio samples (either Noise or Gunshot).
- Click on the three dots (…) menu next to the sample.
- Choose Split Sample.
- Use the tool to crop each segment into 1-second chunks.
- Example: a 10-second audio file becomes 10× 1-second samples.
- For gunshot recordings, isolate the exact segment of the shot to ensure the model learns the event clearly.
- Click Split to save.

Continue: Forest Guard Part 2