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

Raspberry Pi 5-Based Obstacle-Avoiding Robot with Ultrasonic Sensors and DC Motors

View and Edit Project In Cirkit DesignerImage of Raspberry Pi 5-Based Obstacle-Avoiding Robot with Ultrasonic Sensors and DC Motors

Circuit Documentation

Summary

This circuit is designed to control two DC motors using a Raspberry Pi 5 and a ZK-BM1 10A Motor Driver. Additionally, it includes three HC-SR05 ultrasonic sensors for distance measurement. The Raspberry Pi 5 is powered via a Micro USB to Cable (2 Pin) adapter, and the entire system is powered by a 12V battery with a DCDC 12V/5V 3A converter to provide the necessary 5V for the sensors and Raspberry Pi.

Component List

  1. Raspberry Pi 5

    • Description: A single-board computer used for controlling the motor driver and reading sensor data.
    • Pins: Type-C, Micro HDMI 1, Micro HDMI 2, Camera 1, Camera 2, PoE, Fan, PCIe, USB 3.0, USB 2.0, Ethernet, 5V, GND, 3.3v, GPIO 14, GPIO 15, GPIO 18, GPIO 23, GPIO 24, GPIO 25, GPIO 8, GPIO 7, GPIO 1, GPIO 12, GPIO 16, GPIO 20, GPIO 21, GPIO 2, GPIO 3, GPIO 4, GPIO 17, GPIO 27, GPIO 22, GPIO 10, GPIO 9, GPIO 11, GPIO 0, GPIO 5, GPIO 6, GPIO 13, GPIO 19, GPIO 26
  2. DC Motor RC 7.4V

    • Description: A DC motor used for driving the system.
    • Pins: Negative, Positive
  3. ZK-BM1 10A Motor Driver

    • Description: A motor driver used to control the DC motors.
    • Pins: B+, B-, M1A, M1B, M2A, M2B, IN1, IN2, IN3, IN4, GND
  4. 12V Battery

    • Description: A power source for the circuit.
    • Pins: -, +
  5. DCDC 12V/5V 3A

    • Description: A DC-DC converter to step down 12V to 5V.
    • Pins: 12V (+), GND, 5V (+), Vin (+), V in (-)
  6. Micro USB to Cable (2 Pin)

    • Description: A cable to power the Raspberry Pi.
    • Pins: Micro USB, +, -
  7. HC-SR05

    • Description: An ultrasonic sensor for distance measurement.
    • Pins: VCC, TRIG, GND, ECHO, OUT

Wiring Details

Raspberry Pi 5

DC Motor RC 7.4V

ZK-BM1 10A Motor Driver

12V Battery

DCDC 12V/5V 3A

Micro USB to Cable (2 Pin)

HC-SR05

Code Documentation

const int IN1 = 14;
const int IN2 = 15;
const int IN3 = 18;
const int IN4 = 23;
const int TRIG = 24;
const int ECHO = 25;

void setup() 
{
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  Serial.begin(9600);
}

void loop() 
{  
  long duration, distance;
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  duration = pulseIn(ECHO, HIGH);
  distance = (duration / 2) / 29.1;
  Serial.print("Distance:10");
  Serial.print(distance);
  Serial.println("10cm");
  if (distance < 10) 
  {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }
   else 
   {
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
  }

  delay(100); 
}

Code Explanation