FULL !!! Sistem Keamanan Pintu Menggunakan Sensor Reed Switch dengan Notifikasi Telegram
Table of Contents
Introduction
In this tutorial, we will create a door security system using a Reed Switch sensor and integrate it with Telegram for notifications. This project is perfect for beginners interested in IoT and can serve as an excellent school or college project. By the end of this guide, you will have a working system that alerts you on your phone when the door opens.
Step 1: Gather Your Materials
Before starting, make sure you have the following components:
- NodeMCU ESP8266 Amica - 1 Unit
- Reed Switch Sensor - 1 Unit
- Buzzer - 1 Unit
- LED Light - 1 Unit
- Breadboard
- Jumper Wires
- Data Cable
- Android Phone with Telegram App
Step 2: Understand the Wiring
To successfully set up your system, it's essential to wire the components correctly. Follow these guidelines:
- Connect the Reed Switch to the NodeMCU. One terminal of the Reed Switch goes to a digital pin (e.g., D1) on the NodeMCU, and the other terminal goes to the ground.
- Connect the LED Light to another digital pin (e.g., D2) on the NodeMCU, with the anode connected to the pin and the cathode to ground.
- Connect the Buzzer similarly to another digital pin (e.g., D3) on the NodeMCU.
- Use the breadboard to manage connections neatly and avoid short circuits.
Refer to this wiring diagram for visual guidance: Wiring Diagram.
Step 3: Set Up the Code
Now, let’s write the code that will control the system. Here’s a basic example to get you started:
#include <ESP8266WiFi.h>
#include <TelegramBot.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* telegram_token = "your_TELEGRAM_BOT_TOKEN";
const char* chat_id = "your_CHAT_ID";
TelegramBot bot(telegram_token);
const int reedPin = D1;
const int ledPin = D2;
const int buzzerPin = D3;
void setup() {
Serial.begin(115200);
pinMode(reedPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
WiFi.begin(ssid, password);
}
void loop() {
int reedState = digitalRead(reedPin);
if (reedState == HIGH) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
bot.sendMessage(chat_id, "Warning: Door Opened!");
delay(5000); // Notification Time
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}
}
Practical Tips
- Replace
your_SSID
,your_PASSWORD
,your_TELEGRAM_BOT_TOKEN
, andyour_CHAT_ID
with your actual WiFi credentials and Telegram bot details. - Ensure your NodeMCU is connected to the internet for Telegram notifications to work.
Step 4: Testing the System
After uploading the code to the NodeMCU, it’s time to test your system:
- Open the Telegram app on your phone and ensure your bot is set up and you have the correct chat ID.
- Trigger the Reed Switch by opening the door. You should receive a notification on Telegram, and the buzzer should sound while the LED lights up.
- Close the door to see if the system resets correctly.
Conclusion
You have successfully built a door security system with a Reed Switch and Telegram notifications. This project not only enhances your understanding of IoT but also provides practical applications for home security.
Consider expanding this project by adding features, such as a user interface or integrating more sensors. Happy coding!