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

Arduino UNO Line-Following Robot with IR Sensors and Motor Control

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

Circuit Documentation

Summary

This circuit is designed to control a robot using an Arduino UNO microcontroller. The robot is equipped with IR sensors for line following, motors for movement, LEDs for signaling, and a photocell for detecting ambient light levels. The circuit also includes a motor driver to control the motors and a battery mount for power supply.

Component List

  1. Arduino UNO

    • Description: 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: Hobby motor with gearbox.
    • Pins: vcc, GND
  3. L298N DC motor driver

    • Description: 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
  4. 4 x AAA Battery Mount

    • Description: Battery holder for 4 AAA batteries.
    • Pins: -, +
  5. IR Sensor

    • Description: Infrared sensor for line detection.
    • Pins: out, gnd, vcc
  6. LED: Two Pin (red)

    • Description: Red LED.
    • Pins: cathode, anode
  7. LED: Two Pin (yellow)

    • Description: Yellow LED.
    • Pins: cathode, anode
  8. Toggle Switch

    • Description: Toggle switch for user input.
    • Pins: L1, COM, L2
  9. Resistor

    • Description: Resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  10. Photocell (LDR)

    • Description: Light-dependent resistor.
    • Pins: pin 0, pin 1

Wiring Details

Arduino UNO

Motor amarillo motorreductor hobby

L298N DC motor driver

4 x AAA Battery Mount

IR Sensor

LED: Two Pin (red)

LED: Two Pin (yellow)

Toggle Switch

Resistor

Photocell (LDR)

Documented Code

Arduino UNO Code

#include <LiquidCrystal_I2C.h>  // liquid crystal library

LiquidCrystal_I2C lcd(0x27, 16, 2);  // specifices how to refrence the LCD and it's characteristics

/* 
 Tested Oct. 14
*/

// define variables

char array1[] = "Robot State:    ";
char array2[] = "STOPPED         ";
char array3[] = "FORWARD        ";
char array4[] = "BACKWARDS         ";
char array5[] = "RIGHT TURN    ";
char array6[] = "LEFT TURN    ";

#define leftIR 6
#define rightIR 7

#define LM1 2 // left motor 1
#define LM2 3 // left motor 2
#define RM1 4 // right motor 1
#define RM2 5 // right motor 2

#define FLturn 4 // Front Left Turn Signal
#define BLturn 4 // Back Left Turn Signal
#define FRturn 3 // Front Right Turn Signal
#define BRturn 3 // Back Right Turn Signal

#define Lbright 2 // Left brights 
#define Rbright 1 // Right brights

#define photocellPin 13 // photocell resistor

#define ledpin 12;  //specify the LED pin to pin 12

int LCDprev = 99;   // helps to update the LCD state tracks previous
int LCDcurr = 100;  // helps to update the LCD state tracks current

int leftFlag; // used for debugging
int rightFlag; // used for debugging

// all necessary functions
void forward();
void leftTurn();
void rightTurn();
void reverse();
void stop();
void setup()
{
  lcd.init();       // initializes LCD
  lcd.backlight();  // turn on backlight

  pinMode(LM1, OUTPUT); // output pins for L298N for PWM funcionality
  pinMode(LM2, OUTPUT); // output pins for L298N for PWM funcionality 
  pinMode(RM1, OUTPUT); // output pins for L298N for PWM funcionality
  pinMode(RM2, OUTPUT); // output pins for L298N for PWM funcionality

  pinMode(leftIR, INPUT); // Left IR sensor as an INPUT
  pinMode(rightIR, INPUT); // Right IR sensor as an INPUT
  digitalWrite(leftIR, HIGH); // output pins declared