Human Following Robot by Heyab, Oliver, Abdullahi

by PHS_Engineering in Circuits > Arduino

221 Views, 0 Favorites, 0 Comments

Human Following Robot by Heyab, Oliver, Abdullahi

IMG-9100.jpg

We made to a robot follow a person. We will be using a ultro sonic sensor to do this and connect our arduino to the robot. The wires and all the hardware will be tapped down on top robot. The robot wont be able to turn but will stop moving if its 1 foot away.

Supplies

IMG-8995.jpg

The materials we used were

  • ultra sonic sensor
  • breadboard jumper wires
  • breadboard
  • usb cable
  • nps transistor pn2222
  • resistors
  • arduino uno
  • female to male jumper wires
  • diode rectifier

Wire the Arduino

dc motar.jpg

First you are going to wire up your arduino and your DC motar, you will use GND and 5V. follow the diagram above.

Connect the Ultra Sonic Sensor

ultra sonic sensor.png

Now your going to connect the ultra sonic sensor.

Code

This is the code we used:

(after you copy the code your complete)

int Drivepin = 9;

#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 #define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04

long duration; // variable for the duration of sound wave travel int dist; // variable for the distance measurement

void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor Serial.println("with Arduino UNO R3"); pinMode(Drivepin,OUTPUT); }

void loop() {

// Clears the trigPin condition digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance dist = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back) // Displays the distance on the Serial Monitor Serial.print("Distance: "); Serial.print(dist); Serial.println(" cm");

digitalWrite(Drivepin,HIGH);

if(dist<66 && dist > 33) { digitalWrite(Drivepin,HIGH); } else { digitalWrite(Drivepin,LOW);

} }