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

Arduino Nano Line Follower Robot with Obstacle Avoidance and PID Control

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

Circuit Documentation

Summary

This document provides a detailed overview of a line follower robot with obstacle avoidance capabilities. The robot uses an 8-array IR sensor to follow a line and an ultrasonic sensor to detect and avoid obstacles. The system is controlled by an Arduino Nano microcontroller, which interfaces with various components including motors, sensors, LEDs, and buttons.

Component List

  1. Arduino Nano

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. Ponte H

    • Description: H-bridge motor driver.
    • Pins: OUT4-Motor2, OUT3-Motor2, OUT2-Motor1, OUT1-Motor1, 5V, GND, 12V, IN3, IN1, IN2, IN4
  3. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  4. DC Mini Metal Gear Motor

    • Description: Small DC motor with metal gears.
    • Pins: IN1, IN2
  5. 8 Array IR Sensor

    • Description: Infrared sensor array for line following.
    • Pins: GND, IR, D1, D2, D3, D4, D5, D6, D7, D8, VCC
  6. Pushbutton

    • Description: Simple pushbutton switch.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  7. Battery 12V

    • Description: 12V battery for power supply.
    • Pins: +, -
  8. Rocker Switch

    • Description: On/Off switch.
    • Pins: 1, 2
  9. Alligator Clip Cable (Red)

    • Description: Alligator clip cable for temporary connections.
    • Pins: Pin, Alligator
  10. LED: Two Pin (Blue)

    • Description: Blue LED.
    • Pins: cathode, anode
  11. LED: Two Pin (Orange)

    • Description: Orange LED.
    • Pins: cathode, anode

Wiring Details

Arduino Nano

Ponte H

HC-SR04 Ultrasonic Sensor

DC Mini Metal Gear Motor

8 Array IR Sensor

Pushbutton

Battery 12V

Rocker Switch

Alligator Clip Cable (Red)

LED: Two Pin (Blue)

LED: Two Pin (Orange)

Code Documentation

/*
 * Line Follower Robot with Obstacle Avoidance
 * This Arduino sketch uses a PID algorithm to follow a line using an 8-array IR sensor.
 * It also uses an ultrasonic sensor to detect and avoid obstacles.
 * Two buttons are used: one for calibration and one to start the robot.
 * During calibration, a blue LED is lit.
 */

#include <PID_v1.h>

// Pin definitions
#define IR_PIN A0
#define TRIG_PIN A7
#define ECHO_PIN A6
#define LED_PIN 4
#define CALIBRATE_BUTTON_PIN 2
#define RUN_BUTTON_PIN A3
#define MOTOR1_IN1 9
#define MOTOR1_IN2 6
#define MOTOR2_IN3 5
#define MOTOR2_IN4 3

// PID parameters
double setpoint = 0, input = 0, output = 0;
PID myPID(&input, &output, &setpoint, 2, 5, 1, DIRECT);

// Function prototypes
void calibrateSensors();
void follow