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

ESP32-CAM and Ultrasonic Sensor-Based Smart Conveyor System with IoT Integration

View and Edit Project In Cirkit DesignerImage of ESP32-CAM and Ultrasonic Sensor-Based Smart Conveyor System with IoT Integration

Circuit Documentation

Summary

This circuit is designed to manage a conveyor system for sorting fruits using an ESP32 microcontroller. The system includes pushbuttons, a relay, an ultrasonic sensor, and an ESP32-CAM. The ESP32 microcontroller reads inputs from the pushbuttons and the ultrasonic sensor, controls the relay to manage the conveyor, and interfaces with the ESP32-CAM to capture images.

Component List

  1. Pushbutton

    • Description: A simple pushbutton used to provide user input.
    • Pins: Pin 1, Pin 2, Pin 3, Pin 4
  2. 12V Single Channel Relay

    • Description: A relay module used to control the conveyor motor.
    • Pins: NC, COM, NO, IN, GND, VCC
  3. 12V Power Supply

    • Description: Provides 12V power to the circuit.
    • Pins: Positive, Negative
  4. Conveyor

    • Description: A conveyor belt system used to transport fruits.
    • Pins: Positive, Negative
  5. ESP32 - CAM

    • Description: A microcontroller with a built-in camera module.
    • Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
  6. HC-SR04 Ultrasonic Sensor

    • Description: An ultrasonic sensor used to measure the distance of objects.
    • Pins: VCC, TRIG, ECHO, GND
  7. ESP32

    • Description: A microcontroller used to control the entire system.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT

Wiring Details

Pushbutton 1

Pushbutton 2

Pushbutton 3

12V Single Channel Relay

12V Power Supply

Conveyor

ESP32 - CAM

HC-SR04 Ultrasonic Sensor

ESP32

Documented Code

/*
 * Advanced Sorting Fruit with IoT and Artificial Intelligence
 * This code controls an ESP32 microcontroller to manage a conveyor system
 * with pushbuttons, a relay, an ultrasonic sensor, and an ESP32-CAM.
 * The system sorts fruits based on distance measurements and captures images.
 */

#define BUTTON1_PIN 12
#define BUTTON2_PIN 14
#define BUTTON3_PIN 27
#define RELAY_PIN 5
#define TRIG_PIN 2
#define ECHO_PIN 15
#define CAM_PIN 4

void setup() {
  pinMode(BUTTON1_PIN, INPUT);
  pinMode(BUTTON2_PIN, INPUT);
  pinMode(BUTTON3_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(CAM_PIN, OUTPUT);
  Serial.begin(115200);
}

long readUltrasonicDistance() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  long duration = pulseIn(ECHO_PIN, HIGH);
  long distance = duration * 0.034 / 2;
  return distance;
}

void loop() {
  if (digitalRead(BUTTON1_PIN) == HIGH) {
    Serial.println("Button 1 Pressed");
  }
  if (digitalRead(BUTTON2_PIN) == HIGH) {
    Serial.println("Button 2 Pressed");
  }
  if (digitalRead(BUTTON3_PIN) == HIGH) {
    Serial.println("Button 3 Pressed");
  }
  long distance = readUltrasonicDistance();
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  if (distance < 10) {
    digitalWrite(RELAY_PIN, HIGH);
    Serial.println("Relay ON");
  } else {
    digitalWrite(RELAY_PIN, LOW);
    Serial.println("Relay OFF");
  }
  delay(1000);
}

This code initializes the pins for the pushbuttons, relay, ultrasonic sensor, and ESP32-CAM. It reads the state of the pushbuttons and the distance from the ultrasonic sensor, controlling the relay based on the distance measurement. The code also prints the status of the pushbuttons and the distance measurement to the serial monitor.