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

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

View and Edit Project In Cirkit DesignerImage 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

IR Sensor

Servo

12V5Ah Battery

DC Motor

Arduino UNO

Wiring Details

L298N DC Motor Driver

IR Sensors

Servos

12V5Ah Battery

DC Motor

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.