Monthly Archives: April, 2025

[Tutorial] : Automated Quality Inspection System Using AI & FAVORIOT

April 6th, 2025 Posted by BLOG, HOW-TO, Internet of Things, IOT PLATFORM, TIPS 0 thoughts on “[Tutorial] : Automated Quality Inspection System Using AI & FAVORIOT”

This guide will show you how to build an AI-powered quality inspection system using a camera and send inspection results to the FAVORIOT IoT platform in real time.


πŸ”§ Step 1: What You Need

Hardware:

  • Raspberry Pi (or any computer with a camera)
  • Camera (USB or Pi Camera)
  • Internet connection

Software:

  • Python 3
  • Libraries: opencv-python, tensorflow, numpy, requests

πŸ› οΈ Step 2: Install the Required Software

Open Terminal and run:

sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip -y
pip3 install opencv-python numpy requests tensorflow

🧠 Step 3: Train an AI Model to Detect Defects

Create a folder called dataset_defects with 2 subfolders: defect and normal.

Now, use this Python code to train the model:

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator

dataset_path = "dataset_defects"
batch_size = 32
img_size = (224, 224)

datagen = ImageDataGenerator(rescale=1./255, validation_split=0.2)

train_data = datagen.flow_from_directory(
    dataset_path,
    target_size=img_size,
    batch_size=batch_size,
    class_mode="binary",
    subset="training"
)

val_data = datagen.flow_from_directory(
    dataset_path,
    target_size=img_size,
    batch_size=batch_size,
    class_mode="binary",
    subset="validation"
)

base_model = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3), include_top=False, weights="imagenet")
base_model.trainable = False

model = tf.keras.Sequential([
    base_model,
    tf.keras.layers.GlobalAveragePooling2D(),
    tf.keras.layers.Dense(1, activation="sigmoid")
])

model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.fit(train_data, validation_data=val_data, epochs=10)

model.save("defect_detection_model.h5")

πŸŽ₯ Step 4: Real-Time Defect Detection Using Camera

Once the model is trained and saved, run this script:

import cv2
import numpy as np
import tensorflow as tf

model = tf.keras.models.load_model("defect_detection_model.h5")
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    img = cv2.resize(frame, (224, 224))
    img = np.expand_dims(img, axis=0) / 255.0
    prediction = model.predict(img)[0][0]

    label = "Defect Detected!" if prediction > 0.5 else "Product OK"
    color = (0, 0, 255) if prediction > 0.5 else (0, 255, 0)

    cv2.putText(frame, label, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2)
    cv2.imshow("Quality Inspection", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

🌐 Step 5: Send Defect Results to FAVORIOT

βœ… 1. Set Up a Device in FAVORIOT

  1. Log in to Favoriot Platform
  2. Go to Devices β†’ Add Device
  3. Note down your Device Developer ID and API Key

βœ… 2. Add Code to Send Data

Below is the function to send results:

import requests
import json

DEVICE_ID = "YOUR_DEVICE_ID"
API_KEY = "YOUR_FAVORIOT_API_KEY"
URL = "https://apiv2.favoriot.com/v2/streams"

def send_data_to_favoriot(status):
    payload = {
        "device_developer_id": DEVICE_ID,
        "data": {
            "status": status
        }
    }

    headers = {
        "Content-Type": "application/json",
        "Apikey": API_KEY
    }

    response = requests.post(URL, data=json.dumps(payload), headers=headers)
    print("Response from Favoriot:", response.json())

βœ… 3. Combine with Real-Time Detection

Add this snippet inside your prediction logic:

if prediction > 0.5:
    send_data_to_favoriot("Defect Detected!")
else:
    send_data_to_favoriot("Product OK")

πŸ“Š Step 6: View Data on FAVORIOT Dashboard

  • Go to your device on the FAVORIOT Dashboard
  • Click on Streams to view defect data
  • You can also create graphs or alert rules for monitoring

πŸš€ Bonus Tips

  • Add Telegram Alerts using Telegram Bot API
  • Add Dashboard Charts using Favoriot’s visualization
  • Improve accuracy with better dataset or model tuning

βœ… Summary

With this project, you have:

βœ… Built a real-time defect detection system
βœ… Displayed results on screen
βœ… Sent reports to FAVORIOT cloud platform

References

Disclaimer

This article provides a step-by-step guide and only serves as a guideline. The source code may need adjustments to fit the final project design.

[Tutorial] : Smart Conveyor System using FAVORIOT

April 6th, 2025 Posted by BLOG 0 thoughts on “[Tutorial] : Smart Conveyor System using FAVORIOT”

Smart Conveyor System with IoT Monitoring

This project shows how to build a smart conveyor system that:

  • Sorts products using IR sensors and servo motors
  • Monitors speed and status in real-time
  • Sends and receives data via the FAVORIOT IoT platform

1. Project Goal

βœ… Automatically detect products, sort them, and adjust conveyor speed
βœ… Send data to FAVORIOT Cloud for real-time monitoring
βœ… Remotely control speed using the FAVORIOT Dashboard


2. Main Components

ComponentPurpose
Arduino/ESP8266Microcontroller
IR SensorDetect object on conveyor
Servo MotorProduct sorting & speed control
ESP8266 WiFiSend data to FAVORIOT
FAVORIOT PlatformIoT Dashboard & Data Analytics

3. System Design

πŸ—οΈ Hardware:

  • Conveyor with IR sensor and servo motor
  • Controlled by Arduino + ESP8266

☁️ IoT Setup:

  • Data sent to FAVORIOT cloud via WiFi
  • IoT Dashboard displays:
    • Speed
    • Status (Running/Stopped)
    • Product Detected

4. Wiring Diagram

  • IR Sensor β†’ Arduino digital pin
  • Servo Motor β†’ PWM pin
  • ESP8266 β†’ TX/RX (for WiFi communication)

5. Sending Data to FAVORIOT

Step 1: Sign up at FAVORIOT Platform

Create a new device called Smart_Conveyor_001 to get your API key.

Step 2: Arduino Code (ESP8266)

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
const char* server = "http://apiv2.favoriot.com/v2/streams";
const char* api_key = "YOUR_FAVORIOT_API_KEY";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(server);
    http.addHeader("Content-Type", "application/json");
    http.addHeader("Apikey", api_key);

    String jsonData = "{\"device_developer_id\":\"Smart_Conveyor_001\",\"data\":{\"speed\":100,\"status\":\"Running\",\"product_detected\":1}}";

    int httpResponseCode = http.POST(jsonData);
    Serial.println(httpResponseCode);
    http.end();
  }
  delay(5000); // Send every 5 seconds
}

6. IoT Dashboard on FAVORIOT

Use the built-in dashboard or tools like Node-RED to:

  • View real-time speed and status
  • Count products
  • Display alerts when needed

7. Receiving Control Commands (Remote Control)

Use FAVORIOT’s API to send speed commands to your device.

Example JSON Payload:

{
  "device_developer_id": "Smart_Conveyor_001",
  "data": {
    "speed": 50
  }
}

Arduino Code to Read Command:

String speed_value = received_data["data"]["speed"];
int motorSpeed = speed_value.toInt();
analogWrite(motorPin, motorSpeed);

8. Testing & Simulation Checklist

βœ… IR Sensor Test – Detect object presence
βœ… Speed Test – Change speed via dashboard
βœ… Data Transmission – View updates on dashboard
βœ… Sorting Automation – Simulate sorting flow


9. Summary & What’s Next

βœ… Project Highlights:

  • Remote monitoring & control
  • Real-time speed and object status updates
  • Simple integration with FAVORIOT

πŸ“ˆ Future Enhancements:

  • Add AI Camera for advanced object detection
  • Use Machine Learning to adjust speed automatically
  • Switch to MQTT for faster data transmission

This project proves that IoT + automation can enhance productivity and reduce human error in smart manufacturing. With the FAVORIOT Platform, developers can scale up easily and integrate analytics, alerts, and AI features.

Copyright Β© 2025 All rights reserved