The Science Of Today Is The Technology Of Tomorrow

How To Make a Simple Autonomous Robot



**Updates: wiring diagram,
                  step by step tutorial
         
Tutorial:
    This is a simple autonomous robot which you can make easily at home without much experience of electronics and coding.  It works on the principle of echolocation using the SONAR. The ultrasound sensor is used for detecting the obstacle. It basically moves around and if it detects any obstacles in its path it will avoid and find its way out.


List of components with Estimated price in INR:
    1. Arduino: Any arduino will do- Arduino UNO, Nano, Mega, Mini, Micro etc.
         (Estimated Rs. 500)
    2. Ping Sensor/ ultrasound sensor: HC SR-04
         (estimated Rs. 150)
    3. Servo motor: Micro Servo motor SG90/ MG90
         (estimated price Rs.300)
    4. BO motor 60-150 RPM two pieces
        (estimated price Rs. 300)
        **please select motor RPM of not more then 150 RPM because it becomes unstable.
    6. BO motor wheel two pieces
        (estimated price Rs.150)
    7. Motor Driver: L298 motor driver
       (estimated Price Rs.250)
    8. Castor Wheel
       (Estimated Price Rs.100)
     9. Jumper Wire:
       (Estimated Price Rs. 100)
     10. Battery: 12V
         (you can buy a rechargeable or you can run from AA/AAA batteries by connecting them in series to obtain 12 volts. But I suggest you buy a rechargeable one because its a pain in the ass to buy a new dry cell every time.)
          (estimated cost: depends upon what you choose: Rs. 80- 1000
     10. Chasis: You can buy a ready made or you can make one of your own like I did.
          ( in case you buy Estimated: Rs. 150)

Now once you have all the above materials you are ready to go.

Watch the tutorial Video  and SUBSCRIBE to my channel or continue reading.





Steps:
1. First of all plan how you want the robot to look. It may be very simple or nice looking like Wall-E.
2. Solder all the terminals of the motors and sensors. you can connect them with jumper wire too.
3. once the soldering is done, place all the components in their places. I don't have any idea how you want to and where you wish to place them but I suppose you have plan it well.
4. Next connect all the wires All GND to Common. And other wires to their designated place.
5. Upload the codes and make a test run.
** if the motor seems to spin in opposite directions, just reverse the wire of the motor.
**if the turning of the robot is not very efficient adjust the delay of the motor on time on the code.
**in case you motor is of high RPM and you want the robot to move a bit slower, adjust the PWM output.
the wiring diagram is given below.


IF YOU NEED ANY HELP COMMENT IN THE YOUTUBE COMMENT SECTION.




Wiring Diagram


____________________________
New Ping Library, Download from here →
https://playground.arduino.cc/Code/NewPing


The codes for the robot:


Please copy the codes after the line and paste it directly.

_________________________________________________________________


//This is the code for the robot                                        
// make sure to  include the NewPing and Servo Libraries  before uploading else it will show error

#include <NewPing.h> 
#include <Servo.h>   
#define TRIG_PIN A4  
#define ECHO_PIN A5  
#define MAX_DISTANCE 200  
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);  
Servo myservo;     
boolean goesForward=false; 
int distance = 100; 
int speedSet = 0;  
const int motorPin1  = 11;   
const int motorPin2  = 10;   
//Motor B 
const int motorPin3  = 6;  
const int motorPin4  = 5;    
void setup() {  
  myservo.attach(9);   
  myservo.write(115);  
  delay(2000); 
  distance = readPing(); 
  delay(100); 
  distance = readPing(); 
  delay(100); 
  distance = readPing(); 
  delay(100); 
  distance = readPing(); 
  delay(100); 
}  
void loop() { 
 int distanceR = 0; 
 int distanceL =  0; 
 delay(40); 
  
 if(distance<=20) 
 { 
  moveStop(); 
  delay(100); 
  moveBackward(); 
  delay(600); 
  moveStop(); 
  delay(200); 
  distanceR = lookRight(); 
  delay(200); 
  distanceL = lookLeft(); 
  delay(200);  
  if(distanceR>=distanceL) 
  { 
    turnRight(); 
    moveStop(); 
  }else 
  { 
    turnLeft(); 
    moveStop(); 
  } 
 }else 
 { 
  moveForward(); 
 } 
 distance = readPing(); 
}  
int lookRight() 
    myservo.write(50);  
    delay(500); 
    int distance = readPing(); 
    delay(100); 
    myservo.write(115);  
    return distance; 
}  
int lookLeft() 
    myservo.write(170);  
    delay(500); 
    int distance = readPing(); 
    delay(100); 
    myservo.write(115);  
    return distance; 
    delay(100); 
}  
int readPing() {  
  delay(70); 
  int cm = sonar.ping_cm(); 
  if(cm==0) 
  { 
    cm = 250; 
  } 
  return cm; 
}  
void moveStop() { 
  analogWrite(motorPin1, 0); 
    analogWrite(motorPin2, 0); 
    analogWrite(motorPin3, 0); 
    analogWrite(motorPin4, 0); 
  }  
   
void moveForward() {   
    analogWrite(motorPin1, 230);
 //the value 230 here is a PWM so you can change it depending up on your motor speed
    analogWrite(motorPin2, 0); 
    analogWrite(motorPin3, 230);
 // this one too is the PWM for other motor
    analogWrite(motorPin4, 0);   
   
}  
void moveBackward() { 
     
    analogWrite(motorPin1, 0); 
    analogWrite(motorPin2, 230);
    analogWrite(motorPin3, 0); 
    analogWrite(motorPin4, 230);    
   
}    
void turnRight() { 
 analogWrite(motorPin1, 240); 
    analogWrite(motorPin2, 0); 
  analogWrite(motorPin3, 0); 
    analogWrite(motorPin4, 230);     
  delay(1200); 
 moveForward();       
   
}  
  
void turnLeft() { 
  analogWrite(motorPin1, 0); 
    analogWrite(motorPin2, 240);    
 analogWrite(motorPin3, 240); 
    analogWrite(motorPin4, 0);      
  delay(800); 
   moveForward(); 
}


_______________________________________________________________________
How To Make a Simple Autonomous Robot How To Make a Simple Autonomous Robot Reviewed by Unknown on February 25, 2017 Rating: 5

35 comments:

  1. Replies
    1. This comment has been removed by the author.

      Delete
    2. you miss the NEWPING sensor librairy, include it or install it from github

      Delete
    3. Thank you for your help Bro. :)

      Delete
  2. Very good, Can this work with arduino uno and adafruit motorshield v2 ?
    could you post a code for this if possible...Thanks

    ReplyDelete
  3. How to include the new ping abd servo libraries

    ReplyDelete
    Replies
    1. instal servo librairy, or if you have it, put it in the code by choose it

      Delete
  4. can we use arduino UNO instead of nano?

    ReplyDelete
  5. It seems that GRD for the Nano is missed . And is it correct that servo gets grd from 12V and vcc from 5V? I am confused.

    ReplyDelete
    Replies
    1. Thanks for telling that. i missed to connect the GND of the arduino.
      and yeah, GND works for all as common, battery, ping, arduino, servo.

      Delete
  6. 1 GND is enough H-bridge will take care of it.
    Great work.
    New ping lib you can add from arduino program go to library and add NewPing.

    ReplyDelete
  7. Excellent. It worked immediately, but my model shortly after running starts spinning on itself and enters in a loop that can not leave until I put my hand or a piece of paper in front of the ultrasonic sensor.
    Could you tell me what the problem is? Thank you very much for your valuable design.
    Mario.

    ReplyDelete
    Replies
    1. If u made this project could u tell me about this connections??

      Delete
  8. Hi, I found most parts in my usual shops. But I'm uncertain about the battery 12v.
    Anyone who can give some more info what kind of battery is needed?

    ReplyDelete
  9. I uploaded the codes and connected the 9 v battery not working and how did you make the 12 v battery I just don't know the connections to make 12 v battery

    ReplyDelete
  10. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    rpa Training in Bangalore

    ReplyDelete
  11. hi! i’m making these project for school and i chave a big roblem because nothing work 😭😭😭 can i put on arduino „hot metal” ( i dont now the world) besause it start to burn 😟😟😟 i have 2 days pleas help!

    ReplyDelete
  12. hi! i’m making these project for school and i chave a big roblem because nothing work 😭😭😭 can i put on arduino „hot metal” ( i dont now the world) besause it start to burn 😟😟😟 i have 2 days pleas help!

    ReplyDelete
  13. hola ...a la hora de compilar muestra stray ´303´ in program y voy a esa linea del programa y es en más:
    moveStop ();
    }
    }más /....303 aqui muestra error

    ReplyDelete
  14. Sir great work u have done making this bot . Please continue to make Arduino nano based similar robots.

    ReplyDelete
  15. Can you send me the connection of this project??

    ReplyDelete
  16. What are the dimensions of the chasis?

    ReplyDelete

Powered by Blogger.