Kieu Vu
Published © GPL3+

ESP32-CAM AI Vision Rover: Line Following & Obstacle Avoidan

A compact AI-powered rover featuring the ESP32-CAM. It integrates computer vision for real-time tracking, path following, and obstacle avoid

IntermediateProtip96
ESP32-CAM AI Vision Rover: Line Following & Obstacle Avoidan

Things used in this project

Hardware components

ESP32 Camera Module Development Board
M5Stack ESP32 Camera Module Development Board
×1
SparkFun Motor Driver - Dual TB6612FNG (1A)
SparkFun Electronics SparkFun Motor Driver - Dual TB6612FNG (1A)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Pi Adaptor
Breadboard Mates Pi Adaptor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Code

ESP32-CAM Line Following Code (Simplified Logic)

C/C++
#include "esp_camera.h"
#include <WiFi.h>

// Define motor control pins
const int motorLeftForward = 12;
const int motorLeftBackward = 13;
const int motorRightForward = 14;
const int motorRightBackward = 15;

void setup() {
  Serial.begin(115200);
  
  // Initialize motor pins as output
  pinMode(motorLeftForward, OUTPUT);
  pinMode(motorLeftBackward, OUTPUT);
  pinMode(motorRightForward, OUTPUT);
  pinMode(motorRightBackward, OUTPUT);
  
  // Initialize camera module
  // Note: Configure camera settings according to your specific ESP32-CAM model
}

void loop() {
  camera_fb_t * fb = esp_camera_fb_get();
  if (!fb) return;

  // Simple image processing: Calculate the center of mass based on pixel brightness
  // If the left side is brighter (e.g., white line), turn left; if right, turn right
  int centerMass = calculateLineCenter(fb->buf, fb->len);
  
  if (centerMass < 100) {
    turnLeft();
  } else if (centerMass > 150) {
    turnRight();
  } else {
    moveForward();
  }

  esp_camera_fb_return(fb);
  delay(50);
}

// Placeholder for line tracking algorithm
int calculateLineCenter(uint8_t * buf, size_t len) {
  // Implement your pixel analysis logic here
  return 128; // Return the detected center position
}

void moveForward() { /* Implement motor forward logic */ }
void turnLeft() { /* Implement motor left turn logic */ }
void turnRight() { /* Implement motor right turn logic */ }

Credits

Kieu Vu
10 projects • 0 followers
Electronics sourcing expert at lisleapex. Focused on component integrity, EOL solutions, and next-gen semiconductor trends.

Comments