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

Arduino-Controlled Line Following Trolley with Ultrasonic Obstacle Detection and Bluetooth Connectivity

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Line Following Trolley with Ultrasonic Obstacle Detection and Bluetooth Connectivity

Circuit Documentation

Summary

This circuit is designed to control a line-following trolley using an array of sensors and modules. The core of the system is an Arduino UNO microcontroller, which interfaces with an HC-SR04 Ultrasonic Sensor for obstacle detection, an HC-05 Bluetooth Module for wireless communication, a TCRT 5000 IR Sensor for line tracking, and an L298N Motor Driver to control two DC motors. The circuit is powered by a 9V battery, and it includes logic for line following and obstacle avoidance.

Component List

HC-SR04 Ultrasonic Sensor

HC-05 Bluetooth Module

DC Motor

9V Battery

Arduino UNO

L298N DC Motor Driver

TCRT 5000 IR SENSOR

Wiring Details

HC-SR04 Ultrasonic Sensor

HC-05 Bluetooth Module

DC Motors

9V Battery

L298N DC Motor Driver

TCRT 5000 IR SENSOR

Documented Code

/*
 * Arduino Sketch for a Line Following Trolley
 *
 * This code interfaces with various sensors and modules to control a trolley
 * that follows a line. The components include an HC-SR04 Ultrasonic Sensor,
 * HC-05 Bluetooth Module, TCRT 5000 IR Sensor, and L298N Motor Driver.
 * The Arduino UNO is the main microcontroller.
 */

// Pin definitions
const int trigPin = 9;
const int echoPin = 8;
const int irPin = A0;
const int irDigitalPin = 7;
const int motorIn1 = 5;
const int motorIn2 = 4;
const int motorIn3 = 3;
const int motorIn4 = 2;
const int motorEnA = 10;
const int motorEnB = 11;

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

  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(irPin, INPUT);
  pinMode(irDigitalPin, INPUT);
  pinMode(motorIn1, OUTPUT);
  pinMode(motorIn2, OUTPUT);
  pinMode(motorIn3, OUTPUT);
  pinMode(motorIn4, OUTPUT);
  pinMode(motorEnA, OUTPUT);
  pinMode(motorEnB, OUTPUT);
}

void loop() {
  // Read IR sensor
  int irValue = analogRead(irPin);
  int irDigitalValue = digitalRead(irDigitalPin);

  // Line following logic
  if (irDigitalValue == HIGH) {
    // Move forward
    digitalWrite(motorIn1, HIGH);
    digitalWrite(motorIn2, LOW);
    digitalWrite(motorIn3, HIGH);
    digitalWrite(motorIn4, LOW);
    analogWrite(motorEnA, 255);
    analogWrite(motorEnB, 255);
  } else {
    // Stop
    digitalWrite(motorIn1, LOW);
    digitalWrite(motorIn2, LOW);
    digitalWrite(motorIn3, LOW);
    digitalWrite(motorIn4, LOW);
    analogWrite(motorEnA, 0);
    analogWrite(motorEnB, 0);
  }

  // Ultrasonic sensor logic
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  // If an obstacle is detected within 10 cm, stop the motors
  if (distance < 10) {
    digitalWrite(motorIn1, LOW);
    digitalWrite(motorIn2, LOW);
    digitalWrite(motorIn3, LOW);
    digitalWrite(motorIn4, LOW);
    analogWrite(motorEnA, 0);
    analogWrite(motorEnB, 0);
  }

  delay(100);
}

This code is responsible for the operation of the line-following trolley. It initializes the sensor and motor driver pins, reads the IR sensor for line tracking, and uses the ultrasonic sensor to detect obstacles. The motors are controlled based on the sensor inputs to follow a line and avoid collisions.