Skip to main content

how to make Obstacle avoiding robot at home

Arduino automatic robot
Needed
  • Arduino UNO
    • Mini breadboard
    • L298 motor driver module
    • 2x dc motors with wheels
    • HC-SR04 ultrasonic sensor
    • Micro servo motor
    • Button
    • Red LED
    • 220 Ohm resistor
    • 9V battery holder (with or without power jack)
    • 8 spacers (male-female)
    • 8 nuts and 8 screws
    Make this circuit perfectly
    Get the code of your arduino from here 

    //Obstacle Avoiding robot
    //Praveen Sridhar
    //psbots.blogspot.com
    const int left=1,mid=2,right=3;
    const int i1=8,i2=10,ea=9,i3=5,i4=7,eb=6;
    const int cthres=600,rthres=600,lthres=600;
    int s1=0;
    int s2=0;
    int s3=0;
    int r;
    void setup()
    {
      Serial.begin(9600);
      pinMode(i1,OUTPUT);
      pinMode(i2,OUTPUT);
      pinMode(ea,OUTPUT);
      pinMode(13,OUTPUT);
      pinMode(i4,OUTPUT);
      pinMode(eb,OUTPUT);
    }
    void updateS()
    {
      s1=analogRead(left);
      s2=analogRead(mid);
      s3=analogRead(right);
    }
    void moveforward()
    {
     analogWrite(ea,200);
     analogWrite(eb,200);
     digitalWrite(i2,LOW);
     digitalWrite(i1,HIGH);
     digitalWrite(i4,LOW);
     digitalWrite(i3,HIGH);
    }
    void turnleft()
    {
      analogWrite(ea,150);
      analogWrite(eb,150);
      digitalWrite(i1,LOW);
      digitalWrite(i2,HIGH);
      digitalWrite(i4,LOW);
      digitalWrite(i3,HIGH);
    }
    void turnright()
    {
      analogWrite(eb,150);
      analogWrite(ea,150);
      digitalWrite(i2,LOW);
      digitalWrite(i1,HIGH);
      digitalWrite(i3,LOW);
      digitalWrite(i4,HIGH);
    }
    void loop()
    {
      moveforward();
      
      updateS();
      
      if(s2>cthres)
      {
        randomSeed(analogRead(0));
        r=random(3000);
        if(r%2==0)
            turnright();
        else
            turnleft();
        while((s3>rthres-10||s2>cthres-10))
        {
          updateS();
          delay(10);
        }
        moveforward();
      }
      
      if((s3>rthres)||((s3>rthres)&&(s2>cthres)))
      {
        turnleft();
        while(s3>rthres-10)
        {
          updateS();
          delay(10);
        }
        moveforward();
      }
      
      if((s1>lthres)||((s1>lthres)&&(s2>cthres)))
      {
        turnright();
        while(s1>lthres-10)
        {
          updateS();
          delay(10);
        }
        moveforward();
      }
        
    }
    This code is depend on your pin configuration

    Comments

    Popular posts from this blog

    Arduino colour sensor and servo pro

    Colour sensor with servo project Making All we need for this project is one color sensor (TCS3200) and two hobbyist servo motors, which makes this project quite simple but yet very fun to build it. In the first place, using the Solidworks 3D modeling software I made the design of the color sorter and here’s its working principle Initially, the colored skittles which are held in the charger drop into the platform attached on the top servo motor.Then the servo motor rotates and brings the skittle to the color sensor which detects its color.After that the bottom servo motor rotates to the particular position and then the top servo motor rotates again till the skittle drop into the guide rail. Connecting method The code is below /* Arduino Project - Color Sorting Machine * * by Dejan Nedelkovski, www.HowToMechatronics.com * */ #include <Servo.h> #define S0 2 #define S1 3 #define S2 4 #define S3 5 #define sensorOut 6 Servo topServo; Servo b...

    how to fire a matchstrick wirelessly using android phone

    Copper wire:0.5mm/1mm Copper wire:0.1-0.4mm Motor Arduino esp8266 12E 5v relay module Alkaline battery:5v-9v AA battery:3v Android phone Blynk application No worry about this circuit because this is 100% working and tested. The basic consept of this circuit is below This circuit is possible because mini copper wire get more heat than the bigger wire. Codeing method First you install arduino ide on your pc Then copy and paste this code in your arduino #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "YourAuthToken"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; void setup() {   Serial.begi...

    how to login windows 7 without password using command promt

    windows 7 password hacking step by step Now you can  bypass your Windows 7 logon screen free with command prompt  in safe mode. In Windows 7 computer, there are 3 different types of safe modes to choose, Safe Mode, Safe Mode with Networking and Safe Mode with Command Prompt. In order to make full use of command prompt to bypass Windows login password, we just could select the third one. Step 1: Restart your Windows 7 computer and hold on pressing F8 to enter Advanced Boot Options. Step 2: Choose Safe Mode with Command Prompt in the coming screen and press Enter. Step 3: In pop up command prompt window, type net user and hit Enter. Then all Windows 7 user accounts would be listed in the window. Just find the login user which ever appeared again and again on Windows 7 logon screen. Step 4: Remove the Windows 7 login user password with net user command. For example, if...