Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi Zero & ESP32-CAM Based Object Detection System with Ultrasonic Distance Measurement and Audio Feedback

View and Edit Project In Cirkit DesignerImage of Raspberry Pi Zero & ESP32-CAM Based Object Detection System with Ultrasonic Distance Measurement and Audio Feedback

Circuit Documentation

Summary

This circuit integrates a Raspberry Pi Zero with an ESP32-CAM module, an HC-SR04 Ultrasonic Sensor, and a Speaker. The primary function of this system is to capture images using the ESP32-CAM, process them for object detection, and provide audio feedback through the Speaker. The HC-SR04 Ultrasonic Sensor is used to measure the distance to objects. The Raspberry Pi Zero serves as the central processing unit, controlling the ESP32-CAM, processing sensor data, and driving the Speaker for audio output.

Component List

ESP32-CAM

Raspberry Pi Zero

Speaker

HC-SR04 Ultrasonic Sensor

Wiring Details

ESP32-CAM

Raspberry Pi Zero

Speaker

HC-SR04 Ultrasonic Sensor

Documented Code

/*
 * This Arduino Sketch is designed for a Raspberry Pi Zero connected to an ESP32 CAM,
 * an HC-SR04 Ultrasonic Sensor, and a Speaker. The system captures images using the
 * ESP32 CAM, processes them for object detection, and provides audio feedback via
 * the speaker. Additionally, the HC-SR04 sensor measures distance to objects.
 */

#include <WiFi.h>
#include <HTTPClient.h>
#include <ESP32CAM.h>
#include <Ultrasonic.h>
#include <TTS.h>

// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// ESP32 CAM URL
const char* esp32_cam_url = "http://<ESP32_CAM_IP_ADDRESS>/capture";

// Ultrasonic Sensor pins
#define TRIG_PIN 23
#define ECHO_PIN 24

// Speaker pin
#define SPEAKER_PIN 18

// Initialize Ultrasonic Sensor
Ultrasonic ultrasonic(TRIG_PIN, ECHO_PIN);

// Initialize TTS
TTS tts(SPEAKER_PIN);

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Initialize ESP32 CAM
  ESP32CAM.begin();
}

void loop() {
  // Capture image from ESP32 CAM
  HTTPClient http;
  http.begin(esp32_cam_url);
  int httpCode = http.GET();
  if (httpCode == HTTP_CODE_OK) {
    WiFiClient* stream = http.getStreamPtr();
    ESP32CAM.capture(stream);
    if (ESP32CAM.detectObject()) {
      tts.speak("Object Detected");
    } else {
      tts.speak("No Object Detected");
    }
  } else {
    Serial.println("Failed to capture image");
  }
  http.end();

  // Measure distance using Ultrasonic Sensor
  long distance = ultrasonic.MeasureInCentimeters();
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Delay before next loop
  delay(1000);
}

This code is designed to be uploaded to the Raspberry Pi Zero, which controls the ESP32-CAM for image capture and object detection, the HC-SR04 Ultrasonic Sensor for distance measurement, and the Speaker for audio feedback. The code includes setup for WiFi connectivity, initialization of the camera and sensor modules, and a loop that captures images, detects objects, measures distance, and provides audio output.