
The problem: The growing crisis of human-elephant conflict
For centuries, humans and elephants have shared landscapes, coexisting in a delicate balance. But today, that balance is breaking. Expanding cities, deforestation, and agricultural development are pushing elephants out of their natural habitats and into human settlements, leading to devastating consequences for both people and wildlife.
Imagine waking up in a rural village to find that an elephant has wandered onto your farmland overnight. Entire crops, representing months of hard labor and a family’s livelihood, are destroyed in minutes. For the elephants, the consequences are just as dire—villagers, desperate to protect their homes, resort to firecrackers, electric fences, and even lethal force to drive them away.
This isn’t just an isolated problem. In Sri Lanka, nearly 70 people and 300 elephants die every year due to these conflicts. In Kenya, elephants frequently raid crops and villages, creating tension with local communities. In Thailand, rapid urbanization is forcing elephants into closer contact with humans, intensifying conflicts.
We need a better way to protect both humans and elephants.
The solution: Smart tracking and geofencing to prevent conflict
What if we could predict and prevent human-elephant encounters before they happen?
This project introduces a real-time elephant tracking and geofencing system using Particle IoT, GPS, cloud storage, and solar power to:
- Monitor elephants in real time using GPS.
- Create virtual geofences that trigger alerts if an elephant moves into restricted areas.
- Send instant SMS notifications to rangers, giving them time to respond before a crisis occurs.
- Store location data in Firebase for analysis, helping researchers understand migration patterns.
- Display elephant locations on a live map so conservation teams can track movements easily.
- Power the entire system with solar energy, ensuring uninterrupted operation in remote areas.
This system gives conservationists, rangers, and local communities the power to act before a conflict happens—reducing harm to both humans and elephants.
Bill of materials
Hardware components
- Particle B524 SoM – Cellular IoT module for real-time tracking
- M.2 Evaluation Board – Breakout board for the B524 SoM
- RYS352A GPS Module – High-accuracy GPS tracking
- LiPo Battery (1800mAh) – For backup power
- 6V Solar Panels (x2) – For sustainable energy
- Solar Power Manager – Handles power distribution
- Custom 3D-printed enclosure – Protects components from weather and damage
Software and services
- Particle Workbench – To write and flash firmware
- Firebase Realtime Database – Stores and syncs tracking data
- Twilio – Sends SMS alerts when elephants leave safe zones
- OpenStreetMap (Leaflet.js) – Displays live tracking on a web interface
Step 1: Setting up the Particle B524 SoM
At the heart of this system is the Particle B524 SoM, a cellular IoT module designed for remote tracking applications. Since Wi-Fi is unavailable in the remote areas where elephants roam, cellular connectivity is the best option for real-time tracking.
Why the B524 SoM?
- Global cellular coverage with an integrated SIM, allowing tracking even in remote areas.
- Low power consumption, critical for a solar-powered device.
- Secure cloud connectivity using the Particle IoT platform.
Connecting the SoM to the M.2 Evaluation Board
- Attach the cellular antenna to the U.FL connector labeled CELL on the SoM.
- Align the B524 SoM with the M.2 NGFF connector on the Evaluation Board.
- Insert the module carefully into the connector and secure it with screws to prevent movement.
Setting up Particle Workbench
- Install Visual Studio Code.
- Install the Particle Workbench Extension from the VS Code Marketplace.
- Open VS Code and press
Ctrl+Shift+P
→ Select Particle: Create New Project. - Choose B524 SoM, set the firmware version, and begin coding.
Step 2: Setting up the GPS module
The RYS352A GPS module provides high-accuracy location tracking, ensuring that we can pinpoint an elephant’s location in real time.
Why this GPS module?
- Multi-GNSS support: Works with GPS, GLONASS, Galileo, and BeiDou for better accuracy.
- Advanced noise filtering: Reduces interference from nearby cellular signals.
- Compact and power-efficient: Ideal for battery-powered applications.
Wiring the GPS module to the SoM
GPS Module Pin | B524 SoM Pin | Description |
---|---|---|
TX | RX | Sends GPS data to SoM |
RX | TX | Receives commands from SoM |
3.3V | 3.3V | Power |
GND | GND | Ground |
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 minimize signal noise effectively.
Additionally, it includes enhanced components such as an 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:
- TX from GPS to RX on the SoM.
- RX from GPS to TX on the SoM.
- 3.3V from GPS to 3.3V on SoM
- GND from GPS to GND on SoM
TinyGPS++ library is used to parse the NMEA sentences coming from the module.
Code to fetch GPS coordinates
#include "Particle.h" #include <TinyGPSPlus.h> SYSTEM_MODE(AUTOMATIC); SYSTEM_THREAD(ENABLED); TinyGPSPlus gps; void printLatLng() { if (gps.location.isValid()) { Serial.print("Latitude: "); Serial.print(gps.location.lat(), 6); Serial.print(", Longitude: "); Serial.println(gps.location.lng(), 6); String locationMsg = String::format("%.6f,%.6f", gps.location.lat(), gps.location.lng()); Particle.publish("location", locationMsg); } } void setup() { Serial1.begin(115200); Serial.begin(); Particle.publish("status", "Device online and ready"); } void loop() { while (Serial1.available() > 0) { if (gps.encode(Serial1.read())) { printLatLng(); } } }
This code continuously fetches GPS coordinates and
publishes them to the Particle Cloud
.
Step 3: Storing and managing tracking data in Firebase
To make tracking data accessible across multiple devices, we use Firebase Realtime Database, which allows rangers to access real-time elephant locations from anywhere.
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:
Real-time synchronization: Data changes are propagated instantly to all connected devices.
Offline support: Firebase SDKs cache data locally, allowing apps to function offline and sync changes when reconnected.
Scalability: Firebase RTDB can handle large-scale applications with millions of users.
Setting up Firebase
Go to Firebase Console → Click Add Project.
Add Firebase to your web app and copy the config object.
Enable Realtime Database and set it to test mode.
Sending real-time location updates to Firebase
void loop() {
float lat = gps.location.lat();
float lng = gps.location.lng();
String data = String::format("{\"lat\": %f, \"lng\": %f}", lat, lng);
Particle.publish("put-location", data, PRIVATE);
delay(5000);
}
This publishes live GPS coordinates to Firebase every five seconds.
Step 4: Sending SMS alerts with Twilio
When an elephant crosses a geofence, rangers need immediate alerts. Twilio allows us to send real-time SMS notifications when an elephant moves into a restricted zone.
Setting up Twilio
- Go to Particle Console → Integrations → New Integration → Twilio.
- Enter your Twilio Account SID, Auth Token, and Phone Number.
- Set Event Name as
"twilio_sms_alert"
.
Code to send SMS alerts
void sendAlert() {
Particle.publish("twilio_sms_alert", "Elephant has left the geofenced area!", PRIVATE);
}
Now, when an elephant leaves the safe zone, rangers will receive instant notifications, allowing them to take action before a conflict occurs.
Step 5: Setting up solar power for continuous operation
Since this tracking system is designed to be deployed in remote locations, it needs a reliable and sustainable power source. Using solar energy ensures the device remains operational without human intervention for extended periods.
Why solar power?
- Sustainability – Harnessing solar energy eliminates the need for frequent battery replacements.
- Reliability – Ideal for deployment in conservation areas where access to electricity is impossible.
- Low maintenance – Once installed, the system runs autonomously.
Components needed for the solar power system
- 6V solar panels (x2) – Provide a steady charge throughout the day.
- Solar power manager module – Regulates power flow and prevents overcharging.
- 1800mAh LiPo battery – Stores excess energy for nighttime operation.
Wiring the solar power system
Component | Connection |
---|---|
Solar panels (connected in parallel) | To solar power manager input |
Solar power manager output | To LiPo battery |
LiPo battery | To M.2 Evaluation Board VIN pin |
Assembly process
- Connect the solar panels in parallel to increase the current output while maintaining voltage.
- Wire the panels to the solar power manager, ensuring they are securely connected.
- Connect the power manager to the LiPo battery, which will store energy for continuous operation.
- Connect the battery output to the M.2 Evaluation Board so it powers the SoM and GPS module.
Now, the device will charge during the day and run on battery power at night, ensuring uninterrupted elephant tracking.
Step 6: Designing a rugged enclosure for field deployment
To protect the system from rain, dust, and potential damage, we need a durable enclosure.
Features of the enclosure
- Weather-resistant – Protects electronics from environmental conditions.
- Ventilation – Allows heat dissipation to prevent overheating.
- Mounting points – Secures the device to trees or poles in conservation areas.
3D printing the enclosure
The enclosure consists of two parts:
- Top section – Holds the solar panels.
- Bottom section – Houses the electronics, including the GPS module, power manager, and evaluation board.
Steps to assemble the enclosure:
- Print the enclosure using PLA+ or ABS filament for durability.
- Mount the solar panels on the top section, securing them with weatherproof adhesive or screws.
- Secure the GPS module inside the bottom section to prevent movement.
- Connect all wires inside the enclosure and test the setup before sealing.
- Seal the enclosure with waterproof tape or silicone to protect against moisture.
Once the enclosure is fully assembled, it is ready for deployment in the field.
Step 7: Setting up real-time tracking with a web interface
Now that our system is tracking elephants and storing their locations in Firebase, we need a way to visualize the data. Using OpenStreetMap and Leaflet.js, we can build an interactive map that updates in real time.
Why OpenStreetMap?
- Free and open-source – No costly API fees.
- Customizable – Easy to add features like geofencing and route tracking.
- Offline-friendly – Works with preloaded maps if an internet connection is unavailable.
Setting up the web interface
- Create an HTML file and include Leaflet.js.
- Fetch real-time tracking data from Firebase using JavaScript.
- Update the map with the elephant’s latest location every few seconds.
Sample HTML and JavaScript for real-time tracking
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elephant Tracker</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-database.js"></script>
</head>
<body>
<div id="map" style="width: 100%; height: 500px;"></div>
<script>
// Initialize Firebase
var firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
databaseURL: "YOUR_DATABASE_URL",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
var database = firebase.database();
// Initialize map
var map = L.map('map').setView([0, 0], 5);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var marker = L.marker([0, 0]).addTo(map);
// Fetch real-time location updates
database.ref('elephants/elephantX/livelocation').on('value', function(snapshot) {
var data = snapshot.val();
if (data) {
var lat = data.lat;
var lng = data.lng;
marker.setLatLng([lat, lng]);
map.setView([lat, lng], 10);
}
});
</script>
</body>
</html>
Now, every time the elephant’s location updates in Firebase, the map will automatically refresh.
Step 8: Integrating geofencing and SMS alerts
To prevent elephants from straying into human settlements, we need to set up a geofence and send alerts when an elephant crosses the boundary.
Defining the geofence
A geofence is a virtual boundary defined by GPS coordinates. When an elephant enters or exits this boundary, we trigger an event.
Firebase structure for geofencing
{
"elephants": {
"elephantX": {
"geofence": {
"latitude": 10.12345,
"longitude": 35.67890,
"radius": 5000
},
"livelocation": {
"lat": 10.12456,
"lng": 35.67901
}
}
}
}
Code to check if an elephant crosses the geofence
#include <math.h>
#define EARTH_RADIUS 6371000 // Radius of Earth in meters
// Function to calculate distance between two coordinates
double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
double dLat = (lat2 - lat1) * M_PI / 180.0;
double dLon = (lon2 - lon1) * M_PI / 180.0;
lat1 = lat1 * M_PI / 180.0;
lat2 = lat2 * M_PI / 180.0;
double a = pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
return EARTH_RADIUS * c;
}
void loop() {
double geofenceLat = 10.12345;
double geofenceLon = 35.67890;
double geofenceRadius = 5000; // in meters
double currentLat = gps.location.lat();
double currentLon = gps.location.lng();
double distance = calculateDistance(geofenceLat, geofenceLon, currentLat, currentLon);
if (distance > geofenceRadius) {
Particle.publish("twilio_sms_alert", "Elephant has left the geofenced area!", PRIVATE);
}
delay(5000);
}
Now, when the elephant moves beyond the geofence, an SMS alert is sent to rangers via Twilio.
Conclusion
This real-time elephant tracking system is not just a piece of technology—it is a life-saving tool that can help conservationists protect both elephants and humans. By combining IoT, solar power, GPS tracking, and real-time alerts, we provide a proactive approach to wildlife conservation.
This system can be adapted for other species facing similar challenges, making it a versatile solution for conservation efforts worldwide.