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

Arduino UNO Bluetooth-Controlled Line Following Robot with Object Detection

View and Edit Project In Cirkit DesignerImage of Arduino UNO Bluetooth-Controlled Line Following Robot with Object Detection

Circuit Documentation

Summary

This circuit is designed to control a robotic vehicle with the ability to follow a line and detect objects. The vehicle is equipped with an Arduino UNO microcontroller, an L298N DC motor driver, two DC motors, a 5-channel IR array for line detection, an HC-05 Bluetooth module for wireless communication, and a 12V battery for power. The Arduino UNO is programmed to operate in both manual and automatic modes, allowing for Bluetooth control or autonomous operation.

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. 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
  3. DC Motor (Motor 1)

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  4. DC Motor (Motor 2)

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  5. 5 Channel IR Array

    • Description: Infrared sensor array for line detection.
    • Pins: A5, A4, A3, A2, A1, VCC, GND
  6. 12V Battery

    • Description: Power source for the circuit.
    • Pins: -, +
  7. HC-05 Bluetooth Module

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

    • Description: Additional power source for the Arduino UNO.
    • Pins: -, +

Wiring Details

Arduino UNO

L298N DC Motor Driver

DC Motor (Motor 1)

DC Motor (Motor 2)

5 Channel IR Array

12V Battery

HC-05 Bluetooth Module

9V Battery

Documented 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':
      stopMotors