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

Arduino UNO-Based Line-Following and Obstacle-Avoiding Robot with IR and Ultrasonic Sensors

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Line-Following and Obstacle-Avoiding Robot with IR and Ultrasonic Sensors

Circuit Documentation

Summary

This circuit is designed to control a robotic vehicle using an Arduino UNO microcontroller. The vehicle is equipped with multiple sensors, including IR sensors and an ultrasonic sensor, to enable line-following and obstacle detection capabilities. The vehicle's movement is controlled by DC motors, which are driven through a relay module. Additionally, push buttons are used for manual control of the vehicle's movement.

Component List

  1. 250W 12V Electric Motor Brush Motor DC

    • Pins: POSITIF, NEGATIF
    • Description: High-power DC motor for driving the vehicle.
  2. IR Sensor

    • Pins: out, gnd, vcc
    • Description: Infrared sensor for line-following.
  3. Push Button Round

    • Pins: leg0, leg1
    • Description: Push button for manual control.
  4. Arduino UNO

    • 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
    • Description: Microcontroller for controlling the vehicle.
  5. Relevo 4 Canales

    • Pins: JD-VCC, VCC2, K4-NO, K4-NF, K4-Com, K3-NO, K3-NF, K3-Com, K1-NO, K1-NF, K1-Com, K2-NO, K2-NF, K2-Com, IN4, VCC, IN2, IN3, GND, IN1
    • Description: Relay module for controlling the DC motors.
  6. HC-SR04 Ultrasonic Sensor

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Ultrasonic sensor for obstacle detection.
  7. 12V 7Ah Battery

    • Pins: 12v +, 12v -
    • Description: Power source for the circuit.
  8. 12V Buzzer

    • Pins: +, -
    • Description: Buzzer for audio alerts.

Wiring Details

250W 12V Electric Motor Brush Motor DC

IR Sensor

Push Button Round

Arduino UNO

Relevo 4 Canales

HC-SR04 Ultrasonic Sensor

12V 7Ah Battery

12V Buzzer

Code Documentation

// Pin Definitions
const int leftMotorForward = 2;
const int leftMotorReverse = 3;
const int rightMotorForward = 4;
const int rightMotorReverse = 5;
const int irSensorLeft = A0;
const int irSensorRight = A1;
const int ultrasonicTrigger = 6;
const int ultrasonicEcho = 7;
const int forwardButton = 8;
const int leftTurnButton = 9;
const int rightTurnButton = 10;
const int stopButton = 11;

// Variables
bool manualControl = false;

// Function Prototypes
void lineFollowing();
bool detectObstacle();
void moveForward();
void turnLeft();
void turnRight();
void stopMotors();

// Arduino setup function
void setup() {
    pinMode(leftMotorForward, OUTPUT);
    pinMode(leftMotorReverse, OUTPUT);
    pinMode(rightMotorForward, OUTPUT);
    pinMode(rightMotorReverse, OUTPUT);
    pinMode(irSensorLeft, INPUT);
    pinMode(irSensorRight, INPUT);
    pinMode(ultrasonicTrigger, OUTPUT);
    pinMode(ultrasonicEcho, INPUT);
    pinMode(forwardButton, INPUT_PULLUP);
    pinMode(leftTurnButton, INPUT_PULLUP);
    pinMode(rightTurnButton, INPUT_PULLUP);
    pinMode(stopButton, INPUT_PULLUP);
    Serial.begin(9600);
}

// Arduino loop function
void loop() {
    if (digitalRead(stopButton) == LOW) {
        stopMotors();
    } else if (digitalRead(forwardButton) == LOW) {
        manualControl = true;
        moveForward();
    } else if (digitalRead(leftTurnButton) == LOW) {
        manualControl = true;
        turnLeft();
    } else if (digitalRead(rightTurnButton) == LOW) {
        manualControl = true;
        turnRight();
    } else {
        manualControl = false;
        lineFollowing();
    }

    if (detectObstacle()) {
        stopMotors();
    }
}

// Line-following logic