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

Arduino-Controlled Line Following Robot with Dual IR Sensors

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Line Following Robot with Dual IR Sensors

Circuit Documentation

Summary

This circuit is designed to control a pair of 12V geared motors using an Arduino UNO and an L298N DC motor driver. The motors are intended to be driven based on the input from two infrared (IR) sensors. The Arduino UNO is powered by a 9V battery and also provides power to the IR sensors. The L298N motor driver interfaces with the Arduino to control the direction and speed of the motors based on the sensor inputs. The circuit is likely part of a robotic system where the IR sensors are used for navigation, such as avoiding obstacles or following a path.

Component List

Arduino UNO

9V Battery

12V Geared Motors (x2)

IR Sensors (x2)

L298N DC Motor Driver

Wiring Details

Arduino UNO

9V Battery

12V Geared Motors

IR Sensors

L298N DC Motor Driver

Documented Code

#define LS 10      // left sensor
#define RS 9       // right sensor
#define LM1 7      // motor Driver in1
#define LM2 6      // motor Driver in2
#define RM1 5      // motor Driver in3
#define RM2 4      // motor Driver in4

void setup()
{
  pinMode(LS, INPUT);  // Set left sensor as input
  pinMode(RS, INPUT);  // Set right sensor as input
  pinMode(LM1, OUTPUT); // Set motor driver inputs as outputs
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
}

void loop()
{
  // Read sensor values and control motor driver outputs accordingly
  if(!digitalRead(LS) && !digitalRead(RS))  
  {
    // Move forward
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
  
  if(digitalRead(LS) && !digitalRead(RS))     
  {
    // Turn left
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
  
  if(!digitalRead(LS) && digitalRead(RS))     
  {
    // Turn right
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }
  
  if(digitalRead(LS) && digitalRead(RS))    
  {
    // Stop
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }
}

This code is designed to read inputs from two IR sensors and control the motors through the L298N motor driver. The LS and RS constants represent the left and right sensors, respectively, while LM1, LM2, RM1, and RM2 represent the motor driver inputs. The setup function initializes the sensor pins as inputs and the motor driver pins as outputs. The loop function continuously reads the sensor inputs and controls the motor outputs to move forward, turn left, turn right, or stop based on the sensor readings.