In this tutorial, we will guide you through developing a Smart Inventory System for managing stock in a factory using RFID technology or weight sensors. This system automatically monitors raw materials or spare parts and sends alerts via Telegram when stock levels are low. All data will be processed using the Favoriot IoT platform.

What You Need:

  • Hardware: RFID Reader, RFID Tags, Weight Sensors, Arduino or Raspberry Pi.
  • Software: Arduino IDE or Python (for Raspberry Pi), Favoriot IoT platform account, Telegram Bot API.

Step 1: Setting Up the Favoriot IoT Platform

Before we begin setting up the hardware, you need to prepare the Favoriot IoT platform to receive data from your devices.

  1. Create a Favoriot Account:
    • Go to Favoriot and create a new account if you don’t already have one.
    • After registering, log in to your account.
  2. Create a New Application:
    • On the dashboard, go to Applications and create a new application for your Smart Inventory System.
  3. Add a Device:
    • Go to Devices and click on Add New Device.
    • Choose your device type (Arduino or Raspberry Pi) and set up a connection to transmit data (via HTTP or MQTT). Make sure to note down the Device ID and API URL that will be used in the code.
  4. Configure Data Streams:
    • In the device settings, create data streams to track inventory stock (e.g., RFID tags or weight readings).

Step 2: Setting Up the Hardware (Arduino or Raspberry Pi)

Using Arduino with RFID Reader:

  1. Connect the RFID Reader:
    • Connect the MFRC522 RFID Reader to your 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
  2. Upload the RFID Code:
    • Open Arduino IDE, and upload the following code to read RFID tags.

Arduino Code (for RFID):

#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 Weight Sensor (HX711):

  1. Connect the HX711 Weight Sensor:
    • Connect the HX711 load cell to the GPIO pins of the Raspberry Pi.
  2. Install Required Libraries:
    • On the Raspberry Pi, install the necessary Python libraries for reading data from the sensor.
  3. Upload the Python Code:
    • Use the following Python code to read the weight and send it to Favoriot.

Python Code (for Weight Sensor):

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()


Step 3: Setting Up Telegram Alerts

To receive Telegram alerts when stock is low, you need to create a Telegram Bot and get the API Token:

  1. Create a Telegram Bot:
    • Open Telegram and search for BotFather.
    • Start a conversation with BotFather and use the /newbot command to create a new bot.
    • After creating the bot, you will receive the API Token.
  2. Get Your Chat ID:
    • To get your Chat ID, send a message to your bot, then use the following URL:
  3. https://api.telegram.org/bot<YOUR_BOT_API>/getUpdates
    • Look for your chat_id in the JSON response.
  4. Configure the Bot to Send Alerts:
    • In your Python or Arduino code, use the Telegram API to send a message when stock falls below the set threshold.

Example Telegram Alert URL:

https://api.telegram.org/bot<YOUR_BOT_API>/sendMessage?chat_id=<YOUR_CHAT_ID>&text=Stock%20is%20low!


Step 4: Testing and Monitoring

Once the system is set up:

  1. Monitor the data on the Favoriot Dashboard to ensure that stock readings (RFID or weight) are being sent correctly.
  2. Check if the Telegram alerts are triggered when stock goes below the set threshold.

Step 5: Final Integration and Deployment

After confirming everything is working:

  • Deploy the system in your factory for continuous stock monitoring.
  • You will receive real-time Telegram alerts 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 and the Favoriot platform, you can ensure real-time monitoring and immediate action when stock levels decrease, all while remotely tracking inventory.

[Disclaimer: This article provides a step-by-step guide. The source code may need adjustments to fit the final project design.]

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This

Share this post with your friends!

Discover more from IoT World

Subscribe now to keep reading and get access to the full archive.

Continue reading