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

Bluetooth-Controlled Smart Robot Car with Ultrasonic Obstacle Avoidance and Water Pump

View and Edit Project In Cirkit DesignerImage of Bluetooth-Controlled Smart Robot Car with Ultrasonic Obstacle Avoidance and Water Pump

Smart Robot Car Circuit Documentation

Summary

The Smart Robot Car circuit is designed to control a robotic vehicle with wireless communication capabilities. It features an Arduino UNO microcontroller interfaced with an L293D motor driver shield to drive two DC motors and a water pump. The circuit also includes an HC-SR04 ultrasonic distance sensor for obstacle detection, a Bluetooth HC-06 module for wireless communication, and a servo motor for precise angular movement. Power management is handled by a 4 x AAA battery mount and a rocker switch.

Component List

Arduino UNO

L293D Motor Driver Shield

4 x AAA Battery Mount

HC-SR04 Ultrasonic Distance Sensor

Bluetooth HC-06

DC Motor (x2)

Rocker Switch

Mini Diaphragm Water Pump

SG90 Servo Motor

Wiring Details

Arduino UNO

L293D Motor Driver Shield

4 x AAA Battery Mount

HC-SR04 Ultrasonic Distance Sensor

Bluetooth HC-06

DC Motors

Rocker Switch

Mini Diaphragm Water Pump

SG90 Servo Motor

Documented Code

/*
 * Smart Robot Car
 * This code interfaces with an L293D motor driver shield to drive two DC motors
 * and a water pump, controls a servo motor, uses an HC-SR04 ultrasonic sensor
 * for distance sensing, and communicates wirelessly via a Bluetooth HC-06
 * module. Power is supplied by a 4 x AAA battery mount and managed by a
 * rocker switch.
 */

#include <Servo.h>

// Pin definitions
const int trigPin = A1;
const int echoPin = A0;
const int motor1Pin1 = 10;
const int motor1Pin2 = 11;
const int motor2Pin1 = 12;
const int motor2Pin2 = 13;
const int pumpPin1 = 8;
const int pumpPin2 = 9;
const int servoPin = 2;

Servo myServo;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize motor pins
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(pumpPin1, OUTPUT);
  pinMode(pumpPin2, OUTPUT);

  // Initialize ultrasonic sensor pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // Attach servo motor
  myServo.attach(servoPin);
}

void loop() {
  // Read distance from ultrasonic sensor
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  // Print distance to serial monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Example motor control logic
  if (distance < 20) {
    // Stop motors if obstacle is too close
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  } else {
    // Move forward
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  }

  // Example pump control logic
  digitalWrite(pumpPin1, HIGH);
  digitalWrite(pumpPin2, LOW);
  delay(1000);
  digitalWrite(pumpPin1, LOW);
  digitalWrite(pumpPin2, LOW);

  // Example servo control logic
  myServo.write(90); // Move servo to 90 degrees
  delay(1000);
  myServo.write(0); // Move servo to 0 degrees
  delay(1000);

  delay(100); // Delay between loop iterations
}

This code is responsible for the main control loop of the Smart Robot Car. It initializes the hardware components, reads sensor data, and controls the motors, pump, and servo based on the sensor inputs and predefined logic. The code also includes serial communication for debugging and wireless control via Bluetooth.