Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Bluetooth-Controlled Robotic Car with Ultrasonic Distance Sensing

Image of Arduino UNO Bluetooth-Controlled Robotic Car with Ultrasonic Distance Sensing

Circuit Documentation

Summary

This circuit is designed to control a set of DC motors using an Arduino UNO and an L293D motor driver shield. The circuit also includes an HC-SR04 ultrasonic distance sensor, a sound sensor, and an HC-05 Bluetooth module for remote control. The power is supplied by a 18650 Li-Ion battery.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. L293D Driver Shield

    • Description: A motor driver shield capable of driving four DC motors.
    • Pins: 5v, GND, A0, A1, A2, A3, A4, A5, M+, M2, M2, M1, M3, M4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, gnd, Aref, ser1, Servo2, +, -, 9v
  3. 18650 Li-Ion Battery

    • Description: A rechargeable lithium-ion battery.
    • Pins: Positive, Negative
  4. DC Motor (4 units)

    • Description: A simple DC motor.
    • Pins: pin 1, pin 2
  5. HC-SR04 Ultrasonic Distance Sensor

    • Description: A sensor used to measure distance using ultrasonic waves.
    • Pins: VCC, TRIG, ECHO, GND
  6. Sound Sensor

    • Description: A sensor used to detect sound levels.
    • Pins: VCC, GND, DO, AO
  7. HC-05 Bluetooth Module

    • Description: A Bluetooth module used for wireless communication.
    • Pins: Key, VCC, GND, TXD, RXD, State

Wiring Details

Arduino UNO

  • AREF connected to Aref of L293D Driver Shield
  • GND connected to gnd of L293D Driver Shield
  • D13 connected to 12 of L293D Driver Shield
  • D12 connected to 12 of L293D Driver Shield
  • D11 connected to 11 of L293D Driver Shield
  • D10 connected to 10 of L293D Driver Shield
  • D9 connected to 9 of L293D Driver Shield
  • D8 connected to 8 of L293D Driver Shield
  • D7 connected to 7 of L293D Driver Shield
  • D6 connected to 6 of L293D Driver Shield
  • D5 connected to 5 of L293D Driver Shield
  • D4 connected to 4 of L293D Driver Shield
  • D3 connected to 3 of L293D Driver Shield
  • D2 connected to 2 of L293D Driver Shield
  • D1 connected to 1 of L293D Driver Shield
  • D0 connected to 0 of L293D Driver Shield

L293D Driver Shield

  • 5v connected to 5v of HC-SR04 Ultrasonic Distance Sensor
  • GND connected to GND of HC-SR04 Ultrasonic Distance Sensor
  • A0 connected to TRIG of HC-SR04 Ultrasonic Distance Sensor
  • A1 connected to ECHO of HC-SR04 Ultrasonic Distance Sensor
  • M+ connected to Positive of 18650 Li-Ion Battery
  • GND connected to Negative of 18650 Li-Ion Battery
  • M2 connected to pin 1 of DC Motor
  • M2 connected to pin 2 of DC Motor
  • M1 connected to pin 1 of DC Motor
  • M1 connected to pin 2 of DC Motor
  • M3 connected to pin 1 of DC Motor
  • M3 connected to pin 2 of DC Motor
  • M4 connected to pin 1 of DC Motor
  • M4 connected to pin 2 of DC Motor
  • ser1 connected to RXD of HC-05 Bluetooth Module
  • Servo2 connected to TXD of HC-05 Bluetooth Module
  • + connected to VCC of HC-05 Bluetooth Module
  • - connected to GND of HC-05 Bluetooth Module

HC-SR04 Ultrasonic Distance Sensor

  • VCC connected to 5v of L293D Driver Shield
  • GND connected to GND of L293D Driver Shield
  • TRIG connected to A0 of L293D Driver Shield
  • ECHO connected to A1 of L293D Driver Shield

18650 Li-Ion Battery

  • Positive connected to M+ of L293D Driver Shield
  • Negative connected to GND of L293D Driver Shield

DC Motor (4 units)

  • pin 1 connected to M2 of L293D Driver Shield
  • pin 2 connected to M2 of L293D Driver Shield
  • pin 1 connected to M1 of L293D Driver Shield
  • pin 2 connected to M1 of L293D Driver Shield
  • pin 1 connected to M3 of L293D Driver Shield
  • pin 2 connected to M3 of L293D Driver Shield
  • pin 1 connected to M4 of L293D Driver Shield
  • pin 2 connected to M4 of L293D Driver Shield

HC-05 Bluetooth Module

  • RXD connected to ser1 of L293D Driver Shield
  • TXD connected to Servo2 of L293D Driver Shield
  • VCC connected to + of L293D Driver Shield
  • GND connected to - of L293D Driver Shield

Documented Code

#include <AFMotor.h>
#include <SoftwareSerial.h>

SoftwareSerial bluetoothSerial(9, 10); // RX, TX

//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command;

void setup()
{
  bluetoothSerial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

void loop() {
  if (bluetoothSerial.available() > 0) {
    command = bluetoothSerial.read();

    Stop(); //initialize with motors stoped
    
    switch (command) {
      case 'F':
        forward();
        break;
      case 'B':
        back();
        break;
      case 'L':
        left();
        break;
      case 'R':
        right();
        break;
    }
  }
}

void forward()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD);  //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD);  //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void back()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void left()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run