Simple Autonomous Robot

This is a common and easy project for arduino beginners that can be build in under an hour. The main concept  is to create a robot that can move free into space and avoid collisions.

For this project i have used:

- 4 Line Tracker Sensors.

-2 x 5V Relay.

-2 x battery cases (4 batteries x 1.5V each).

-2 x Motors.

-3 or 4 wheels- 2 for the move with the rotors and the others to balance the robot. (in my case i used 3)

-Something to use as the body of the robot (use our imagination! :p ).

-a bunch of wires

- Arduino Uno board.

The Robot (Same as Simple Line Follow Robot):

The wiring is quite easy.  To power arduino 2 crocodile wires were used connected with all the 8 batteries. To power the motors 3 batteries are enough, otherwise it will run too fast.

Connect the line track sensors to arduino digital pins (in my case 2, 4, 7 & 8) and place 3 tracking sensors to the front side of the robot. Place one sensor in the centre and the other 2 slightly left and right of the robot’s centre. The fourth is placed behind the robot but is not used in this project (you can add some extra logic if you want and make things more interesting!). After placing the sensors take a screwdriver and play a bit with the 3 potentiometers on the sensor’s board. By changing the potentiometers you can adjust the sensitivity of the sensors. For the side sensors you can adjust the distance you want the robot to recognise an object.

Now that we have set our inputs you have to connect the relays. Relays are used as a switch to stop & start the motors. In this example we are using the motors at one speed only (on/off) so a relay is the perfect switch. for this project you can use any relay of 5V and more. Connect the one end of the relay’s inductor with ground and the other one with an input signal from arduino digital pin (in my case pin 13 for the one relay and pin 12 for the second). Connect the 3 batteries to the relays input voltage and the normally closed (NC) pin to the motor. Also connect the motor’s second pin to ground and that’s all with the wiring!

*Remember to put photos here!!

The code:

The logic used for the robot is simple. If the sensor on the right side finds an obstacle the robot turns left and vice versa. If it finds an obstacle in the middle it stops.

A small paragraph of code as the one below is more than enough!

/*
Simple Autonomous Robot
Author: Christos Kyprianou
Requires:
  2 relay
  4 line track sensors
  arduino UNO board
  2 motors
*/
int buttonpin1 = 2; // define tracing sensor interface
int buttonpin2 = 4;
int buttonpin3 = 7;
int buttonpin4 = 8;
int rel1 = 12;
int rel2 = 13;
int val ;// define numeric variables val
void setup ()
{
  pinMode (buttonpin1, INPUT) ;// define tracing sensor output interface
  pinMode (buttonpin2, INPUT);
  pinMode (buttonpin3, INPUT);
  pinMode (buttonpin4, INPUT);
  pinMode(rel1, OUTPUT);
  pinMode(rel2,OUTPUT);

  Serial.begin(9600);
}
void loop ()
{
   
  int val1 = digitalRead (buttonpin1) ;// digital interface will be assigned a value of 3 to read val
  int val2 = digitalRead (buttonpin2) ;// digital interface will be assigned a value of 3 to read val
  int val3 = digitalRead (buttonpin3) ;// digital interface will be assigned a value of 3 to read val
  int val4 = digitalRead (buttonpin4) ;// digital interface will be assigned a value of 3 to read val
  
  if (val1 == 1 && val2 ==1 && val3==1)
  {      
    digitalWrite(rel1,HIGH);
    digitalWrite(rel2,HIGH);
  }
  if (val3 == 0)
    digitalWrite(rel2,LOW);
  if (val1 == 0)
    digitalWrite(rel1,LOW);
  if (val2 == 0)
  {      
    digitalWrite(rel1,LOW);
    digitalWrite(rel2,LOW);
  }  
} 

 

The output: