Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Camera & Vision Modules

AI Tinyml with Person Detection on ESP32-CAM Offline

AI Tinyml with Person Detection on ESP32-CAM Offline

March 11, 2026 /Posted byJayesh Jain / 0

Running TinyML person detection on ESP32-CAM offline brings AI vision capabilities to a ₹500 device without any cloud dependency. TensorFlow Lite Micro runs a quantised MobileNet model directly on the ESP32’s CPU, enabling real-time person detection at the edge. This tutorial covers model deployment, inference code, and practical applications for Indian makers interested in edge AI.

Table of Contents

  • What is TinyML?
  • Pre-trained Person Detection Model
  • Arduino Setup for TFLite Micro
  • Inference Code
  • Interpreting Output and Triggering Actions
  • Optimisation Tips
  • Frequently Asked Questions

What is TinyML?

TinyML (Tiny Machine Learning) refers to machine learning models optimised to run on microcontrollers and edge devices with limited memory and compute. Key characteristics:

  • Models are quantised to INT8 or INT4 to reduce size (from MBs to KBs)
  • No internet connection required — inference runs locally
  • Low power consumption (milliwatts vs watts for server-based AI)
  • Latency is predictable — no network variability
  • Privacy: no images sent to cloud

The ESP32-CAM with 4MB PSRAM can run models up to ~500KB in size — enough for simple object detection and classification tasks.

Recommended: Arducam 2MP OV2640 Camera Shield for Arduino — For higher-quality TinyML input images on Arduino, the Arducam SPI camera provides cleaner JPEG frames than the ESP32-CAM’s onboard camera.

Pre-trained Person Detection Model

Google’s open-source person detection model for microcontrollers is the starting point. It’s included in the TensorFlow Lite for Microcontrollers examples repository:

  • Input: 96×96 greyscale image
  • Output: Two scores — person / no person
  • Model size: ~300KB (INT8 quantised)
  • Accuracy: ~89% on test set (real-world lower in variable conditions)
  • Inference time on ESP32: ~200–400ms per frame

Arduino Setup for TFLite Micro

// Install these libraries in Arduino IDE Library Manager:
// 1. "TensorFlow Lite for Microcontrollers" by EloquentTinyML
//    (or the Harvard Edge Impulse version)
// 2. ESP32 board support (Espressif)

// Board settings for ESP32-CAM:
// Board: AI Thinker ESP32-CAM
// CPU Freq: 240 MHz (max for inference speed)
// Upload Speed: 115200

// Memory requirements:
// Model: ~300KB Flash
// Tensor arena: ~100KB PSRAM
// Total: ~400KB - fits in ESP32-CAM 4MB Flash

Inference Code

#include "esp_camera.h"
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "person_detect_model_data.h"  // From TFLite examples

// AI Thinker pin definitions (same as before)
#define PWDN_GPIO_NUM 32
// ... (same camera config as RTSP example)

constexpr int kTensorArenaSize = 100 * 1024;
uint8_t tensor_arena[kTensorArenaSize];

tflite::AllOpsResolver resolver;
const tflite::Model* model;
tflite::MicroInterpreter* interpreter;
TfLiteTensor* input;

void setup() {
  Serial.begin(115200);
  
  // Camera init (same config, but GRAYSCALE, 96x96)
  camera_config_t config;
  // ... fill in pin definitions ...
  config.pixel_format = PIXFORMAT_GRAYSCALE;
  config.frame_size = FRAMESIZE_96X96;
  config.fb_count = 1;
  esp_camera_init(&config);
  
  // Load TFLite model
  model = tflite::GetModel(g_person_detect_model_data);
  interpreter = new tflite::MicroInterpreter(
    model, resolver, tensor_arena, kTensorArenaSize
  );
  interpreter->AllocateTensors();
  input = interpreter->input(0);
  
  Serial.println("TinyML Person Detection Ready");
}

void loop() {
  camera_fb_t *fb = esp_camera_fb_get();
  if (!fb) { Serial.println("Camera capture failed"); return; }
  
  // Copy 96x96 grayscale frame to model input
  for (int i = 0; i data.int8[i] = (int8_t)fb->buf[i] - 128;
  }
  esp_camera_fb_return(fb);
  
  // Run inference
  TfLiteStatus status = interpreter->Invoke();
  if (status != kTfLiteOk) {
    Serial.println("Inference failed");
    return;
  }
  
  // Get output scores
  TfLiteTensor* output = interpreter->output(0);
  int8_t no_person_score = output->data.int8[0];
  int8_t person_score = output->data.int8[1];
  
  Serial.printf("Person: %d, No Person: %d
", 
                person_score, no_person_score);
  
  if (person_score > no_person_score) {
    Serial.println("PERSON DETECTED!");
    // Trigger GPIO, LED, buzzer, relay, etc.
    digitalWrite(LED_GPIO_NUM, HIGH);
  } else {
    digitalWrite(LED_GPIO_NUM, LOW);
  }
  
  delay(100);
}

Interpreting Output and Triggering Actions

The model outputs two INT8 scores. A score above 100 (out of 127) indicates high confidence. Typical thresholds:

  • person_score > 100: High confidence person detected → trigger security alert, unlock door, turn on light
  • person_score > 50: Moderate confidence → log detection, increment counter
  • person_score ≤ 0: No person
Recommended: Arducam 8MP PTZ Camera for Raspberry Pi — For more advanced TinyML projects needing higher resolution and pan-tilt tracking when a person is detected.

Optimisation Tips

  • Set CPU to 240 MHz (maximum) in setCpuFrequencyMhz(240)
  • Use PSRAM for tensor arena: uint8_t* tensor_arena = (uint8_t*)heap_caps_malloc(kTensorArenaSize, MALLOC_CAP_SPIRAM)
  • Run inference on every 3rd frame — person positions change slowly
  • Consider Edge Impulse (edgeimpulse.com) for training custom models and deploying to ESP32 — they have an excellent free tier and Arduino library export

Frequently Asked Questions

Can I train my own custom TinyML model for ESP32-CAM?

Yes — Edge Impulse is the best platform for this. Collect images, annotate them in the web interface, train a model, and export an Arduino library. The entire process from data collection to deployment takes a few hours. Edge Impulse’s free tier supports models that fit on ESP32. Popular custom models: face detection, specific product detection, gesture recognition, defect detection for Indian manufacturing QC.

How accurate is the person detection model on ESP32-CAM?

In good lighting with a frontal view of a person, accuracy is typically 80–90%. In challenging conditions (backlit, partial view, unusual angles, Indian sarees/traditional clothing), accuracy drops to 60–75%. For security applications, combine person detection as a first filter with a higher-quality secondary check (Telegram alert + human review) rather than using it as a sole access control mechanism.

What other TinyML models can run on ESP32-CAM?

Models that fit in ~300KB INT8 quantised and process 96×96 images: keyword spotting (with microphone, not camera), gesture recognition (hand gestures), digit recognition, simple fruit/object classification. Models requiring higher resolution (96×96 is very low) or more processing power are better suited for Raspberry Pi with TensorFlow Lite or Jetson Nano with CUDA acceleration.

Shop Camera & Vision Modules at Zbotic →

Tags: edge AI offline India, person detection ESP32, TensorFlow Lite ESP32, TinyML ESP32-CAM, TinyML tutorial
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Grid-Tied Solar System: Net Me...
blog grid tied solar system net metering in india explained 599001
blog raspberry pi home server media iot and vpn all in one india 599005
Raspberry Pi Home Server: Medi...

Related posts

Svg%3E
Read more

Endoscope Camera Module: PCB Inspection and Industrial Use

April 1, 2026 0
An endoscope camera module is an invaluable tool for PCB inspection, industrial equipment maintenance, and quality control tasks where direct... Continue reading
Svg%3E
Read more

Number Plate Recognition System: ESP32-CAM ANPR Project India

April 1, 2026 0
Building a number plate recognition system with ESP32-CAM is an affordable approach to automatic number plate recognition (ANPR) for Indian... Continue reading
Svg%3E
Read more

Machine Vision with OpenCV: Raspberry Pi Object Detection Guide

April 1, 2026 0
Running OpenCV on a Raspberry Pi for object detection opens up countless applications, from industrial quality inspection to smart doorbell... Continue reading
Svg%3E
Read more

Arducam vs Raspberry Pi Camera: Which Camera Module to Choose

April 1, 2026 0
Choosing between Arducam and Raspberry Pi camera modules is one of the first decisions for any vision project. Both connect... Continue reading
Svg%3E
Read more

360-Degree Camera Stitching Project with OpenCV and Pi

March 11, 2026 0
Creating a 360-degree camera using OpenCV image stitching with Raspberry Pi is an ambitious computer vision project that combines multiple... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now