Making self-defending robot with demonstration video

Understanding automated systems with the help of Arduino platform

( If you are not aware what Arduino actually is, just go to this website: Know about Arduino )



Stuffs you will need:

1. Arduino Uno Board.
2. Arduino IDE installed. (Refer this link: Download Arduino IDE )
3. Servo motor
4. HC-SR04 ( Ultrasonic sensor )
and other necessary stuffs i.e. jumper wires, breadboard etc.



Concept:
We are using HC-SR04 ( Ultrasonic sensor ) in order to interact with real world. Ultrasonic-sensor is being used here in order to measure distance. This distance is later used as input for servo motor, by giving necessary commands we can rotate the servo moter to generate a specific motion. That is how one can control different parts of an automated system as a function of surrounding conditions. 


Let us understand the whole mechanism in following steps:

1. Emitter of HC-SR04 emits Ultrasound in the air (surrounding of robot).

2. In presence of any obstacle, these high frequency sound waves reflect back and detected by receiver of ultrasonic sensor.

3. Time elapsed between emission of Ultrasound and detection is calculated. Think about it how it is done.
(Alright! it's quite easy, it is done in following manner,  the moment Ultrasound is emitted, system clock begins and after detection of Ultrasound, system clock stops. Hence we can compute elapsed time.)

4. As we know speed of  Ultrasound in air is approximately 340 m/s.

5. Using this formula, distance= speed * time; A real-time distance is calculated by the computer program. 

6. This distance as input is sent to the processor and with some coding or commands (i.e. using if/else conditions), output of servo motor is generated.

7. In the code you can see that I've given a command, whenever distance of obstacle is less than 10 cm, activate voltage across servo-motor and rotate it by 180 degree.

8. Distance of response ( means distance at which robot wbill respond ) can be changed through the code. For example you can set it to 20 cm, 30 cm, 100 cm or whatever.



Remark: You can rotate servo motor by any angle i.e. 0 to 360. Here I have rotated it by 180 degree.
If you like you can do some modification in this robot.



See Demonstration Video:

In this video, you can see whenever the distance between obstacle and robot is less than 10 cm, automated system responds in order to protect itself.



Code:

#include <Servo.h>

Servo myservo;   // create servo object to control a servo-motor

const int trigPin = 9;
const int echoPin = 10;                          // defines pins numbers

long duration;
int distance;                                           // defines variables


void setup() 
{
myservo.attach(5);                                 // attaches the servo on pin 5 to the servo object
pinMode(trigPin, OUTPUT);                // Sets the trigPin as an Output
pinMode(echoPin, INPUT);                 // Sets the echoPin as an Input
Serial.begin(9600);                               // Starts the serial communication

}
void loop() {
digitalWrite(trigPin, LOW);                 // Clears the trigPin
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);                      // Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;                 // Calculating the distance

Serial.print("Distance: ");
Serial.println(distance);                        // Prints the distance on the Serial Monitor


/* This is for output of my automated system which decides how it behaves */
while (distance<10)
{for (int i=0;i<=180;i++)
{myservo.write(i);              
delay(1);}
for (int j=180;j>=0;j--)
{myservo.write(j);              
delay(5);}
break;}
}



Hope you enjoyed reading this post. See you soon!

Thanks! 

PS: If you like it, consider sharing with others.


Comments

Popular posts from this blog

IUCAA - ISSAA 2021

Books Catalog For Undergraduate and Graduate Physics Students

Photography Collection