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

Arduino UNO GPS Navigation Robot with Bluetooth and Obstacle Avoidance

View and Edit Project In Cirkit DesignerImage of Arduino UNO GPS Navigation Robot with Bluetooth and Obstacle Avoidance

Circuit Documentation

Summary

This document provides a detailed overview of a GPS navigation robot circuit. The circuit includes various components such as DC gear motors, an L298N motor driver, a 12V battery, IR sensors, a siren, and an Arduino UNO microcontroller. The robot is designed to navigate to a target location using GPS coordinates and can be controlled via Bluetooth. It also includes obstacle detection using ultrasonic sensors.

Component List

Gearmotor DC Wheels Right

Gearmotor DC Wheels Left

L298N DC Motor Driver

12V 7Ah Battery

IR Sensor

Siren

Arduino UNO

Wiring Details

Gearmotor DC Wheels Right

Gearmotor DC Wheels Left

L298N DC Motor Driver

12V 7Ah Battery

IR Sensor

Siren

Arduino UNO

Documented Code

#include <SoftwareSerial.h>
#include <TinyGPS++.h>

// Pin Definitions for Motors and Sensors
#define motorA1 8
#define motorA2 9
#define motorB1 10
#define motorB2 11
#define trigPin 6
#define echoPin 7

TinyGPSPlus gps;
SoftwareSerial gpsSerial(0, 1); // RX, TX for GPS
SoftwareSerial bluetooth(3, 4); // RX, TX for Bluetooth

// Target coordinates (latitude and longitude)
double targetLatitude = 37.7749;
double targetLongitude = -122.4194;

void setup() {
  // Motor pins setup
  pinMode(motorA1, OUTPUT);
  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT);
  
  // Ultrasonic Sensor setup
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  // Serial communication setup
  Serial.begin(9600);
  gpsSerial.begin(9600);    // GPS module
  bluetooth.begin(9600);    // Bluetooth module
  
  Serial.println("GPS Navigation Robot with Bluetooth Starting...");
}

void loop() {
  // Reading GPS data
  while (gpsSerial.available() > 0) {
    if (gps.encode(gpsSerial.read())) {
      double distanceToTarget = calculateDistance(gps.location.lat(), gps.location.lng(), targetLatitude, targetLongitude);
      Serial.print("Distance to Target: ");
      Serial.println(distanceToTarget);
      
      if (distanceToTarget > 5) {
        moveForward();
      } else {
        stopRobot();
        Serial.println("Arrived at destination!");
      }
    }
  }

  // Ultrasonic obstacle detection
  long duration = getDistance();
  if (duration < 20) { // If obstacle detected
    avoidObstacle();
  }
  
  // Bluetooth control
  if (bluetooth.available()) {
    char command = bluetooth.read();
    controlRobot(command);
  }
}

// Function to calculate distance to target (Haversine formula)
double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
  const double R = 6371e3; // Earth radius in meters
  double phi1 = radians(lat1);
  double phi2 = radians(lat2);
  double deltaPhi = radians(lat2 - lat1);
  double deltaLambda = radians(lon2 - lon1);
  
  double a = sin(deltaPhi/2) * sin(deltaPhi/2) +
             cos(phi1) * cos(phi2) * sin(deltaLambda/2) * sin(deltaLambda/2);
  double c = 2 * atan2(sqrt(a), sqrt(1-a));
  
  return R * c; // Distance in meters
}

// Function to move the robot forward
void moveForward() {
  digitalWrite(motorA1, HIGH);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}

// Function to stop the robot
void stopRobot() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, LOW);
}

// Function to get ultrasonic distance
long getDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  long duration = pulseIn(echoPin, HIGH);
  long distance = (duration * 0.034) / 2; // Distance in cm
  return distance;
}

// Function to avoid obstacles
void avoidObstacle() {
  stopRobot();
  delay(1000); // Stop for 1 second
  // Implement additional logic to avoid obstacle
}

// Function to control robot via Bluetooth
void controlRobot(char command) {
  switch (command) {
    case 'F': // Move Forward
      moveForward();
      break;
    case 'B': // Move Backward
      moveBackward();
      break;
    case 'L': // Turn Left
      turnLeft();
      break;
    case 'R': // Turn Right
      turnRight();
      break;
    case 'S': // Stop
      stopRobot();
      break;
  }
}

// Function to move the robot backward
void moveBackward() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digital