ESP32 মোশন অ্যালার্ট — PIR দেখলে ক্লাউডে খবর, বাসায় বাজারESP32 Motion Alert
PIR এর OUT পিন ESP32 কে জাগায়, ESP32 ক্লাউডে খবর পাঠায় আর বাসায় বাজনা বাজে — জিএসএম অ্যালার্মের মতোই, শুধু সিম ছাড়াই।
The PIR OUT pin wakes the ESP32, which pings a cloud URL with the event and sounds the local buzzer — the same someone-is-in-the-shop pattern as a GSM alarm, minus the SIM.
সার্কিট ডায়াগ্রাম · Circuit diagram
যা যা লাগবে · Parts you need
- 1 × ESP32 DevKit V1 (WROOM-32) ESP32 DevKit V1 (WROOM-32)
- 1 × PIR motion sensor (HC-SR501) PIR মোশন সেন্সর (HC-SR501)
- 1 × Buzzer (5 V) Buzzer (বাঁশি, 5 V)
- 1 × Resistor 220Ω Resistor
- 1 × LED (red) LED বাতি
- 8 × Jumper wires জাম্পার তার
তার লাগানো · Wiring
| PIR motion sensor (HC-SR501) VCC | → | ESP32 DevKit V1 (WROOM-32) VIN |
| PIR motion sensor (HC-SR501) GND | → | ESP32 DevKit V1 (WROOM-32) GND |
| PIR motion sensor (HC-SR501) OUT | → | ESP32 DevKit V1 (WROOM-32) D4 |
| Buzzer (5 V) + | → | ESP32 DevKit V1 (WROOM-32) D15 |
| Buzzer (5 V) - | → | ESP32 DevKit V1 (WROOM-32) GND.2 |
| ESP32 DevKit V1 (WROOM-32) D27 | → | Resistor a |
| Resistor b | → | LED A |
| LED K | → | ESP32 DevKit V1 (WROOM-32) GND.2 |
Code (Arduino C++)
#include <WiFi.h>
#include <HTTPClient.h>
// ESP32 motion alert: the PIR's OUT pin wakes the ESP32, which pings a cloud
// URL with the event and sounds the local buzzer — the same "someone is in
// the shop after midnight" pattern as a real GSM/WiFi alarm, minus the SIM.
// Wi-Fi credentials stay in the sketch for the demo; in production read them
// from preferences so they never sit in a git repository.
void setup() {
Serial.begin(115200);
pinMode(4, INPUT);
pinMode(15, OUTPUT); pinMode(27, OUTPUT);
WiFi.begin("Tekko-WiFi", "12345678");
Serial.println("Booting; joining WiFi in the background");
}
void loop() {
bool motion = digitalRead(4) == HIGH;
if (motion) {
digitalWrite(15, HIGH);
digitalWrite(27, HIGH);
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("http://cloud.tekko.sim/alert?site=shop&event=motion");
int code = http.GET();
http.end();
Serial.print("Motion! ALERT sent, cloud reply ");
Serial.println(code);
} else {
Serial.println("Motion! WiFi down - siren on, alert queued");
}
delay(1200);
digitalWrite(15, LOW);
digitalWrite(27, LOW);
}
delay(150);
}