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

Arduino UNO Line Following Robot with Dual Motor Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO Line Following Robot with Dual Motor Control

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a robot using an Arduino UNO microcontroller. The circuit includes various components such as motors, a motor driver, a line tracking sensor, a rocker switch, and batteries. The Arduino UNO is programmed to read sensor inputs and control the motors accordingly.

Component List

  1. Arduino UNO

    • Description: A 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. Motor amarillo motorreductor hobby

    • Description: A small DC motor with a gearbox.
    • Pins: vcc, GND
  3. 3 channel line tracking

    • Description: A sensor module used for line tracking.
    • Pins: GND, +VCC, S1, S2, S3
  4. Rocker switch

    • Description: A switch used to control the power supply.
    • Pins: output, input
  5. 9V Battery

    • Description: A 9V battery used as a power source.
    • Pins: -, +
  6. L298N DC motor driver

    • Description: A dual H-Bridge motor driver.
    • 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
  7. 3.7v Battery

    • Description: A 3.7V battery used as an additional power source.
    • Pins: +, -

Wiring Details

Arduino UNO

Motor amarillo motorreductor hobby

3 channel line tracking

Rocker switch

9V Battery

L298N DC motor driver

3.7v Battery

Code Documentation

// กำหนด pin
const int Sensor1 = 2;
const int Sensor2 = 3;
const int Sensor3 = 4;

const int EnB_PWM = 6;
const int(IN1) = 7;
const int IN2 = 8;
const int IN3 = 9;
const int IN4 = 10;
const int EnA_PWM = 11;

void setup() {
  // กำหนดเซ็นเซอร์ 3 ตัว
  pinMode(Sensor1, INPUT);
  pinMode(Sensor2, INPUT);
  pinMode(Sensor3, INPUT);
  
  // กำหนดมอเตอร์ 4 ตัว
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  // ควบคุมความเร็วมอเตอร์
  pinMode(EnA_PWM, OUTPUT);
  pinMode(EnB_PWM, OUTPUT);
  
  stopMotors();
}

void loop() {
  
  int sensor1 = digitalRead(Sensor1);
  int sensor2 = digitalRead(Sensor2);
  int sensor3 = digitalRead(Sensor3);
  
  if (sensor2 == LOW && sensor3 == LOW) {
    // Move forward
    moveForward();
  } else if (sensor1 == HIGH) {
    // Turn right
    turnRight();
  } else if (sensor4 == HIGH) {
    // Turn left
    turnLeft();
  } else {
    // Stop if no clear path
    stopMotors();
  }
}

void moveForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(EnA_PWM, 255);
  analogWrite(EnB_PWM, 255);
}

void turnRight() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  analogWrite(EnA_PWM, 255);
  analogWrite(EnB_PWM, 255);
}

void turnLeft() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(EnA_PWM, 255);
  analogWrite(EnB_PWM, 255);
}

void stopMotors() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  analogWrite(EnA_PWM, 0);
  analogWrite(EnB_PWM, 0);
}

This code is written for the Arduino UNO microcontroller. It initializes the pins for the sensors and motors, reads the sensor inputs, and controls the motors to move the robot forward, turn left, or turn right based on the sensor readings. The stopMotors function is used to stop the motors when no clear path is detected.