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

Arduino UNO Line Following Robot with L298N Motor Driver and Battery Power

View and Edit Project In Cirkit DesignerImage of Arduino UNO Line Following Robot with L298N Motor Driver and Battery Power

Circuit Documentation

Summary

This document provides a detailed overview of a line-following robot circuit. The robot uses an Arduino UNO microcontroller to read values from a line sensor array and control two DC motors via an L298N motor driver. The robot is powered by a 18650 Li-Ion battery.

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. Line Sensor

    • Description: Sensor array used to detect lines on the ground.
    • Pins: 8, 7, 6, 5, 4, 3, 2, 1, +5v, GND
  3. 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
  4. DC Motor (Motor 1)

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

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  6. 18650 Li-Ion Battery

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

Wiring Details

Arduino UNO

Line Sensor

L298N DC Motor Driver

DC Motor (Motor 1)

DC Motor (Motor 2)

18650 Li-Ion Battery

Code Documentation

/*
 * Arduino-Controlled Line Following Robot with Dual DC Motors and L298N Driver
 * This code reads values from a line sensor array and controls two DC motors
 * via an L298N motor driver to follow a line.
 */

// Pin definitions
const int lineSensorPins[] = {A0, A1, A2, A3, A4, A5};
const int motorEnablePins[] = {5, 6};
const int motorControlPins[] = {8, 9, 10, 11};

void setup() {
  // Initialize line sensor pins
  for (int i = 0; i < 6; i++) {
    pinMode(lineSensorPins[i], INPUT);
  }
  // Initialize motor control pins
  for (int i = 0; i < 4; i++) {
    pinMode(motorControlPins[i], OUTPUT);
  }
  // Initialize motor enable pins
  for (int i = 0; i < 2; i++) {
    pinMode(motorEnablePins[i], OUTPUT);
  }
  // Enable motors
  digitalWrite(motorEnablePins[0], HIGH);
  digitalWrite(motorEnablePins[1], HIGH);
}

void loop() {
  int sensorValues[6];
  // Read sensor values
  for (int i = 0; i < 6; i++) {
    sensorValues[i] = analogRead(lineSensorPins[i]);
  }
  // Determine motor actions based on sensor values
  if (sensorValues[0] < 500 && sensorValues[5] < 500) {
    // Move forward
    moveForward();
  } else if (sensorValues[0] < 500) {
    // Turn left
    turnLeft();
  } else if (sensorValues[5] < 500) {
    // Turn right
    turnRight();
  } else {
    // Stop
    stopMotors();
  }
}

void moveForward() {
  digitalWrite(motorControlPins[0], HIGH);
  digitalWrite(motorControlPins[1], LOW);
  digitalWrite(motorControlPins[2], HIGH);
  digitalWrite(motorControlPins[3], LOW);
}

void turnLeft() {
  digitalWrite(motorControlPins[0], LOW);
  digitalWrite(motorControlPins[1], HIGH);
  digitalWrite(motorControlPins[2], HIGH);
  digitalWrite(motorControlPins[3], LOW);
}

void turnRight() {
  digitalWrite(motorControlPins[0], HIGH);
  digitalWrite(motorControlPins[1], LOW);
  digitalWrite(motorControlPins[2], LOW);
  digitalWrite(motorControlPins[3], HIGH);
}

void stopMotors() {
  digitalWrite(motorControlPins[0], LOW);
  digitalWrite(motorControlPins[1], LOW);
  digitalWrite(motorControlPins[2], LOW);
  digitalWrite(motorControlPins[3], LOW);
}

This code initializes the line sensor and motor control pins, reads sensor values, and controls the motors to follow a line based on the sensor readings. The robot moves forward, turns left, turns right, or stops based on the sensor values.