0% found this document useful (0 votes)
14 views6 pages

Parcel Delivery Detection

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

Parcel Delivery Detection

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Parcel Delivery Detection – IOT ( Telegram Notification )

Hardware Requirements:

1. NodeMCU ESP8266
2. Infrared sensor module (like IR proximity sensor)
3. Breadboard and jumper wires
4. 5V power supply (from NodeMCU or external source)

Hardware Connections:

1. Infrared Sensor Connections:


o VCC: Connect to 3.3V pin of the NodeMCU.
o GND: Connect to the GND pin of the NodeMCU.
o OUT (Digital Output): Connect to D1 (GPIO5) pin of the NodeMCU.
2. NodeMCU to Power Source:
o Connect the NodeMCU to a USB power adapter or to your computer via a
USB cable.

Telegram Bot Setup:

1. Create a Telegram Bot:


o Open Telegram, and search for "BotFather".
o Start a chat with BotFather and use /newbot to create a new bot.
o Follow the prompts, and you’ll receive a Telegram Bot Token. Save it for
later use.
2. Get the Chat ID:
o Start a chat with your bot and send a message.
o Visit https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates,
replacing <YOUR_BOT_TOKEN> with your actual bot token.
o You will receive a JSON response containing your Chat ID. Note this for use
in the code.
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "YOUR_SSID"; // Your WiFi SSID


const char* password = "YOUR_PASSWORD"; // Your WiFi password

const char* telegramBotToken = "YOUR_BOT_TOKEN"; // Replace with your Telegram Bot


Token
const char* chatID = "YOUR_CHAT_ID"; // Replace with your Chat ID

const int irSensorPin = D1; // GPIO5 (D1 pin)

void setup() {
Serial.begin(115200);
pinMode(irSensorPin, INPUT);

WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
}

void loop() {
if (digitalRead(irSensorPin) == LOW) { // Assuming LOW is when an object is detected
sendTelegramMessage("Parcel detected in your post box!");
delay(5000); // Wait for 5 seconds to avoid multiple notifications for the same detection
}
}

void sendTelegramMessage(String message) {


if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure(); // Disable certificate verification for simplicity

HTTPClient https;
String url = "https://api.telegram.org/bot" + String(telegramBotToken) + "/sendMessage?
chat_id=" + String(chatID) + "&text=" + message;

if (https.begin(client, url)) {
int httpCode = https.GET();
if (httpCode > 0) {
Serial.printf("Telegram message sent, response code: %d\n", httpCode);
} else {
Serial.printf("Error sending message: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
}
} else {
Serial.println("WiFi Disconnected");
}
}
Explanation:

1. WiFi Setup:
o Replace "YOUR_SSID" and "YOUR_PASSWORD" with your WiFi credentials.
2. Telegram Setup:
o Replace "YOUR_BOT_TOKEN" and "YOUR_CHAT_ID" with your bot token and
chat ID from Telegram.
3. IR Sensor Logic:
o The code checks the status of the IR sensor. If a parcel is detected (LOW
signal), it sends a notification through Telegram.
o delay(5000) is used to prevent multiple messages from being sent for the
same parcel.

Testing and Running:

1. Power the NodeMCU and ensure it connects to WiFi.


2. Place the IR sensor inside your post box. When the sensor detects a parcel (meaning
an obstruction in its range), it will trigger the notification.
3. Telegram Notification: Check your Telegram for messages from the bot.

You might also like