Building a Smart Inventory System with Telegram Alerts Using Favoriot
This tutorial guides you through developing a Smart Inventory System for managing stock in a factory using RFID technology or weight sensors. The system automatically monitors raw materials or spare parts and sends alerts via Telegram when stock levels are low. All data is processed using the Favoriot IoT platform.
Hardware and software
Hardware
RFID Reader, RFID Tags, Weight Sensors, Arduino or Raspberry Pi.
Software
Arduino IDE or Python (for Raspberry Pi), a Favoriot IoT platform account, and Telegram Bot API.
Setting up the Favoriot IoT platform
Before setting up the hardware, prepare the Favoriot IoT platform to receive data from the devices.
- Create a Favoriot account. Go to Favoriot and create a new account, then log in.
- Create a new application. On the dashboard, go to Applications and create a new application for the Smart Inventory System.
- Add a device. Go to Devices and click Add New Device. Choose the device type (Arduino or Raspberry Pi) and set up a connection to transmit data via HTTP or MQTT. Note down the Device ID and API URL that will be used in the code.
- Configure data streams. In the device settings, create data streams to track inventory stock, such as RFID tags or weight readings.
Setting up the hardware (Arduino or Raspberry Pi)
Using Arduino with an RFID reader
- Connect the RFID reader. Connect the MFRC522 RFID Reader to the Arduino using the following pin connections: SDA to Pin 10, SCK to Pin 13, MISO to Pin 12, MOSI to Pin 11, RST to Pin 9.
- Upload the RFID code. Open Arduino IDE and upload the code below to read RFID tags.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("RFID Reader initialized");
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent()) {
if (mfrc522.PICC_ReadCardSerial()) {
String rfidTag = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
rfidTag += String(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("RFID Tag detected: ");
Serial.println(rfidTag);
sendToFavoriot(rfidTag); // Send data to Favoriot
}
}
}
void sendToFavoriot(String rfidTag) {
String url = "http://<FAVORIOT API URL>/update?device_id=<YOUR_DEVICE_ID>&data=" + rfidTag;
// Send HTTP request to Favoriot
}
Using Raspberry Pi with a weight sensor (HX711)
- Connect the HX711 weight sensor. Connect the HX711 load cell to the GPIO pins of the Raspberry Pi.
- Install required libraries. On the Raspberry Pi, install the necessary Python libraries for reading data from the sensor.
- Upload the Python code. Use the code below to read the weight and send it to Favoriot.
import time
import requests
from hx711 import HX711
# Initialize HX711 sensor
hx = HX711(dout_pin=5, pd_sck_pin=6)
# Tare the scale
hx.tare()
print("Tare complete")
while True:
try:
weight = hx.get_weight(5) # Read the weight
print("Weight: ", weight)
if weight < 100: # Example threshold to check low stock
print("Low stock detected")
sendToFavoriot(weight)
sendTelegramAlert("Stock is low!")
time.sleep(2)
except (KeyboardInterrupt, SystemExit):
cleanAndExit()
def sendToFavoriot(weight):
url = "http://<FAVORIOT API URL>/update?device_id=<YOUR_DEVICE_ID>&data=" + str(weight)
requests.get(url)
def sendTelegramAlert(message):
telegram_api_url = f"https://api.telegram.org/bot<YOUR_BOT_API>/sendMessage?chat_id=<YOUR_CHAT_ID>&text={message}"
requests.get(telegram_api_url)
def cleanAndExit():
print("Exiting...")
exit()
Setting up Telegram alerts
To receive Telegram alerts when stock is low, create a Telegram Bot and get the API Token.
- Create a Telegram bot. Open Telegram and search for BotFather. Start a conversation and use the /newbot command to create a new bot. After creating the bot, an API Token will be provided.
- Get the chat ID. Send a message to the bot, then visit the URL below and look for the chat_id in the JSON response.
https://api.telegram.org/bot<YOUR_BOT_API>/getUpdates
- Configure the bot to send alerts. In the Python or Arduino code, use the Telegram API to send a message when stock falls below the set threshold.
https://api.telegram.org/bot<YOUR_BOT_API>/sendMessage?chat_id=<YOUR_CHAT_ID>&text=Stock%20is%20low!
Testing and monitoring
Once the system is set up:
- Monitor the data on the Favoriot Dashboard to ensure that stock readings, whether RFID or weight, are being sent correctly.
- Check that Telegram alerts are triggered when stock goes below the set threshold.
Final integration and deployment
After confirming everything is working:
- Deploy the system in the factory for continuous stock monitoring.
- Real-time Telegram alerts will be received whenever stock is low.
Conclusion
This Smart Inventory System with Telegram alerts and Favoriot IoT platform integration provides a simple and effective solution for automating stock management in a factory.
By using RFID or weight sensors together with the Favoriot platform, real-time monitoring and immediate action become possible whenever stock levels decrease, all while tracking inventory remotely.
Disclaimer: This article provides a step by step guide. The source code may need adjustments to fit the final project design.






Leave a Reply