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

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

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

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a robot using an Arduino UNO. The circuit includes various sensors and actuators, such as an ultrasonic sensor, IR sensors, and DC motors, all interfaced through an L298N motor driver. The robot is powered by a 4 x AAA battery mount and includes a rocker switch for power control.

Component List

4 x AAA Battery Mount

HC-SR04 Ultrasonic Sensor

L298N DC Motor Driver

Rocker Switch

Hobby Gearmotor with 48:1 Gearbox

Arduino UNO

5 Channel IR Sensor

Wiring Details

4 x AAA Battery Mount

HC-SR04 Ultrasonic Sensor

L298N DC Motor Driver

Rocker Switch

Hobby Gearmotor with 48:1 Gearbox

Arduino UNO

5 Channel IR Sensor

Documented Code

// Definición pines EnA y EnB para el control de la velocidad
int VelocidadMotor1 = 6; 
int VelocidadMotor2 = 5;

// Definición de los pines de control de giro de los motores In1, In2, In3 e In4
int Motor1A = 13; 
int Motor1B = 12;  
int Motor2C = 11; 
int Motor2D = 10; 

// Sensores infrarrojo - izquierdo y derecho
int infraPin  = 2;    
int infraPin1 = 4;

// Variables para la captura de los valores: 0 - fondo claro y 1 - línea negra
int valorInfra = 0;  
int valorInfra1 = 0;  

// Ultrasonicos
#define PIN_TRIG 9
#define PIN_ECHO 8
 
long duration, distancia;
// Configuración inicial
void setup() {
  Serial.begin(9600);
  
  delay(1000);
  //configuración del ultrasonico
  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);
  // Establecemos modo de los pines de los sensores infrarrojo
  pinMode(infraPin, INPUT);    
  pinMode(infraPin1, INPUT);

  // Establecemos modo de los pines del control de motores
  pinMode(Motor1A,OUTPUT);
  pinMode(Motor1B,OUTPUT);
  pinMode(Motor2C,OUTPUT);
  pinMode(Motor2D,OUTPUT);
  pinMode(VelocidadMotor1, OUTPUT);
  pinMode(VelocidadMotor2, OUTPUT);

  // Configuramos los