#define BLYNK_TEMPLATE_ID "TMPL4mhud2_gw"
#define BLYNK_TEMPLATE_NAME "IoT in GIS"
#define BLYNK_AUTH_TOKEN "zuLUQu7kWSfAjKSJVo9IZeexKPoU0co4"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#define PIR_PIN 4 // PIR sensor connected to GPIO 4
char ssid[] = "Wokwi-GUEST"; // WiFi SSID
char pass[] = ""; // WiFi Password (Wokwi-GUEST has no password)
float latitude = 0.0, longitude = 0.0; // Global variables to store GPS coordinates
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Serial.println("ESP32 Motion Detection with GPS Simulation Started...");
}
// Function to update the GPS coordinates
void updateGPS() {
latitude = 4.0 + ((float)random(0, 100000) / 100000) * (13.9 - 4.0);
longitude = 2.5 + ((float)random(0, 100000) / 100000) * (14.6 - 2.5);
Serial.print("📍 New GPS Location: ");
Serial.print(latitude, 5);
Serial.print(", ");
Serial.println(longitude, 5);
// Send updated coordinates to Blynk
Blynk.virtualWrite(V0, latitude);
Blynk.virtualWrite(V1, longitude);
}
void loop() {
Blynk.run(); // Run Blynk to keep it updated
int motion = digitalRead(PIR_PIN);
if (motion == HIGH) {
Serial.println("⚠️ Motion Detected!");
updateGPS(); // Generate new GPS data
delay(5000); // Prevent multiple detections in quick succession
} else {
Serial.println("No motion detected...");
}
delay(1000); // Check motion every second
}
// #define BLYNK_TEMPLATE_ID "TMPL4mhud2_gw"
// #define BLYNK_TEMPLATE_NAME "IoT in GIS"
// #define BLYNK_AUTH_TOKEN "zuLUQu7kWSfAjKSJVo9IZeexKPoU0co4"
// #define PIR_PIN 4 // PIR sensor connected to GPIO 4
// char ssid[] = "Wokwi-GUEST";
// char pass[] = "";
// void setup() {
// Serial.begin(115200); // Start serial communication
// pinMode(PIR_PIN, INPUT); // Set PIR sensor as input
// Serial.println("ESP32 Motion Detection with GPS Simulation Started...");
// }
// void loop() {
// int motion = digitalRead(PIR_PIN); // Read motion sensor state
// if (motion == HIGH) { // If motion detected
// Serial.println("⚠️ Motion Detected!");
// // Generate random latitude and longitude within Nigeria
// float latitude = 4.0 + ((float)random(0, 100000) / 100000) * (13.9 - 4.0); // Between 4.0°N and 13.9°N
// float longitude = 2.5 + ((float)random(0, 100000) / 100000) * (14.6 - 2.5); // Between 2.5°E and 14.6°E
// // Print GPS coordinates
// Serial.print("📍 GPS Location: ");
// Serial.print(latitude, 5);
// Serial.print(", ");
// Serial.println(longitude, 5);
// delay(5000); // Delay to prevent multiple detections in quick succession
// } else {
// Serial.println("No motion detected...");
// }
// delay(1000); // Check motion every second
// }