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

Arduino UNO-Based Line Following and Object Detecting Robot with Bluetooth Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Line Following and Object Detecting Robot with Bluetooth Control

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a robotic vehicle with object detection and line-following capabilities. The circuit includes an Arduino UNO microcontroller, various sensors, a motor driver, and other components to achieve the desired functionality. The vehicle can operate in both manual and automatic modes, with manual control via Bluetooth and automatic control using IR sensors and an ultrasonic sensor.

Component List

  1. Arduino UNO

    • Description: 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. HC-06

    • Description: Bluetooth module for wireless communication.
    • Pins: RXD, TXD, GND, VCC
  3. 9V Battery

    • Description: Power source for the circuit.
    • Pins: -, +
  4. Servo

    • Description: Servo motor for object grabbing.
    • Pins: GND, VCC, PWM
  5. 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
  6. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic sensor for distance measurement.
    • Pins: VCC, TRIG, ECHO, GND
  7. DC Motor

    • Description: DC motor for vehicle movement.
    • Pins: pin 1, pin 2
  8. Rocker Switch

    • Description: Switch for controlling power.
    • Pins: 1, 2
  9. IR Sensor

    • Description: Infrared sensor for line following.
    • Pins: out, gnd, vcc

Wiring Details

Arduino UNO

HC-06

9V Battery

Servo

L298N DC Motor Driver

HC-SR04 Ultrasonic Sensor

DC Motor

Rocker Switch

IR Sensor

IR Sensor

Documented Code

Arduino UNO Code

#include <Servo.h>

// Pin definitions
const int irSensor1Pin = A0;
const int irSensor2Pin = A1;
const int trigPin = 2;
const int echoPin = 3;
const int servoPin = 4;
const int motorENAPin = 10;
const int motorIN1Pin = 9;
const int motorIN2Pin = 8;
const int motorIN3Pin = 7;
const int motorIN4Pin = 6;
const int motorENBPin = 5;
const int btRxPin = 0;
const int btTxPin = 1;

// Servo object
Servo grabberServo;

// Variables
bool manualMode = false;
bool objectDetected = false;
long duration;
int distance;

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

  // Initialize pins
  pinMode(irSensor1Pin, INPUT);
  pinMode(irSensor2Pin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorENAPin, OUTPUT);
  pinMode(motorIN1Pin, OUTPUT);
  pinMode(motorIN2Pin, OUTPUT);
  pinMode(motorIN3Pin, OUTPUT);
  pinMode(motorIN4Pin, OUTPUT);
  pinMode(motorENBPin, OUTPUT);

  // Attach servo
  grabberServo.attach(servoPin);

  // Set initial servo position
  grabberServo.write(0);
}

void loop() {
  if (manualMode) {
    // Manual mode: control via Bluetooth
    if (Serial.available() > 0) {
      char command = Serial.read();
      handleBluetoothCommand(command);
    }
  } else {
    // Automatic mode: follow line and detect object
    int irSensor1Value = digitalRead(irSensor1Pin);
    int irSensor2Value = digitalRead(irSensor2Pin);

    if (irSensor1Value == HIGH && irSensor2Value == HIGH) {
      // Move forward
      moveForward();
    } else if (irSensor1Value == LOW && irSensor2Value == HIGH) {
      // Turn left
      turnLeft();
    } else if (irSensor1Value == HIGH && irSensor2Value == LOW) {
      // Turn right
      turnRight();
    } else {
      // Stop
      stopMotors();
    }

    // Check for object detection
    distance = getUltrasonicDistance();
    if (distance < 10) {
      objectDetected = true;
      grabObject();
    }
  }
}

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