After waiting a long time to be able to make one obstacle avoiding robot myself, with as little expenses as possible, after all to make one successful project it should be cost-effective, but again not too professional, i.e easy to develop and deploy, I finallly build this obstacle avoiding vehicle project with Arduino.
https://www.youtube.com/watch?v=e9kJUxe3Ykw
// My First Obstacle Avoiding Bot With IR Led-Photodiode Sensor
//Created somewhere around 2011
#include "LiquidCrystal.h"
//This library contains the functions for the LCD Module Interface
//Now let's define the IR based Digital Obstacle Sensors
int aFS = A0; int aLS = A1; int aRS = A2;
//Analog IR Sensor and Photodiode Modules Connection
int FSv = 0, LSv = 0, RSv = 0;
//variables to store sensor value states.
//Set, if respective sensor detects an obstacle
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
//Define the pins to which the LCD Module is connected
void setup()
{
lcd.begin(16, 2);
//Initialize the 16X2 LCD Module
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(12, OUTPUT);
}
void move_forward()
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(12, LOW);
digitalWrite(10, HIGH);
lcd.setCursor(0, 0);
lcd.print("No Obstruction ");
//Print Moving Forward in The LCD
lcd.setCursor(0, 1);
lcd.print(" Moving Forward");
}
void move_reverse()
{
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(10, LOW);
digitalWrite(12, HIGH);
lcd.setCursor(0, 0);
lcd.print("Obstacle Detected");
lcd.setCursor(0, 1);
lcd.print(" Taking Reverse ");
}
void turn_left()
{
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(12, LOW);
digitalWrite(10, HIGH);
lcd.setCursor(0, 0);
lcd.print("Avoiding Obstacle");
lcd.setCursor(0, 1);
lcd.print(" Turning Right ");
}
void turn_right()
{
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(12, LOW);
digitalWrite(10, LOW);
lcd.setCursor(0, 0);
lcd.print("Avoiding Obstacle");
lcd.setCursor(0, 1);
lcd.print(" Turning Left ");
}
void loop() {
int FS, LS, RS;
FSv = analogRead(aFS);
LSv = analogRead(aLS);
RSv = analogRead(aRS);
if (FSv < 950) //Set Condition of Front Sensor,
//i.e Front sensor is HIGH when an obstacle is detected in Front of the Bot
FS = HIGH;
else
FS = LOW;
if (LSv < 950) //Set condition for Left Sensor
LS = HIGH;
else
LS = LOW;
if (RSv < 950) // Set Condition for Right Sensor
RS = HIGH;
else
RS = LOW;
//Move the bot according to the status of the sensors (Condition Check)
if (FS == LOW)//If No obstcacles are detected in the front , move the bot forward.
{
move_forward();
}
else
{
if (RS == LOW && LS == HIGH) //If Front obstacle detected, and Right Side of the vehicle is free, i.e RS=LOW then move Right.
{
turn_right();
}
if (LS == LOW && RS == HIGH) //TURN LEFT, if left obstacle is not present and right obstacle is present
{
turn_left();
}
if (LS == LOW && RS == LOW) //TURN RHT
{
turn_right();
}
if (LS == HIGH && RS == HIGH) //move BACK a few distance and then move right
{
//Straight Back
move_reverse();
delay(2500);
//Move Right
turn_right();
delay(2500);
}
}// Close of conditional movement , if front sensor detects an obstacle
}// Cloase of Infinite Loop