
Hardware: ESP32 + Raspberry Pi 4 / 5
AI type: Hybrid AI (Sensor Trigger + Computer Vision)
--------------------------------------------------
Overview
This project demonstrates a hybrid AI system where an ESP32 with a motion sensor
acts as a low-power trigger, while a Raspberry Pi runs AI vision only when motion
is detected.
This approach saves power and CPU resources by activating AI processing only
when needed.
--------------------------------------------------
What you build
- ESP32 motion detection node
- Raspberry Pi AI vision system
- Wireless trigger via Wi-Fi
- Fully local processing
--------------------------------------------------
Required hardware
- ESP32 development board
- PIR motion sensor (HC-SR501 or compatible)
- Raspberry Pi 4 or Raspberry Pi 5
- Camera (Pi Camera or USB camera)
- Wi-Fi network
--------------------------------------------------
Software requirements
ESP32:
- Arduino IDE
- WiFi library
Raspberry Pi:
- Raspberry Pi OS
- Python 3
- OpenCV
- Ultralytics YOLO
--------------------------------------------------
System architecture
1. ESP32 monitors motion using a PIR sensor
2. When motion is detected, ESP32 sends a Wi-Fi message
3. Raspberry Pi receives the trigger
4. AI vision starts only on demand
--------------------------------------------------
ESP32 Arduino code (motion trigger)
#include <WiFi.h>
const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";
const char* pi_ip = "192.168.1.100";
const int pi_port = 5000;
int pirPin = 13;
void setup() {
pinMode(pirPin, INPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
WiFiClient client;
if (client.connect(pi_ip, pi_port)) {
client.println("MOTION");
client.stop();
}
delay(3000);
}
}
--------------------------------------------------
Raspberry Pi Python trigger listener
import socket
import subprocess
HOST = "0.0.0.0"
PORT = 5000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((HOST, PORT))
sock.listen(1)
print("Waiting for ESP32 trigger...")
while True:
conn, addr = sock.accept()
data = conn.recv(1024).decode().strip()
if data == "MOTION":
print("Motion detected - starting AI vision")
subprocess.Popen(["python3", "ai_vision.py"])
conn.close()
--------------------------------------------------
Raspberry Pi AI vision example (ai_vision.py)
import cv2
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture(0)
for i in range(100):
ret, frame = cap.read()
if not ret:
break
results = model(frame, verbose=False)
cv2.imshow("AI Vision", frame)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()
--------------------------------------------------
How it works
The ESP32 continuously monitors motion with very low power usage.
When motion is detected, it sends a simple trigger message to the Raspberry Pi.
The Raspberry Pi then activates AI vision for a limited time.
--------------------------------------------------
Practical applications
- Smart surveillance systems
- Wildlife monitoring
- Energy-efficient AI cameras
- Security triggers
--------------------------------------------------
Limitations
- Requires Wi-Fi connectivity
- PIR detects motion, not object type
- AI runtime duration must be managed
--------------------------------------------------
Conclusion
By combining ESP32 sensors with Raspberry Pi AI vision, efficient hybrid AI systems
can be built on affordable hardware.
AI without millions is achieved through smart architecture, not expensive hardware.