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

Arduino Nano Line Follower Robot with PID Control and Sensor Array

View and Edit Project In Cirkit DesignerImage of Arduino Nano Line Follower Robot with PID Control and Sensor Array

Circuit Documentation

Summary

This document provides a detailed overview of a line follower robot circuit. The circuit includes an Arduino Nano microcontroller, motor driver, DC motors, pushbuttons, a toggle switch, resistors, capacitors, a sensor array, and a battery pack. The robot uses PID control logic to follow a black line on a white surface, with calibration and start functionalities controlled by pushbuttons.

Component List

Arduino Nano

Toggle Switch

Pushbutton

Resistor

Electrolytic Capacitor

DC Mini Metal Gear Motor

Drv8833

18650 Li-ion Battery x 2

Smartelex Sensor Array

Wiring Details

Arduino Nano

Toggle Switch

Pushbutton 1

Pushbutton 2

Resistor 1

Resistor 2

Electrolytic Capacitor 1

Electrolytic Capacitor 2

DC Mini Metal Gear Motor 1

DC Mini Metal Gear Motor 2

Drv8833

18650 Li-ion Battery x 2

Smartelex Sensor Array

Code Documentation

Arduino Nano Code

/*
 * Line Follower Bot with PID Control
 * This code controls a line follower bot using PID logic for stability.
 * The bot starts when the toggle switch is on. The first button calibrates
 * the wheels, and the second button starts the line-following behavior.
 * The bot accurately follows a black line on a white surface, taking
 * precise turns at curves or edges.
 */

// Pin definitions
const int toggleSwitchPin = 2;
const int button1Pin = 3;
const int button2Pin = 4;
const int motor1Pin1 = 5;
const int motor1Pin2 = 6;
const int motor2Pin1 = 9;
const int motor2Pin2 = 10;
const int sensorPins[] = {A0, A1, A2, A3, A4, A5, A6, A7};

// PID constants
float Kp = 1.0;
float Ki = 0.0;
float Kd = 0.0;

// Variables for PID
float error = 0;
float previousError = 0;
float integral = 0;
float derivative = 0;

void setup() {
  // Initialize pins
  pinMode(toggleSwitchPin, INPUT);
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  for (int i = 0; i < 8; i++) {
    pinMode(sensorPins[i], INPUT);
  }
}

void loop() {
  // Check if toggle switch is on
  if (digitalRead(toggleSwitchPin) ==