Circuit Documentation
Summary
This circuit is a GPS tracker system that uses an ESP32C3 microcontroller to interface with a GPS NEO 6M module and a SIM900A Mini module. The system is powered by a 3.7V LiPo battery. The ESP32C3 reads GPS data and sends SMS alerts if the tracked object moves outside a predefined safe zone.
Component List
ESP32C3 Supermini
- Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: GPIO05, GPIO06, GPIO07, GPIO08, GPIO09, GPIO10, GPIO20, GPIO21, GPIO00, GPIO01, GPIO02, GPIO03, GPIO04, 3.3V, GND, +5V
GPS NEO 6M
- Description: A GPS module used to obtain location data.
- Pins: VCC, RX, TX, GND
SIM900A Mini
- Description: A GSM module used to send SMS alerts.
- Pins: VCC, DTR, TX, RX, SPK, MIC, RST, GND
3.7V LiPo
- Description: A rechargeable lithium polymer battery used to power the circuit.
- Pins: +Ve, GND
Wiring Details
ESP32C3 Supermini
- GPIO09 is connected to RX of GPS NEO 6M.
- GPIO10 is connected to TX of GPS NEO 6M.
- GPIO01 is connected to RX of SIM900A Mini.
- GPIO03 is connected to TX of SIM900A Mini.
- 3.3V is connected to +Ve of 3.7V LiPo, VCC of GPS NEO 6M, and VCC of SIM900A Mini.
- GND is connected to GND of 3.7V LiPo, GND of GPS NEO 6M, and GND of SIM900A Mini.
GPS NEO 6M
- RX is connected to GPIO09 of ESP32C3 Supermini.
- TX is connected to GPIO10 of ESP32C3 Supermini.
- VCC is connected to 3.3V of ESP32C3 Supermini and +Ve of 3.7V LiPo.
- GND is connected to GND of ESP32C3 Supermini and GND of 3.7V LiPo.
SIM900A Mini
- RX is connected to GPIO01 of ESP32C3 Supermini.
- TX is connected to GPIO03 of ESP32C3 Supermini.
- VCC is connected to 3.3V of ESP32C3 Supermini and +Ve of 3.7V LiPo.
- GND is connected to GND of ESP32C3 Supermini and GND of 3.7V LiPo.
3.7V LiPo
- +Ve is connected to 3.3V of ESP32C3 Supermini, VCC of GPS NEO 6M, and VCC of SIM900A Mini.
- GND is connected to GND of ESP32C3 Supermini, GND of GPS NEO 6M, and GND of SIM900A Mini.
Documented Code
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps; // GPS object to parse data
// Define serial communication pins for SIM900A and GPS
SoftwareSerial sim900Serial(10, 12); // RX, TX for SIM900A Mini
SoftwareSerial gpsSerial(5, 6); // RX, TX for GPS Neo-6M
// Define the safe zone coordinates (latitude, longitude)
const double safeLatitude = 37.7749; // Example: San Francisco latitude
const double safeLongitude = -122.4194; // Example: San Francisco longitude
const float safeRadius = 100.0; // Safe radius in meters
// Parent phone number to send SMS alert
const char phoneNumber[] = "+917020961222"; // Replace with parent's phone number
void setup() {
// Start serial communication
Serial.begin(115200);
sim900Serial.begin(9600); // Initialize SIM900A Serial at 9600 baud rate
gpsSerial.begin(9600); // Initialize GPS Serial at 9600 baud rate
Serial.println("GPS Tracker System Starting...");
// Initialize SIM900A
sendSMS("Device started and waiting for GPS signal...");
}
void loop() {
// Read data from GPS and SIM900A serial
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
// If we have a valid GPS fix
if (gps.location.isUpdated()) {
double currentLatitude = gps.location.lat();
double currentLongitude = gps.location.lng();
Serial.print("Current Latitude: ");
Serial.println(currentLatitude, 6);
Serial.print("Current Longitude: ");
Serial.println(currentLongitude, 6);
// Check if the child is outside the safe zone
if (isOutsideSafeZone(currentLatitude, currentLongitude)) {
sendSMS("ALERT: Child has left the safe zone!");
delay(60000); // Wait for 1 minute before checking again to avoid spamming
}
}
}
}
// Function to calculate distance between two GPS coordinates using Haversine formula
float calculateDistance(double lat1, double lon1, double lat2, double lon2) {
const float R = 6371.0; // Radius of Earth in kilometers
float dLat = radians(lat2 - lat1);
float dLon = radians(lon2 - lon1);
float a = sin(dLat / 2) * sin(dLat / 2) +
cos(radians(lat1)) * cos(radians(lat2)) *
sin(dLon / 2) * sin(dLon / 2);
float c = 2 * atan2(sqrt(a), sqrt(1 - a));
float distance = R * c * 1000; // Distance in meters
return distance;
}
// Function to check if the current location is outside the safe zone
bool isOutsideSafeZone(double lat, double lon) {
float distance = calculateDistance(lat, lon, safeLatitude, safeLongitude);
Serial.print("Distance from safe zone: ");
Serial.println(distance);
return distance > safeRadius;
}
// Function to send SMS using SIM900A
void sendSMS(const char* message) {
sim900Serial.println("AT"); // Check if SIM900A is ready
delay(1000);
sim900Serial.println("AT+CMGF=1"); // Set SMS format to text mode
delay(1000);
sim900Serial.print("AT+CMGS=\"");
sim900Serial.print(phoneNumber); // Send SMS to this number
sim900Serial.println("\"");
delay(1000);
sim900Serial.println(message); // The message content
delay(1000);
sim900Serial.write(26); // CTRL+Z to send SMS
delay(1000);
}
This code initializes the GPS and SIM900A modules, reads GPS data, and sends an SMS alert if the tracked object moves outside the predefined safe zone. The safe zone is defined by a central latitude and longitude, and a radius in meters.
