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

Arduino-Based 4-Wheel Autonomous and Bluetooth-Controlled Car with GPS and Ultrasonic Sensors

View and Edit Project In Cirkit DesignerImage of Arduino-Based 4-Wheel Autonomous and Bluetooth-Controlled Car with GPS and Ultrasonic Sensors

Circuit Documentation

Summary

This document provides a detailed overview of a 4-wheel car circuit controlled via Bluetooth (HC-06) or in autonomous mode. The car uses four ultrasonic sensors for obstacle detection and a NEO-6M GPS module for tracking. The circuit is powered by a 18650 Li-Ion battery and includes a solar panel for charging. The Arduino UNO microcontroller is the brain of the system, interfacing with all sensors, motors, and communication modules.

Component List

  1. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  2. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor for obstacle detection.
    • Pins: VCC, TRIG, ECHO, GND
  3. Neo 6M GPS Module

    • Description: GPS module for tracking.
    • Pins: GND, TX, RX, VCC
  4. DC Motor

    • Description: Standard DC motor for driving wheels.
    • Pins: pin 1, pin 2
  5. 18650 Li-Ion Battery

    • Description: Rechargeable lithium-ion battery.
    • Pins: Positive, Negative
  6. Buck Converter

    • Description: Voltage regulator to step down voltage.
    • Pins: IN+, IN-, OUT+, OUT-
  7. Bluetooth HC-06

    • Description: Bluetooth module for wireless communication.
    • Pins: VCC, GND, TXD, RXD
  8. Arduino UNO

    • Description: Microcontroller board for controlling the circuit.
    • 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
  9. Solar Panel

    • Description: Solar panel for charging the battery.
    • Pins: +, -
  10. TP4056

    • Description: Lithium battery charger module.
    • Pins: OUT-, B-, B+, OUT+, IN-, IN+

Wiring Details

L298N DC Motor Driver

HC-SR04 Ultrasonic Sensor (Front)

HC-SR04 Ultrasonic Sensor (Left)

HC-SR04 Ultrasonic Sensor (Right)

HC-SR04 Ultrasonic Sensor (Back)

Neo 6M GPS Module

DC Motor (Front Left and Front Right)

DC Motor (Back Left and Back Right)

18650 Li-Ion Battery

Buck Converter

Bluetooth HC-06

Solar Panel

TP4056

Code Documentation

/*
 * Arduino 4-Wheel Car
 * Controlled via Bluetooth (HC-06) or Autonomous Mode
 * Uses 4 Ultrasonic Sensors for Obstacle Detection
 * GPS Tracking via NEO-6M Module
 */

#include <SoftwareSerial.h>

// Pin Definitions
#define TRIG_FRONT 6
#define ECHO_FRONT 7
#define TRIG_LEFT 8
#define ECHO_LEFT 11
#define TRIG_RIGHT A0
#define ECHO_RIGHT A1
#define TRIG_BACK 12
#define ECHO_BACK 13
#define ENA 9
#define ENB 10
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 5

// Bluetooth and GPS
SoftwareSerial BTSerial(0, 1); // RX, TX
SoftwareSerial GPSSerial(0, 1); // RX, TX

void setup() {
  // Initialize Serial Communication
  Serial.begin(9600);
  BTSerial.begin(9600);
  GPSSerial.begin(9600);

  // Initialize Motor Control Pins
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // Initialize Ultrasonic Sensor Pins
  pinMode(TRIG_FRONT, OUTPUT);
  pinMode(ECHO_FRONT, INPUT);
  pinMode(TRIG_LEFT, OUTPUT);
  pinMode(ECHO_LEFT, INPUT);
  pinMode(TRIG_RIGHT, OUTPUT);
  pinMode(ECHO_RIGHT, INPUT);
  pinMode(TRIG_BACK, OUTPUT);
  pinMode(ECHO_BACK, INPUT);
}

void loop() {
  // Autonomous Mode or Bluetooth Control
  if (BTSerial.available()) {
    char command = BTSerial.read();
    executeCommand(command);
  } else {
    autonomousMode();
  }
}

void executeCommand(char command) {
  switch (command) {
    case 'F': moveForward(); break;
    case 'B': moveBackward(); break;
    case 'L': turnLeft(); break;
    case 'R': turnRight(); break;
    case 'S': stopCar(); break;
  }
}

void autonomousMode() {
  // Implement obstacle detection and avoidance
  if (detectObstacle(TRIG_FRONT, ECHO_FRONT)) {
    stopCar();
    if (detectObstacle(TRIG_LEFT, ECHO_LEFT)) {
      turnRight();
    } else {
      turnLeft();
    }
  } else {
    moveForward();
  }
}

bool detectObstacle(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  long duration = pulseIn(echoPin, HIGH);
  long distance = duration * 0.034 / 2;
  return distance < 20; // Obstacle within 20 cm