Introduction: Autonomous Roaming Cat

Robotics is been fun and playful for kids and even for youngsters. But, it’s been a challenging scenario for engineers and researchers to build an advanced electro-mechanical machines. Science and engineering plays a greater role to develop a new technology for building advanced robots. Science and mathematics lies behind from a tiny little walking robot (which is called as ‘toys’ for normal humans) to a bigger size humanoid robot. Everyone admires and appreciates the product and the creator, but not the science and maths behind it.

It’s not about equations and coding. It’s about curiosity and interest. So, here is your place to learn robotics in advancements with fun and maths :)


Let’s smash up things and play with robots…………!

Step 1: Introduction

A wheeled robot which can avoid the obstacles in its visibility by finding and comparing range of the object in its view by mimicking the function of cute kitty. It’s autonomous in function. This robot is a basic start to autonomous robotics.

Time Duration:

> Expert’s: 40 minutes > Starter’s: 180 minutes

Things you will need:

> Ultrasonic sensor (PING Sensor)

> Arduino based microcontroller- Arduino Uno

> Single strand wires / Jumper wires

> Servo motor

> Bread board

> L293D driver IC (You can use Motor Shield too)

> 2 set of Wheels

> 1 set DC motors (500rpm)

> Dummy axles

> Chassis

> 12V Battery

Note: You can get these components from a local electronic stores market or from online stores such as www.ebay.com or you can seek near by electronics hub / hobby stores.

Step 2: Sensor Overview

Ultrasonic sensor / Ping sensor:

> Ultrasonic sensor is simply a transducers which evaluate the attributes of the target by interpreting the echoes from radio or sound waves. It functions by measuring the time interval between sending the signal and receiving the echo to determine the distance to an object.

Servo motor:

> Servo motors has three simple parts: a DC motor, potentiometer and a control circuit. The motor is attached by gears to the control wheel. As the motor rotates, the potentiometer's resistance changes, so the control circuit can precisely regulate how much movement there is and in which direction.

> When the shaft of the motor is at the desired position, power supplied to the motor is stopped. If not, the motor is turned in the appropriate direction. The desired position is sent via electrical pulses through the signal wire. The motor's speed is proportional to the difference between its actual position and desired position. So if the motor is near the desired position, it will turn slowly, otherwise it will turn fast. This is called proportional control.

> Servos are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM), through the control wire. There is a minimum pulse, a maximum pulse, and a repetition rate. A servo motor can usually only turn 90 degrees in either direction for a total of 180 degree movement. The motor's neutral position is defined as the position where the servo has the same amount of potential rotation in the both the clockwise or counter-clockwise direction. The PWM sent to the motor determines position of the shaft, and based on the duration of the pulse sent via the control wire; the rotor will turn to the desired position. The servo motor expects to see a pulse every 20 milliseconds and the length of the pulse will determine how far the motor turns.

L293D IC:

> L293D is a motor driver IC which has the H-Bridge circuit inbuilt within it. It can control two motors by enabling the corresponding input and output pins of the IC. Refer to the picture for getting an overview of the Pins used.

Step 3: Programming the Arduino

Programming is just a way to speak/communicate with the components>

> Download the Arduino IDE software from the link below, www.arduino.cc/en/Main/Software

> Install suitable drivers to your PC/Laptop for uploading the codes into the Arduino Uno.

Let’s do programming >

At first let us work on ultrasonic sensor>

> Connect the Arduino Uno to the PC which has Arduino IDE software. Type the codes below, which is used to find the distance of the obstacle using the ultrasonic sensor.

Wire the sensor:

> Connect the ‘trigger pin’ to ‘pin 12’ of Arduino Uno and ‘Echo pin’ to ‘pin 11’ of Arduino Uno.

> Connect the ‘Vcc pin’ and ‘Gnd pin’ to ‘5V pin’ and ‘Gnd Pin’ of Arduino Uno.

> Download the “New Piing” library from www.arduino.cc website and place it in the library folder of Arduino in PC. [The ‘trigger pin’ and ‘echo pin’ can be replaced by ‘SIG pin’ in the program depending upon the model of sensor]

#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.#define MAX_DISTANCE 200 Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. void setup() { Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results. } void loop() { delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). Serial.print("Ping: "); Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.println("cm"); }

Output:

> Use the serial monitor to see the output from Arduino Uno.

> The above code is used to test the ultrasonic sensor by giving the distance of the objects as output in the serial monitor of Arduino IDE. Try focusing the ultrasonic sensor to various objects at various distances.


Step 4: Let’s Centre the Servo

> Take the servo and connect the wires of the servos to the Arduino as said below:

> Identify the Vcc, Gnd, Signal wires of the servo motor correctly as discussed in the Introduction >

· Vcc pin of servo to 5V pin on Arduino

· Gnd pin of servo to Gnd pin on Arduino

· Signal pin of Servo to pin 9 on Arduino

Use the code below to centre the servo at 90 degree position in case of 0 to 180 degree servo.

#include Servo servo;
void setup() { servo.attach(9); // attach the signal wire to pin 9 } void loop(){ servo.write(90); //Turn the servo motor knob to 90 degree }

Output:

> You will find that your servo has turned to 90 degree/centred.

Step 5: Let’s See How L293D Works>

Fix the L293D IC on the breadboard and wire all the pins of the IC accordingly as shown in the pin configuration below:

· motor1 Pin1 = 3 on Arduino // pin 2 on L293D IC

· motor1 Pin2 = 4 on Arduino // pin 7 on L293D IC

· enable1 Pin = 5 on Arduino // pin 1 on L293D IC

· motor2 Pin1 = 8 on Arduino // pin 10 on L293D IC

· motor2 Pin2 = 9 on Arduino // pin 15 on L293D IC

· enable2 Pin = 10 on Arduino // pin 9 on L293D IC

> Connect the output 1, 2 and output 3, 4 to the motor 1 and motor 2 respectively.

> Connect the VCC and V+ to a external battery of 6V to 12V. This will act as a power supply to the motors.

Use the code below to rotate the motors in forward, backward, left and right direction.

int motor1Pin1 = 3; // pin 2 on L293D IC
int motor1Pin2 = 4; // pin 7 on L293D IC
int enable1Pin = 5; // pin 1 on L293D IC
int motor2Pin1 = 8; // pin 10 on L293D IC
int motor2Pin2 = 9; // pin 15 on L293D IC
int enable2Pin = 10; // pin 9 on L293D IC
int state;
void setup() {

// sets the pins as outputs:
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enable2Pin, OUTPUT);
Serial.begin(9600);
}

void loop()

{

if(Serial.available() > 0){                                      //if some date is sent, reads it and saves in state
state = Serial.read();   
}   

if (state == '1') {                                               // if the state is '1' the DC motor will go forward

digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW); 
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);

}     
else if (state == '2') {                                                      
// if the state is '2' the motor will turn left 
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } else if (state == '3' ) {
// if the state is '3' the motor will Stop digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); } else if (state == '4') {
// if the state is '4' the motor will turn right digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } else if (state == '5') {
// if the state is '5' the motor will Reverse digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } }

> Upload the codes into the Arduino and open the serial monitor and type 1 or 2 or 3 or 4 or 5 for respective actions to take place. You should have the data cable connected to the Arduino Uno.

Step 6: Let’s Jump Into Action to Make the Cat

Procedure:

> Attach the Dc motors and dummy axles to the chassis and connect the wheels to it. Make sure to fix the wheels tight enough to the axles.

> Then place a cardboard piece above the chassis (if the chassis is made of metal) to mount the micro-controller board and the bread board on the chassis.

> This is done, so as to reduce any electrical conductivity between the metal chassis and the micro-controller board.

> Mount the servo motor on the front end of the chassis and attach the ultrasonic sensor over its head by using a double side tape.

> Use L-clamps to support the servo motor firmly to the chassis of the robot.

> Follow the steps below for connecting the micro-controller (Arduino Uno) to the ultrasonic sensor, L293D driver and the servo motor.

Circuit diagram:

Connections overview>

Servo motor- signal wire to pin 11 on Arduino Uno

Ultrasonic sensor- Echo pin to pin 6 on Arduino Uno

Ultrasonic sensor- Trigger pin to pin 7 on Arduino Uno

L293D IC- Input 1, 2 (motor 1) to pin 3, 4 on Arduino Uno

Input 3, 4 (motor 2) to pin 8, 9 on Arduino Uno

Enable 1 (motor 1) to pin 5 on Arduino Uno

Enable 2 (motor 2) to pin 10 on Arduino Uno

Step 7: Lets Teach the CAT

Programming the Arduino for Autonomous cat robot:

The program is simple and involves the combinations of above implied programs for ultrasonic sensor, servo motor and L293D motor driver.

Function of the program:

> The ultrasonic sensor is swept 30 degree towards left and right from servos centre position.

> This determines the range of object on the left and right of the robot’s front end.

> The distance is compared and the robot is moved along the direction which has obstacle at a longer distance. > This is looped again and again and the robot moves in a confined space by avoiding the obstacles in its way autonomously

#include                                           //include Servo library

int motor1Pin1 = 3;                                // pin 2 on L293D IC 
int motor1Pin2 = 4;                                // pin 7 on L293D IC
int enable1Pin = 5;                                // pin 1 on L293D IC
int motor2Pin1 = 8;                               // pin 10 on L293D IC
int motor2Pin2 = 9;                               // pin 15 on L293D IC
int enable2Pin = 10; 
const int trigpin = 7; 
const int echopin = 6;
const int dangerThresh = 15;                      //threshold for obstacles (in cm)
int leftDistance, rightDistance;                  //distances on either side
Servo panMotor;  
long duration;                                    //time it takes to receive PING))) signal


void setup() {
// sets the pins as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(enable1Pin, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enable2Pin, OUTPUT); panMotor.attach(11); //attach servo motor to pin 11 panMotor.write(90); //set PING))) pan to center } void loop() { int distanceFwd = ping(); if (distanceFwd>dangerThresh) //if path is clear { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); //move forward } else //if path is blocked { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); panMotor.write(60); delay(1000); rightDistance = ping(); //scan to the right delay(1000); panMotor.write(120); delay(1000); leftDistance = ping(); //scan to the left delay(1000); panMotor.write(90); //return to center delay(1000); compareDistance(); } } void ompareDistance() { if(leftDistance>rightDistance) //if left is less obstructed { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); //turn left delay(1000); } else if (rightDistance>leftDistance) //if right is less obstructed { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); //turn right delay(1000); } else //if they are equally obstructed { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); // go backwards delay(1000); } } long ping() { //Send out PING))) signal pulse pinMode(trigpin, OUTPUT); pinMode(echopin,INPUT); digitalWrite(trigpin, LOW); delayMicroseconds(2); digitalWrite(trigpin, HIGH); delayMicroseconds(10); digitalWrite(trigpin, LOW); //Get duration it takes to receive echo duration = pulseIn(echopin, HIGH); //Convert duration into distance return duration / 29 / 2; }

> Change the connections of respective “input pins” accordingly to rotate the motor in particular direction specified by the program

> You can modify the angle given to sweep the sensor according to your robot size. You can modify the program according to the model of ping sensor used as 4 pins or 3pins.

> Once the program is uploaded, Connect the batteries separately for Arduino and L293D driver and place the robot on the floor and see the fun and the behavior of robot >

Finally we made it. An autonomous cat that rolls on the Surface by avoiding its obstacles on its way, by using its Micro-controller as its brain!

Step 8: Finally We Made It!

Make your own style of Cat!

Robotics Contest 2017

Participated in the
Robotics Contest 2017