Overview

This project demonstrates how to build a real-time elephant tracking system using the Particle B Series SoM. The system enables live GPS tracking of elephants and implements geofencing to notify forest rangers if the animal leaves a predefined boundary. Data is displayed on a web interface with OpenStreetMap integration and stored in Firebase for analysis.

Motivation

The tragic loss of a 40-year-old man in our locality due to a wild elephant attack has deeply shaken our community. This heartbreaking incident is not isolated; it reflects a growing global crisis of human-elephant conflicts that threaten both human lives and the survival of these majestic animals. Such conflicts are becoming increasingly frequent, highlighting the urgent need for innovative solutions to mitigate these encounters and foster coexistence.

In many regions around the world, human-elephant conflicts have reached alarming levels, often resulting in devastating consequences such as crop destruction, property damage, and the loss of both human and animal lives. For instance:

These incidents underscore the critical need for sustainable and humane solutions to address human-elephant conflicts. This project aims to contribute to such efforts by developing an elephant tracking and geofencing system powered by advanced IoT technology

Key Features

Setting Up the Particle B Series SoM

The B-SoM module serves as the heart of this project, tailored for cellular IoT applications. It is Particle's flagship IoT module, designed to work seamlessly with the Particle IoT Platform-as-a-Service, which offers free usage for up to 100 devices. Additionally, it includes a global embedded SIM card and data plan, ensuring reliable cellular connectivity worldwide.

We specifically chose the B524 SoM for this project due to its robust cellular connectivity, as Wi-Fi is not a feasible option in remote wildlife areas. The cellular capability ensures uninterrupted communication, even in challenging outdoor environments where other connectivity options are unavailable.

DSC01959.JPG

To fully harness the capabilities of the B524 SoM, the M.2 Evaluation Board is an essential tool. This breakout board simplifies development and streamlines prototyping, enabling seamless access to the full potential of the module. The board includes USB ports for both the nRF52840 MCU and the cellular modem, an SD card connector, an Ethernet connector, a barrel jack power connector, buttons, an RGB LED, a charge status LED, and a connector for a LiPo battery (battery not included).

DSC01962.JPG

Here is how we connect the B524 SoM to the Eval Board.

DSC01887.JPG

To utilize the full capabilities of the B524 SoM with the Particle platform, you’ll need to set up your Particle.io account and configure your device. Follow the steps below:

1. Access the Particle Setup Website:

Starting_page.png

2. Log Into Your Particle Account:

3. Select Your Device:

Select device.png
upadte.png

4. Organize your Particle device

Organize.png
image.png

5. Complete the Setup:

image.png

Particle Workbench

Work_Bench.png

Particle Workbench is an advanced development environment that integrates with Visual Studio Code, making it easy to write, compile, and debug firmware for the B524 SoM. Here’s how you can set it up:

1. Install Visual Studio Code

2. Install Particle Workbench Extension

3. Set Up Your Project

Preparing the GPS Module

DSC01971.JPG
DSC01975.JPG
reyax pin.png

For this project, we used the RYS352A GPS module for precise location tracking. The specifications of the module are below.

The RYS352A module features a 3.3V UART connection, allowing seamless communication with microcontrollers. It supports multiple GNSS systems, including GPS, GLONASS, Galileo, BeiDou, QZSS, and SBAS, providing high-accuracy location data. The module integrates 12 multi-tone active interference cancellers to effectively minimize signal noise.

Additionally, it includes enhanced components such as a SAW filter, LNA (Low-Noise Amplifier), and TCXO (Temperature-Compensated Crystal Oscillator) for superior signal processing. The embedded GPS/GLONASS/BeiDou antenna ensures consistent satellite signal reception. With an RTC (Real-Time Clock) battery backup, the module can maintain time even when powered off. It also delivers a maximum navigation update rate of 10Hz, making it suitable for high-speed tracking applications.

Connect the Reyax GPS module to the Particle B Series SoM:

TinyGPS++ library is used to parse the NMEA sentences coming from the module.

Here is the sample code for fetching your latitude and longitude.

// Include required libraries
#include "Particle.h"
#include <TinyGPSPlus.h>
// System configuration
SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);
// Global variables
TinyGPSPlus gps;
// Function to print only latitude and longitude
void printLatLng() {
if (gps.location.isValid()) {
// Print latitude and longitude to Serial
Serial.print("Latitude: ");
Serial.print(gps.location.lat(), 6);
Serial.print(", Longitude: ");
Serial.println(gps.location.lng(), 6);
// Optionally publish to cloud
String locationMsg = String::format(
"%.6f,%.6f",
gps.location.lat(),
gps.location.lng()
);
Particle.publish("location", locationMsg);
}
}
void setup()
{
// Initialize GPS on Serial1
Serial1.begin(115200);
// Initialize USB serial for output
Serial.begin();
// Notify device is ready
Particle.publish("status", "Device online and ready");
}
void loop()
{
// Read GPS data
while (Serial1.available() > 0) {
if (gps.encode(Serial1.read())) {
printLatLng();
}
}
// Check for GPS signal timeout
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println("No GPS data received: check wiring");
Particle.publish("error", "No GPS data received");
delay(1000);
}
}

If the GPS obtains a fix, it will display as follows.

gps_output.png

Setting Up Firebase Real-Time Database

Firebase Real-Time Database is a NoSQL database that stores data as JSON objects. It synchronizes data in real-time across all connected clients, ensuring that every user sees the same data at the same time. Key features include:

Setting Up a Firebase Project

1. Create a Firebase Project:

2. Add Firebase to Your App:

Enabling Firebase Realtime Database

1. Navigate to Real-Time Database:

2. Create a Database:

3. Database URL

4. Firebase Project ID:

The Firebase Project ID is a unique identifier for your Firebase project. It distinguishes your project from others and is required when making API calls or configuring Firebase services.

From the Firebase Console:

From the Firebase Configuration Object:

When you add Firebase to your app, Firebase provides a configuration object. This object contains the projectId field.

const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_AUTH_DOMAIN",
  projectId: "YOUR_PROJECT_ID", // This is your Firebase Project ID
  storageBucket: "YOUR_STORAGE_BUCKET",
  messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
  appId: "YOUR_APP_ID"
}; 

5. Firebase Auth Token (Firebase Database Secret)

The Firebase Database Secret is a legacy authentication mechanism for the Firebase Realtime Database. It is a long, randomly generated string that grants full read and write access to your entire database. It was primarily used for server-side applications or tools that needed unrestricted access to the database.

Go to the Firebase Console:

Navigate to Project Settings:

Access the Database Secret:

Database Structure and Data Model

Firebase Real-time Database stores data as a JSON tree. Each node in the tree can contain key-value pairs or nested child nodes.

This is the database structure that we use:

{
  "elephants": {
    "elephantX": {
      "geofence": {
        "coordinates": "latitude1,longitude1|latitude2,longitude2|latitude3,longitude3|..."
      },
      "livelocation": {
        "lat": "latitudeX",
        "lng": "longitudeX"
      },
      "locations": {
        "uniqueLocationId1": {
          "latitude": "latitudeValue1",
          "longitude": "longitudeValue1",
          "timestamp": "timestampValue1"
        },
        "...": {
          "latitude": "latitudeValueN",
          "longitude": "longitudeValueN",
          "timestamp": "timestampValueN"
        }
      }
    },
    "elephantY": {
      "geofence": {
        "coordinates": "latitude1,longitude1|latitude2,longitude2|latitude3,longitude3|..."
      },
      "livelocation": {
        "lat": "latitudeY",
        "lng": "longitudeY"
      },
      "locations": {
        "uniqueLocationId1": {
          "latitude": "latitudeValue1",
          "longitude": "longitudeValue1",
          "timestamp": "timestampValue1"
        },
        "...": {
          "latitude": "latitudeValueN",
          "longitude": "longitudeValueN",
          "timestamp": "timestampValueN"
        }
      }
    }
  }
}

Setting Up Particle Integration with Firebase

Particle provides a built-in integration for Firebase, allowing you to send data directly to the Firebase Realtime Database.

We need 3 different integrations between Particle And Firebase to

1. Get Geo-fence Data from Firebase to Particle

This integration involves fetching geofence data (e.g., boundary coordinates) from Firebase and sending it to the Particle device.

Create a Firebase Integration in Particle Console:

Particle Firmware Code:

#include "Particle.h"

void setup() {
  Serial.begin(9600);
  Particle.subscribe("hook-response/get-geofence", handleGeofenceData, MY_DEVICES);
}

void loop() {
 // Request geofence data every 10 seconds
  Particle.publish("get-geofence");
  delay(10000);
}

void handleGeofenceData(const char *event, const char *data) {
  Serial.println("Geofence Data:");
  Serial.println(data);
}

2. Put Real-time Location from Particle to Firebase

This integration involves sending real-time location data from the Particle device to Firebase using a PUT request.

Create a Firebase Integration in Particle Console:

Particle Firmware Code:

#include "Particle.h"

void setup() {
  Serial.begin(9600);
}

void loop() {
 // Simulate location data
 float lat = 37.7749 + (random(100) / 1000.0);
 float lng = -122.4194 + (random(100) / 1000.0);
  String data = String::format("{\"lat\": %f, \"lng\": %f, \"timestamp\": %d}", lat, lng, Time.now());

 // Send location data
  Particle.publish("put-location", data, PRIVATE);
  delay(5000); // Send data every 5 seconds
}

3. Post Real-time Location from Particle to Firebase

This integration involves sending real-time location data from the Particle device to Firebase using a POST request to create a location history.

Create a Firebase Integration in Particle Console:

Particle Firmware Code:

#include "Particle.h"

void setup() {
  Serial.begin(9600);
}

void loop() {
 // Simulate location data
 float lat = 37.7749 + (random(100) / 1000.0);
 float lng = -122.4194 + (random(100) / 1000.0);
  String data = String::format("{\"lat\": %f, \"lng\": %f, \"timestamp\": %d}", lat, lng, Time.now());

 // Send location data
  Particle.publish("post-location", data, PRIVATE);
  delay(5000); // Send data every 5 seconds
}

Integrating Twilio For SMS Alerts

Integrating Twilio with a Particle device allows you to send SMS alerts directly from the BSoM, making it ideal for applications where immediate notifications are crucial, such as in alert systems. Follow these steps to set up and integrate Twilio with your BSoM for sending SMS alerts.

Set Up a Twilio Account and Get Your Credentials

Set Up a Twilio Integration in the Particle Console

Parameters: Set up parameters fields as follows:

Form Data: Set up form data fields as follows:

Website

The Elephant Geofence webpage serves as a sophisticated and user-friendly interface for monitoring elephant movement, managing geofence zones, and analyzing location data. Designed for conservationists, researchers, and field personnel, it provides a seamless blend of functionality and intuitive design. Key functionalities include

Real-Time Tracking

Geofence Management

Location History

Technologies Used

Frontend

Backend Integration

1. Firebase Realtime Database:

2. JavaScript: Handles geofence creation, saving/loading functionalities, and map interaction.

Solar Power Setup

The project utilizes a solar power system comprising two 6V solar panels.

DSC02000.JPG

These panels will be connected to the solar power manager.

DSC01991.JPG

It is a high-efficiency solar power management module specifically designed for 5V solar panels. Featuring advanced MPPT (Maximum Power Point Tracking) technology, it maximizes solar panel efficiency and can provide up to 900mA charging current for 3.7V Li batteries through USB or solar panel inputs. The module includes controllable DC-DC converters with 5V 1A output, making it versatile for various solar power and low-power applications. Its comprehensive protection mechanisms safeguard the battery, solar panel, and output circuits, significantly enhancing the stability and safety of solar projects.

To power up the Eval Board we used an 1800mAh lipo battery.

DSC01985.JPG

Enclosure

We designed a custom enclosure using Fusion 360 to protect and house the device's components effectively. The enclosure has two parts: the upper section, which holds the solar panels, and the bottom section, which accommodates the charge controller, battery, and other electronics.

Collar v27.png

These parts are 3d printed with the PLA+

DSC02009.JPG

Assembly

First, we securely mounted the solar panels, connecting them in parallel to enhance the current output.

DSC02013.JPG

Next, we positioned the GPS module and connected it to the evaluation board using male-to-female jumper wires.

DSC02019.JPG
DSC02020.JPG

Then, we connected the charge controller to the battery and the evaluation board's VIN pin, as it supports an input voltage range of 5V to 12V.

DSC02028.JPG

Finally, we attached the solar panel wires to the charge controller, completing the entire assembly.

DSC02039.JPG
DSC02044.JPG

Final Testing and Deployment

This project showcases an efficient and sustainable solution for wildlife monitoring, leveraging IoT, GPS, and renewable energy technologies to ensure the safety of elephants and their natural habitats