DIY AI Smart Miniature Supermarket

DIY AI Smart Miniature Supermarket – Robotics Project for Kids | Camera, Smart LEDs, Auto-Billing
AI · Computer Vision · IoT · Smart Retail

Build a DIY Smart
Miniature Supermarket

A tiny store that actually works — AI spots products, LEDs light up shelves, bills add up automatically, customers pay by QR code, and the exit catches theft. All built by you. 🛒🤖

Advanced Difficulty 3–4 Weekends Build Time Age 13+ With Adult Help ~₹5,000–₹8,000 Total Cost Python + Arduino Languages
Enter the Store ↓
AI Product ID
Dynamic Price Display
Auto Billing
Smart Shelf LEDs
QR Payment
Theft Detection
Personalised Offers
Mission Briefing

What Are We Building?

Real supermarkets like Amazon Go, Reliance Smart, and Walmart use millions of rupees worth of technology to automate shopping. This project builds a miniature version of that same technology — using a shoebox-sized store, a Raspberry Pi, an Arduino, and parts you can buy online for a few thousand rupees.

Your smart supermarket will have seven working systems:

  1. AI Product Camera — a Pi camera that recognises which product a customer picks up
  2. Dynamic Price Display — an OLED screen that updates prices in real-time
  3. Auto Billing + Digital Cart — a running total that adds items automatically
  4. Smart Shelf LEDs — LED strips that highlight low-stock shelves or featured products
  5. QR Code Payment — a unique QR code the customer scans to pay
  6. Exit Theft Detection — a sensor at the exit that beeps if unpaid items pass through
  7. Personalised Offers — a customer recognition system that shows tailored discounts
🧠 Two-brain design: This project uses two computers working together — a Raspberry Pi 4 for all the AI, computer vision, and WiFi logic, and an Arduino Uno for controlling LEDs, buzzers, and sensors in real time.
System Overview

The 7 Smart Systems Explained

Each system is a standalone module — you can build and test them one at a time, then connect them all.

📷

AI Product Identifier

Pi Camera + TFLite

A Pi Camera watches a "scan zone" on the counter. A TensorFlow Lite model recognises which product a customer places there and instantly sends its name and price to the billing system.

🏷️

Dynamic Price Display

SSD1306 OLED

A 0.96" OLED displays the current scanned item's price, running cart total, and special offers. Prices can update in real-time from the Raspberry Pi over serial communication.

🧾

Auto Billing + Digital Cart

Python + Flask

A Python Flask web app keeps the digital shopping cart. Every time the AI identifies a product, it's added to the cart and the total updates automatically. The receipt is generated on demand.

💡

Smart Shelf LEDs

WS2812B + Arduino

Addressable RGB LED strips under each shelf glow green for well-stocked items, amber for low stock, and blue to highlight featured/offer items. Controlled by Arduino receiving commands from the Pi.

📱

QR Code Payment

Python + qrcode lib

When the customer is ready to pay, the Pi generates a unique QR code displayed on a small LCD screen. Scanning it (with any phone) shows the itemised bill for "payment."

🚨

Exit Theft Detection

IR Sensor + Buzzer

An IR break-beam sensor across the exit doorway detects when something passes. If the cart hasn't been paid yet, an Arduino triggers a buzzer alarm and flashes red LEDs.

🎁

Personalised Offers

Face Recognition

A simple face recognition check (using the OpenCV face_recognition library) identifies returning customers and displays personalised discounts on the OLED screen when they approach.

Shopping List

Full Parts List

🧠 Brains & Connectivity

~₹4,000

Raspberry Pi 4 (4GB)

Main brain — runs all AI, web server, face recognition, QR generation, and serial comms with Arduino.

~₹550

Arduino Uno R3

Real-time controller for LEDs, buzzer, and IR sensors — takes instant commands from the Pi.

~₹500

32GB MicroSD Card (A1)

Stores Raspberry Pi OS, AI models, web app, and customer face database.

~₹500

Official Pi 4 USB-C Power Supply

Pi needs a stable 5V/3A — underpowered supplies cause crashes during AI processing.

👁️ Vision & Display

~₹700

Raspberry Pi Camera Module v2

Connected to Pi CSI port — captures the scan zone where customers present products.

~₹250

0.96" SSD1306 OLED Display (I²C)

Shows item name, price, cart total, and offers in real time.

~₹350

1.8" TFT LCD Display (ST7735)

Larger display for showing the QR code payment screen.

💡 LEDs & Lighting

~₹400

WS2812B LED Strip (1m, 60 LEDs/m)

Cut into 3 strips for the 3 shelf levels. Each LED is individually colour-controllable.

~₹80

Red/Green LED Pair (×5)

Small indicator LEDs at each shelf section for at-a-glance stock status.

~₹60

5V 2A External Power Supply

Dedicated power for the LED strips — never power WS2812B from the Arduino's 5V pin.

🚨 Sensors & Alarms

~₹200

IR Break-Beam Sensor Pair

Emitter + receiver across the exit door. When the beam breaks, an exit event is triggered.

~₹40

Piezo Buzzer (active, 5V)

Sounds when someone passes through the exit without paying.

~₹80

HC-SR04 Ultrasonic Sensor

Detects when a customer is standing at the checkout counter to trigger personalised offers.

🏗️ Structure & Misc

~₹300

Large Cardboard Box / Foam Board

The store body — approximately 60cm × 40cm × 30cm. Foam board cuts cleanly and holds LED strips with tape.

~₹100

Breadboard + Jumper Wires + USB Cable

For connecting Arduino sensors and the Pi-to-Arduino serial USB link.

~₹200

Small Toy Products (10–15 items)

Matchbox cars, Kinder Eggs, small bottles — anything consistent for training the AI model.

Free

Python Libraries

Flask, OpenCV, tflite-runtime, face_recognition, qrcode, Pillow, pyserial — all free to install.

System Design

Full System Architecture

Every component connects to either the Raspberry Pi (for smart logic) or the Arduino (for instant hardware control). They talk to each other over USB serial.

Raspberry Pi 4 AI · Flask · Face Recog · QR GPIO 2/3 (I²C → OLED) SPI (TFT LCD) CSI (Pi Camera) USB Serial → Arduino WiFi (Flask web app) Pi Camera (AI Scan) PRICE: ₹24 TOTAL: ₹84.50 OLED Price Display TFT LCD (QR Pay) Arduino Uno Pin 6 WS2812B Pin 7 WS2812B Pin 8 WS2812B Pin 9 Buzzer Pin 2 IR sensor A0 HC-SR04 USB Serial ← Pi USB Serial Shelf LEDs ×3 BUZZ Buzzer IR BEAM Exit Sensor scan & pay Phone (WiFi) WiFi → Flask App
LED shelf control
I²C / display bus
Camera CSI
USB Serial (Pi ↔ Arduino)
SPI display
WiFi (customer phone)

The Raspberry Pi handles all intelligence: AI inference, face recognition, billing logic, QR generation, and the web server. The Arduino handles all real-time hardware: lighting 3 LED shelf strips, triggering the exit buzzer, and reading the IR break-beam sensor. They communicate over USB serial using simple text commands like "LED_SHELF1_RED" or "BUZZER_ON".

Physical Build

Building the Miniature Store

1

Build the Store Box

Use a large foam board or sturdy cardboard box (approximately 60cm wide × 40cm deep × 35cm tall). Cut out a front "window" opening so you can see inside. Cut a small doorway on one side as the "customer entrance" and another on the opposite side as the "exit" — this is where the theft detection beam will go.

📐 Foam board from a stationery shop is ideal — it cuts cleanly with a craft knife and LED strips stick to it perfectly with double-sided tape.
2

Install the Shelves

Cut 3 shelf boards from foam board (approximately 50cm × 10cm each). Stack them vertically inside the store, spaced about 10cm apart. Use foam board strips as shelf supports on each side. Arrange your miniature products on each shelf level.

3

Mount the LED Strips

Cut the WS2812B strip into 3 equal sections. Stick each section under the front edge of each shelf (facing outward/downward) using the LED strip's peel-and-stick backing. Route all three data wires and power wires toward one corner where the Arduino will sit.

4

Set Up the Scan Zone and Camera

Create a small "scan counter" area at the front of the store — a small flat surface where customers place products to be recognised. Mount the Pi Camera above this zone pointing straight down, approximately 20cm above the surface.

5

Install the Exit Sensor

Mount the IR emitter on one side of the exit doorway and the receiver directly opposite it, at approximately the same height as the miniature products. When a product passes through, it breaks the beam and triggers the alarm logic.

6

Mount the Displays and Electronics

Mount the OLED display and TFT LCD near the checkout counter area, visible to the "customer." Place the Arduino and Raspberry Pi in a corner of the store or in a small box attached to the back. Route all cables neatly through small holes in the foam board.

🔌 Keep the Pi's power supply outside the store structure — don't enclose it where it could overheat.
📷

Module 1 — AI Product Identifier

Pi Camera + TFLite

The camera watches the scan zone. A TensorFlow Lite model (trained on your specific products) identifies each item in under half a second. Here's how to set it up:

A

Install Libraries on the Pi

# Update and install dependencies
sudo apt update && sudo apt upgrade -y
pip3 install tflite-runtime opencv-python Pillow pyserial flask qrcode face_recognition
sudo apt install -y python3-picamera2
B

Train a Product Model (Google Teachable Machine)

Go to teachablemachine.withgoogle.com → Image Project → Standard Image Model. Create one class per product (e.g. "RedApple", "BlueBottle", "ChocolateBar"). Upload 30–50 photos of each product from different angles. Train the model, then Export → TensorFlow Lite → Floating Point. Download the .tflite file and labels.txt, copy to your Pi.

📸 Use a white background in your product photos for clearest recognition. Take photos in the same lighting as your scan zone.

Product Recognition Code

"""
Module 1: AI Product Identifier
Raspberry Pi 4 + Pi Camera + TFLite model
"""

import cv2, numpy as np, json, serial, time
import tflite_runtime.interpreter as tflite
from picamera2 import Picamera2

# ── Load product catalogue (name → price in ₹) ──────────────────
PRODUCTS = {
    "RedApple":       {"price": 15.00, "shelf": 1, "stock": 8},
    "BlueBottle":     {"price": 35.00, "shelf": 1, "stock": 3},
    "ChocolateBar":   {"price": 25.00, "shelf": 2, "stock": 12},
    "GreenPack":      {"price": 18.00, "shelf": 2, "stock": 2},
    "YellowSnack":    {"price": 10.00, "shelf": 3, "stock": 15},
}

cart     = []
cart_total = 0.0
paid     = False

# ── TFLite model ────────────────────────────────────────────────
interp = tflite.Interpreter(model_path="model.tflite")
interp.allocate_tensors()
inp  = interp.get_input_details()
outp = interp.get_output_details()
SIZE = inp[0]['shape'][1]

labels = [l.strip() for l in open("labels.txt").readlines()]

# ── Arduino serial link ──────────────────────────────────────────
ard = serial.Serial("/dev/ttyUSB0", 9600, timeout=1)
time.sleep(2)

def send_arduino(cmd):
    ard.write((cmd + "\n").encode())

# ── Classify a frame ────────────────────────────────────────────
def classify(frame):
    img = cv2.resize(frame, (SIZE, SIZE)).astype(np.float32) / 255.0
    interp.set_tensor(inp[0]['index'], img[np.newaxis, ...])
    interp.invoke()
    scores = interp.get_tensor(outp[0]['index'])[0]
    idx    = int(np.argmax(scores))
    conf   = float(scores[idx])
    return (labels[idx], conf) if conf > 0.80 else (None, 0)

# ── Add item to cart ─────────────────────────────────────────────
def add_to_cart(name):
    global cart_total
    info = PRODUCTS.get(name)
    if not info: return
    cart.append({"name": name, "price": info["price"]})
    cart_total += info["price"]
    info["stock"] -= 1
    print(ff"✅ Added {name} ₹{info['price']}  |  Total: ₹{cart_total:.2f}")
    # Update shelf LED based on stock level
    shelf = info["shelf"]
    if   info["stock"] <= 2: send_arduino(ff"SHELF{shelf}_RED")
    elif info["stock"] <= 5: send_arduino(ff"SHELF{shelf}_AMBER")
    else:                   send_arduino(ff"SHELF{shelf}_GREEN")

# ── Main camera loop ─────────────────────────────────────────────
cam = Picamera2()
cam.configure(cam.create_preview_configuration(main={"size": (640,480)}))
cam.start()
last_scan = ""; last_time = 0

try:
    while True:
        frame = cam.capture_array()
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        name, conf = classify(frame)

        if name and name != last_scan and time.time() - last_time > 2:
            add_to_cart(name)
            last_scan = name; last_time = time.time()
            send_arduino(ff"OLED:{name}:{PRODUCTS[name]['price']:.0f}:{cart_total:.0f}")

        cv2.putText(frame, ff"{name or 'Scanning...'} {conf:.0%}",
                    (10,30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0,200,80), 2)
        cv2.imshow("Scan Zone", frame)
        if cv2.waitKey(1) & 0xFF == ord('q'): break
finally:
    cam.stop(); cv2.destroyAllWindows()
💡

Module 2 — Smart Shelf LEDs

WS2812B + Arduino

The Arduino listens on the serial port for commands from the Pi and updates the 3 shelf LED strips accordingly. It also controls the exit buzzer, OLED display updates, and ultrasonic sensor for customer detection.

Arduino Uno Pin 6 → Shelf 1 LED Pin 7 → Shelf 2 LED Pin 8 → Shelf 3 LED Pin 9 → Buzzer Pin 2 → IR receiver A0/A1 → HC-SR04 SHELF 1 WS2812B SHELF 2 WS2812B SHELF 3 WS2812B 5V 2A Power Supply (LED strips only) BUZZ Buzzer (5V) IR RX / TX Pair HC-SR04 USB ← Pi Serial

Each WS2812B shelf strip connects: Data pin → Arduino digital pin, V+ → 5V 2A external supply (NOT Arduino 5V pin), GND → shared ground. Always add a 300–500Ω resistor in series with each data wire to protect the first LED from voltage spikes.

Arduino Controller Code

/*
  Smart Supermarket — Arduino Controller
  Receives serial commands from Pi, controls LEDs, buzzer, sensors
*/

#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SHELF1_PIN   6
#define SHELF2_PIN   7
#define SHELF3_PIN   8
#define SHELF_LEDS   10   // LEDs per shelf strip
#define BUZZER_PIN   9
#define IR_PIN       2
#define TRIG_PIN    A0
#define ECHO_PIN    A1

Adafruit_NeoPixel shelf1(SHELF_LEDS, SHELF1_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel shelf2(SHELF_LEDS, SHELF2_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel shelf3(SHELF_LEDS, SHELF3_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

bool paid = false;

void setShelf(Adafruit_NeoPixel &strip, uint8_t r, uint8_t g, uint8_t b) {
  for (int i = 0; i < SHELF_LEDS; i++) strip.setPixelColor(i, r, g, b);
  strip.show();
}

void setup() {
  Serial.begin(9600);
  shelf1.begin(); shelf2.begin(); shelf3.begin();
  shelf1.setBrightness(80); shelf2.setBrightness(80); shelf3.setBrightness(80);
  // Default: all green (well stocked)
  setShelf(shelf1, 0,200,60); setShelf(shelf2, 0,200,60); setShelf(shelf3, 0,200,60);

  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(IR_PIN, INPUT_PULLUP);
  pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);

  Wire.begin();
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oled.clearDisplay(); oled.setTextSize(1); oled.setTextColor(SSD1306_WHITE);
  oled.setCursor(0,0); oled.println("Smart Market Ready!"); oled.display();
}

void processCommand(String cmd) {
  cmd.trim();

  // Shelf colour commands: SHELF1_GREEN / SHELF1_AMBER / SHELF1_RED
  if      (cmd == "SHELF1_GREEN")  setShelf(shelf1, 0,200,60);
  else if (cmd == "SHELF1_AMBER")  setShelf(shelf1, 255,140,0);
  else if (cmd == "SHELF1_RED")    setShelf(shelf1, 220,20,20);
  else if (cmd == "SHELF1_BLUE")   setShelf(shelf1, 20,80,220);
  else if (cmd == "SHELF2_GREEN")  setShelf(shelf2, 0,200,60);
  else if (cmd == "SHELF2_AMBER")  setShelf(shelf2, 255,140,0);
  else if (cmd == "SHELF2_RED")    setShelf(shelf2, 220,20,20);
  else if (cmd == "SHELF3_GREEN")  setShelf(shelf3, 0,200,60);
  else if (cmd == "SHELF3_AMBER")  setShelf(shelf3, 255,140,0);
  else if (cmd == "SHELF3_RED")    setShelf(shelf3, 220,20,20);

  // Payment status
  else if (cmd == "PAID")          { paid = true;  Serial.println("ACK_PAID"); }
  else if (cmd == "RESET")         { paid = false; Serial.println("ACK_RESET"); }
  else if (cmd == "BUZZER_ON")     { for(int i=0;i<3;i++){digitalWrite(BUZZER_PIN,HIGH);delay(200);digitalWrite(BUZZER_PIN,LOW);delay(150);} }

  // OLED update: format "OLED:ItemName:ItemPrice:Total"
  else if (cmd.startsWith("OLED:")) {
    String data = cmd.substring(5);
    int i1 = data.indexOf(':'), i2 = data.lastIndexOf(':');
    String name  = data.substring(0, i1);
    String price = data.substring(i1+1, i2);
    String total = data.substring(i2+1);
    oled.clearDisplay(); oled.setCursor(0,0);
    oled.setTextSize(1); oled.println(name);
    oled.print("Price: Rs"); oled.println(price);
    oled.println("──────────────");
    oled.setTextSize(2);
    oled.print("Rs"); oled.println(total);
    oled.display();
  }
}

void loop() {
  // Read serial commands from Pi
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    processCommand(cmd);
  }

  // Exit theft detection
  if (digitalRead(IR_PIN) == LOW && !paid) {
    delay(50);
    if (digitalRead(IR_PIN) == LOW) {
      Serial.println("THEFT_ALERT");
      processCommand("BUZZER_ON");
      setShelf(shelf1,220,0,0); setShelf(shelf2,220,0,0); setShelf(shelf3,220,0,0);
      delay(2000);
      setShelf(shelf1,0,200,60); setShelf(shelf2,0,200,60); setShelf(shelf3,0,200,60);
    }
  }
}
🧾

Module 3 — Auto Billing + Digital Cart

Python Flask

A Flask web app runs on the Pi and serves a live cart page on your local network. Every product scan updates the cart in real time. Open it on any phone or laptop connected to the same WiFi.

"""
Module 3: Auto Billing Web App (Flask)
Run: python3 billing_app.py
Open: http://[Pi IP Address]:5000
"""

from flask import Flask, render_template_string, jsonify
import qrcode, io, base64

app   = Flask(__name__)
cart  = []       # shared cart — updated by Module 1
PAID  = [False]

CART_PAGE = """
<!DOCTYPE html><html><head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="refresh" content="3">
<title>Smart Cart</title>
<style>
body{font-family:sans-serif;max-width:420px;margin:auto;padding:20px;background:#F4FAF5;}
h2{color:#1A9E4A;} .item{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid #C8DDD0;}
.total{font-size:1.4rem;font-weight:bold;color:#0E6B30;margin-top:16px;}
.pay-btn{background:#1A9E4A;color:#fff;padding:14px 28px;border:none;border-radius:999px;font-size:1rem;cursor:pointer;width:100%;margin-top:12px;}
</style></head><body>
<h2>🛒 Your Smart Cart</h2>
{% for item in cart %}
<div class="item"><span>{{ item.name }}</span><span>₹{{ "%.2f"|format(item.price) }}</span></div>
{% endfor %}
<div class="total">Total: ₹{{ "%.2f"|format(total) }}</div>
<form action="/pay"><button class="pay-btn">Pay by QR Code →</button></form>
</body></html>
"""

@app.route("/")
def index():
    total = sum(i["price"] for i in cart)
    return render_template_string(CART_PAGE, cart=cart, total=total)

@app.route("/add/<name>/<float:price>")
def add_item(name, price):
    cart.append({"name": name, "price": price})
    return jsonify({"status": "ok", "items": len(cart)})

@app.route("/pay")
def pay():
    total = sum(i["price"] for i in cart)
    receipt = "\n".join(ff"{i['name']}: Rs{i['price']:.2f}" for i in cart)
    receipt += ff"\n\nTOTAL: Rs{total:.2f}\nThank you for shopping!"

    qr = qrcode.make(receipt)
    buf = io.BytesIO(); qr.save(buf, format="PNG")
    img_b64 = base64.b64encode(buf.getvalue()).decode()
    PAID[0] = True

    html = f"""<html><body style="text-align:center;padding:20px;">
    <h2 style="color:#1A9E4A;">Scan to Confirm Payment</h2>
    <img src="data:image/png;base64,{img_b64}" width="220">
    <p>Total: <b>₹{total:.2f}</b></p></body></html>"""
    return html

@app.route("/paid_status")
def paid_status(): return jsonify({"paid": PAID[0]})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)
📱

Module 4 — QR Code Payment

Python qrcode + TFT LCD

When the customer clicks "Pay by QR Code" in the billing web app, the Flask server generates a QR code containing the full itemised receipt. It also displays the QR code on the TFT LCD screen at the checkout counter using the code below.

"""
Module 4: Display QR code on TFT LCD (ST7735)
Called from billing app after /pay endpoint is hit
"""

import qrcode
from PIL import Image
import ST7735   # pip3 install st7735; handles SPI display

def show_qr_on_lcd(receipt_text):
    # Generate QR image
    qr  = qrcode.QRCode(box_size=2, border=2)
    qr.add_data(receipt_text)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white")
    img = img.resize((128, 128))   # ST7735 is 128×160

    # Show on TFT LCD
    disp = ST7735.ST7735(port=0, cs=ST7735.BG_SPI_CS_FRONT, dc=9, backlight=12, rotation=270)
    disp.begin()
    disp.display(img)
    print("✅ QR Code displayed on LCD — customer can scan to pay!")
📱 How payment works in the demo: The QR code contains the itemised receipt as text. When a customer "scans" it with their phone, they see the bill. In a real store this would link to UPI/Razorpay — for the demo it just shows the receipt, which is perfect for a school demonstration!
🚨

Module 5 — Exit Theft Detection

IR Sensor + Arduino

The IR break-beam sensor is already handled in the Arduino code above. The Pi monitors the Arduino's serial output for "THEFT_ALERT" messages and responds accordingly. Here's the Pi-side listener:

"""
Module 5: Pi-side theft detection listener
Runs as a thread alongside Module 1 (AI camera)
"""

import serial, threading, requests

def listen_for_alerts(ser_port):
    ard = serial.Serial(ser_port, 9600, timeout=1)
    while True:
        line = ard.readline().decode().strip()
        if line == "THEFT_ALERT":
            paid = requests.get("http://localhost:5000/paid_status").json()["paid"]
            if not paid:
                print("🚨 THEFT ALERT! Cart not paid — buzzer triggered!")
                # Arduino already triggers buzzer autonomously
                # Here we could also send a notification, log the event, etc.
            else:
                print("✅ Exit OK — cart was paid.")
                ard.write(b"RESET\n")   # reset paid flag for next customer

# Start as background thread
alert_thread = threading.Thread(target=listen_for_alerts, args=("/dev/ttyUSB0",), daemon=True)
alert_thread.start()
🎁

Module 6 — Personalised Offers

Face Recognition + OpenCV

When the ultrasonic sensor (HC-SR04 on the Arduino) detects a customer approaching the checkout counter, it sends "CUSTOMER_NEAR" over serial. The Pi then captures a face image and checks it against a database of registered customers to show a personalised discount.

"""
Module 6: Personalised Offers via Face Recognition
Prerequisites: pip3 install face_recognition
Build face DB by running: python3 enroll_face.py CustomerName
"""

import face_recognition, cv2, pickle, os
from picamera2 import Picamera2

# ── Customer offer database ──────────────────────────────────────
OFFERS = {
    "Arjun":    "Welcome back Arjun! 15% off snacks today 🎉",
    "Priya":    "Hi Priya! Buy 2 get 1 free on drinks 🥤",
    "Ravi":     "Hey Ravi! ₹20 off your total today! 💰",
    "Unknown":  "Welcome! Sign up for personalised offers.",
}

# Load face encodings database (built using enroll_face.py)
db_path = "face_db.pkl"
face_db = pickle.load(open(db_path, "rb")) if os.path.exists(db_path) else {}

def recognise_customer(frame):
    rgb   = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    locs  = face_recognition.face_locations(rgb)
    encod = face_recognition.face_encodings(rgb, locs)

    for enc in encod:
        for name, known_enc in face_db.items():
            match = face_recognition.compare_faces([known_enc], enc, tolerance=0.5)
            if match[0]:
                return name
    return "Unknown"

def greet_customer(serial_port):
    """Called when Arduino reports CUSTOMER_NEAR over serial."""
    cam = Picamera2(); cam.start()
    frame = cv2.cvtColor(cam.capture_array(), cv2.COLOR_RGB2BGR)
    cam.stop()

    name   = recognise_customer(frame)
    offer  = OFFERS.get(name, OFFERS["Unknown"])
    serial_port.write(ff"OLED:{name}:{offer[:20]}:0\n".encode())
    print(ff"👤 Customer: {name}  |  Offer: {offer}")
    return name, offer
👤 Enroll new customers by taking a photo with the Pi camera and saving the face encoding using pickle. Keep your customer database small (5–10 people) for fast recognition on the Pi 4 without extra hardware.

🛑 Safety Rules

  • Adult supervision required for all wiring, especially LED power supply connections and any soldering.
  • Use the dedicated 5V 2A supply for the LED strips — never power them from the Arduino's 5V pin (it can only provide ~500mA total).
  • Keep the Pi's USB-C power supply outside the store enclosure with good ventilation — the Pi 4 generates heat during AI processing.
  • Always power off before changing any wiring — hot-swapping components is the #1 cause of damaged boards.
  • Never enroll real people's faces in your database without their knowledge and permission.
  • Keep the OpenAI API key private if you use ChatGPT for any AI features.
  • The buzzer can be surprisingly loud — test it in a room where sudden noise won't startle anyone.
  • The IR break-beam sensor emits invisible infrared light — avoid looking directly at the emitter LED.
Checkout Desk

Troubleshooting

The AI camera doesn't recognise my products reliably.

The model needs more training data. Go back to Teachable Machine and add 50–100 more photos per product, especially in the lighting conditions of your scan zone. Make sure there are no other objects in the camera frame when scanning.

The shelf LEDs flicker or show wrong colours.

Check the 300Ω resistor on each data wire — without it, noise can corrupt the signal. Also make sure the LED strip power comes from the external 5V 2A supply, not the Arduino.

The Flask web app shows "cart empty" even after scanning.

The Module 1 camera code calls add_to_cart() locally but also needs to call the Flask /add/ endpoint. Make sure both scripts are running simultaneously using Python threading or two terminal sessions.

Face recognition is very slow or crashes.

The face_recognition library is CPU-intensive. On Pi 4 expect 2–3 seconds per recognition. Try reducing the frame resolution to 320×240 for faster processing, or add a small cooling fan to your Pi.

The exit buzzer triggers even when the cart is paid.

There's likely a timing issue between the Flask server updating the PAID flag and the Arduino's IR detection. Add a 3-second debounce delay after payment confirmation before re-enabling the exit alarm.

The Pi serial connection to Arduino keeps disconnecting.

Use a proper USB cable (not a charge-only cable) and specify the correct port: run ls /dev/ttyUSB* on the Pi to confirm the Arduino's port name. Add error handling with try/except around all serial reads.

Store Intel

Fun Facts About Smart Supermarkets

2018

Amazon Go opened its first cashier-less store in Seattle — using the same AI + camera technology concept you just built.

800+

Camera sensors inside a single Amazon Go store — your miniature version needs just one!

₹0.40

Estimated cost per ChatGPT API call for product descriptions — making AI genuinely affordable for small builds.

2025

India's smart retail market is expected to reach ₹1.2 trillion — engineers who understand this technology are in huge demand.

Expansion Packs

Next Level Upgrades

LEVEL 2

Real UPI/Razorpay Payment

Generate a real Razorpay payment link inside the QR code so customers can actually pay with UPI.

LEVEL 2

Inventory Management Dashboard

Build a web dashboard that shows live stock levels for all products with colour-coded alerts.

LEVEL 3

Robotic Shelf Restocking Arm

Add a servo robotic arm that picks items from a storage bin and places them on low-stock shelves automatically.

LEVEL 3

Voice-Activated Price Enquiry

Add a microphone — customers ask "What is the price of chocolate?" and the Pi responds using ChatGPT + text-to-speech.

LEVEL 4

Multiple Camera Zones

Add cameras at each shelf to detect which items are removed, enabling true Amazon-Go-style grab-and-go shopping.

LEVEL 4

Customer Traffic Analytics

Log entry/exit times, most-bought products, and peak shopping hours to a database — then visualise with a chart dashboard.

You've just built in miniature what took Amazon billions of rupees and hundreds of engineers to build at scale. Every single concept you used here — computer vision, real-time inventory, cashless payment, and personalisation — is in use in real stores right now. 🏪

DIY AI Smart Miniature Supermarket — Raspberry Pi + Arduino Robotics Project for Kids 🛒

Tags: smart supermarket robotics · AI product recognition · shelf LED project · auto billing · QR payment · theft detection · STEM project · Raspberry Pi Arduino

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
Young inventors love it!
🖨️
3D Print
All parts
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course