Tech Gyan Set
Published © MIT

Smart School Bag Tracker (Kids Safety)

An IoT-based smart school bag tracker that provides real-time GPS location and emergency alerts to keep kids safe. πŸŽ’πŸ“‘

BeginnerFull instructions provided8 hours251
Smart School Bag Tracker (Kids Safety)

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Complete ESP32 GPS Tracking Code

C/C++
// 1️⃣ Include Required Libraries
1  #include <WiFi.h>              // WiFi connectivity ke liye
2  #include <HTTPClient.h>        // Data server par bhejne ke liye
3  #include <TinyGPS++.h>         // GPS data parse karne ke liye

// Use: Ye libraries internet aur GPS communication enable karti hain.
// 2️⃣ WiFi Credentials
4  const char* ssid = "YOUR_WIFI_NAME";
5  const char* password = "YOUR_WIFI_PASSWORD";

// Use: ESP32 ko internet se connect karta hai.
// 3️⃣ Server URL (Location Send Karne Ke Liye)
6  const char* serverName = "http://yourserver.com/update";

// Use: Location data jahan send hoga wo URL define karta hai.
// 4️⃣ GPS Setup
7  TinyGPSPlus gps;               
8  HardwareSerial gpsSerial(1);  

// Use: TinyGPS object GPS se latitude & longitude read karega.
// 5️⃣ SOS Button Pin
9  #define SOS_BUTTON 5

// Use: Emergency alert ke liye push button define karta hai.
// 6️⃣ Setup Function
10 void setup() {
11   Serial.begin(115200);       
12   gpsSerial.begin(9600, SERIAL_8N1, 16, 17); 
13   pinMode(SOS_BUTTON, INPUT_PULLUP);        

14   WiFi.begin(ssid, password);
15   while (WiFi.status() != WL_CONNECTED) {
16     delay(500);
17     Serial.print(".");
18   }
19   Serial.println("WiFi Connected");
20 }

// Use: GPS start karta hai aur WiFi connection establish karta hai.
// 7️⃣ Main Loop
21 void loop() {

22   while (gpsSerial.available() > 0) {
23     gps.encode(gpsSerial.read());
24   }

πŸ”Ή Use: GPS module se incoming data read karta hai.

25   if (gps.location.isValid()) {

26     float latitude = gps.location.lat();
27     float longitude = gps.location.lng();

πŸ”Ή Use: Valid GPS signal milne par latitude aur longitude read karta hai.

28     Serial.print("Latitude: ");
29     Serial.println(latitude);
30     Serial.print("Longitude: ");
31     Serial.println(longitude);

πŸ”Ή Use: Debug ke liye serial monitor par location print karta hai.

32     if (WiFi.status() == WL_CONNECTED) {
33       HTTPClient http;
34       String serverPath = String(serverName) + "?lat=" + String(latitude,6) + "&lon=" + String(longitude,6);
35       http.begin(serverPath);
36       int httpResponseCode = http.GET();
37       http.end();
38     }

πŸ”Ή Use: Latitude & longitude server par HTTP GET request se send karta hai.

39   }
// 8️⃣ SOS Button Logic
40   if (digitalRead(SOS_BUTTON) == LOW) {
41     Serial.println("SOS Alert Triggered!");

πŸ”Ή Use: Emergency button press detect karta hai.

42     if (WiFi.status() == WL_CONNECTED) {
43       HTTPClient http;
44       String alertPath = String(serverName) + "?alert=SOS";
45       http.begin(alertPath);
46       http.GET();
47       http.end();
48     }

49     delay(2000);
50   }

πŸ”Ή Use: SOS press hone par emergency alert server ko bhejta hai.

51   delay(5000);
52 }

πŸ”Ή Use: Har 5 second me location update karta hai.

Credits

Tech Gyan Set
32 projects β€’ 14 followers
Tech Gyan Set | IoT & Embedded Systems Creator | Arduino, ESP32, GSM & NodeMCU Projects | Smart Home & Real-Life Automation Tutorials
Thanks to Tech Gyan Set .

Comments