Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Obstacle-Avoiding Vehicle with IR Sensors and Servo Barrier Deployment

Image of Arduino-Controlled Obstacle-Avoiding Vehicle with IR Sensors and Servo Barrier Deployment

Circuit Documentation

Summary

This circuit is designed to control a DC motor and a servo using an Arduino UNO microcontroller. It includes IR sensors for input, a motor driver to control the DC motor, and a power supply provided by a 12V battery. The IR sensors are used to detect certain conditions, which then inform the Arduino UNO to execute specific actions, such as controlling the motor speed or the position of the servo.

Component List

L298N DC Motor Driver

  • Description: A motor driver module capable of driving a small DC motor.
  • 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.

IR Sensor

  • Description: An infrared sensor used for detecting proximity or measuring distance.
  • Pins: out, gnd, vcc.

Servo

  • Description: A rotary actuator or linear actuator that allows for precise control of angular or linear position.
  • Pins: GND, VCC, PWM.

12V5Ah Battery

  • Description: A 12V battery used to power the circuit.
  • Pins: 12v +, 12v -.

DC Motor

  • Description: A direct current motor that converts electrical energy into mechanical energy.
  • Pins: pin 1, pin 2.

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.

Wiring Details

L298N DC Motor Driver

  • 5V connected to Arduino UNO 5V and Servo VCC.
  • GND connected to 12V5Ah Battery 12v - and Arduino UNO GND.
  • IN1 connected to Arduino UNO D5.
  • IN2 connected to Arduino UNO D6.
  • OUT1 connected to DC Motor pin 2.
  • OUT2 connected to DC Motor pin 1.
  • 12V connected to 12V5Ah Battery 12v +.

IR Sensors

  • All VCC pins connected to Arduino UNO 5V.
  • All GND pins connected to Arduino UNO GND.
  • IR sensor out pins connected to Arduino UNO A0, A1, and A2 respectively.

Servos

  • VCC connected to Arduino UNO 5V.
  • GND connected to Arduino UNO GND.
  • PWM pins connected to Arduino UNO D7 and D8 respectively.

12V5Ah Battery

  • 12v + connected to L298N DC motor driver 12V.
  • 12v - connected to L298N DC motor driver GND.

DC Motor

  • Pin 1 connected to L298N DC motor driver OUT2.
  • Pin 2 connected to L298N DC motor driver OUT1.

Documented Code

#include <Servo.h>

const int leftcurvesensorPIN = A0;
const int rightcurvesensorPIN = A1;
const int motorpin1 = 5;
const int motorpin2 = 6;
const int servopin = 7;

const int Curvethreshold = 200;
Servo barrierservo;

void setup(){
    Serial.begin(9600);
    pinMode(leftcurvesensorPIN, INPUT);
    pinMode(rightcurvesensorPIN, INPUT);
    pinMode(motorpin1, OUTPUT);
    pinMode(motorpin2, OUTPUT);
    barrierservo.attach(servopin);
    barrierservo.write(0);
}

void loop(){
    int leftcurvevalue = analogRead(leftcurvesensorPIN);
    int rightcurvevalue = analogRead(rightcurvesensorPIN);

    if (leftcurvevalue > Curvethreshold && rightcurvevalue <= Curvethreshold){
        slowDown();
        deployBarrier("right");
    }
    else if (rightcurvevalue > Curvethreshold && leftcurvevalue <= Curvethreshold){
        retractBarrier();
    }

    if(leftcurvevalue <= Curvethreshold && rightcurvevalue <= Curvethreshold){
        driveForward();
    }
    delay(100);
}

void slowDown(){
    digitalWrite(motorpin1, LOW);
    digitalWrite(motorpin2, HIGH);
    Serial.println("Slowing down for curve");
}

void driveForward(){
    digitalWrite(motorpin1, HIGH);
    digitalWrite(motorpin2, LOW);
    Serial.println("Driving forward");
}

void deployBarrier(String direction){
    barrierservo.write(90);
    Serial.print("Barrier deployed to the ");
    Serial.println(direction);
}

void retractBarrier(){
    barrierservo.write(0);
    Serial.println("Barrier retracted");
}

Note: The code provided has some typos and inconsistencies which have been corrected in the documented code above. The setup function was misspelled as steup, and the Serial object was incorrectly written as serial. Additionally, the HIGH and LOW constants were inconsistently cased, and the String type was used instead of string for the deployBarrier function parameter.