Skip to main content

Arduino Object Following Robot

Object Following Robot


    Watch the entire DIY Video of making (J.A.O.F) Arduino Object Following Robot...



Required Parts :

Circuit Diagram :

Arduino Code :

//1 OCT 2020
//Just An Object Follower -> J.A.O.F
//      < M.P.R >
//For THE FAUCETER Subscribers 


#include <Servo.h>
#include <AFMotor.h>

#define echo A0
#define trig A1
#define left A2
#define right A3

Servo servo;
int i;
long duration ;
int distance ;

AF_DCMotor motor3(3,MOTOR34_1KHZ);  //L
AF_DCMotor motor4(4,MOTOR34_1KHZ);  //R

void setup()  {
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  pinMode(left,INPUT);
  pinMode(right,INPUT);
  Serial.begin(9600);
  servo.attach(10);
}

void loop() {
  
  distance = calculateDistance();
  servo.write(0);
  servo.write(180);
    
  Serial.println(distance);
  
  if(distance<=15 && distance>0) {
    servo.write(90);
    motor3.run(FORWARD);
    motor3.setSpeed(180);
    motor4.run(FORWARD);
    motor4.setSpeed(180);
  }

  else if(digitalRead(left)==0 && !analogRead(right)==0) {//L
    servo.write(0);
    motor3.run(FORWARD);
    motor3.setSpeed(150);
    motor4.run(BACKWARD);
    motor4.setSpeed(10);
    
    delay(150);
  }

  else if(!digitalRead(left)==0 && digitalRead(right)==0) {//R
    servo.write(180);
    motor3.run(BACKWARD);
    motor3.setSpeed(10);
    motor4.run(FORWARD);
    motor4.setSpeed(150);
   
    delay(150);
  }

  else {
    servo.write(90);
    motor3.run(RELEASE);
    motor3.setSpeed(0);
    motor4.run(RELEASE);
    motor4.setSpeed(0);
    delay(500);   
  }
}

int calculateDistance() {
    digitalWrite(trig,HIGH);
    delayMicroseconds(1);
    digitalWrite(trig,LOW);

    duration = pulseIn(echo,HIGH);
    distance = duration*0.034/2;
    return distance;
  }


  

Click Here to Download



Comments

Popular posts from this blog

Arduino Line Following Car

Line Follower      In this Arduino Tutorial I will Show you How to Make a Line Following Car Using Arduino Uno Board and Some Electronic Components . You can Watch this Video or Read the following blog for more details.. Working Principle :          Line Follower has a basic and necessary Component   IR Sensor which act as Vision. It works on the principle of Black Surface Absorbs all  Wavelengths of Light Rays. Then the IR Sensors mounted infront of the car detects black line and makes a movement based on your code.

Arduino Smart Car

Smart Car          In this Arduino Tutorial I will show You How to make a Smart Car using Arduino Uno Board and other some Electronic Components. You can Watch this Video or Read the Following Blog for more details.

Measuring Distance Using UltraSonic Sensor with Arduino

Measuring Distance     Using Arduino, UltraSonic Sensor & OLED Display                In this Arduino Tutorial , I will show you How to Measure a Distance of an Object Using Arduino , UltraSonic Sensor & OLED Display . You can watch this Video or Read the following Blogs for More Details.

NodeMCU WiFi Car

 WiFi Car    In this Tutorial I will Show you How to Make a WiFi Car Using NodeMCU ESP8266 Board and Some Electronic Components . You can Watch this Video or Read the following blog for more details..

N95 Respirator Mask

N95

NodeMCU WiFi Switch

 Wi-Fi Switch          In this Tutorial , I will Show you How to Control your Home Appliances by Using Smartphone Over WiFi Connection with NodeMCU ESP8266 Board and Relay(Electric Switch). You can watch this Video or read the following Blog for more Details...