Arduino Uno Automatic Transporting Robot
by jonyeh1688 in Workshop > Electric Vehicles
357 Views, 3 Favorites, 0 Comments
Arduino Uno Automatic Transporting Robot
This is a robot car that transports the objects with a jaw. If the ultrasonic sensor detects there is an object in front of the robot, the machine would catch the object up and move backwards to put the object back to the place that the user is. The robot would keep moving forward to detect the objects and stop until it finds another object in the way of the machine.
Materials
Fischer building blocks
Arduino Uno
Arduino Uno-F5
Jaw
Dubont lines
Ultrasonic sensor
Hardware
In all of the materials, I will build the Fischer building blocks into a car and connect the structure with the two Arduino boards to get the message from the code, which gives the instructions to the jaw and the ultrasonic sensor so the jaw is able to catch the things' directions and working in the system of the program that I wrote.
The Design Sketch
The Circuit Sketch
The Code and the Notations
Link: https://create.arduino.cc/editor/jonyeh/5e71eb79-c14b-4a70-9f28-b4b8518639d6/preview
#define trigPin A0//Pin A0=trigPin
#define echoPin A1//Pin A1=echoPin
#include //Download the servo motor's programs from the library
Servo myservo;//Create the servo-related programs
void oPen(){
myservo.write(150);//Turn to 150 degree(open the jaw)
delay(500);//Remain for 0.5 seconds
}
void cLose(){
myservo.write(90); //Turn to 90 degree(close the jaw)
delay(500);//Remain for 0.5 seconds
}
void forwards() { digitalWrite(3,0);//Different pressure makes the motor move(The directions have to be tested by yourselves)
digitalWrite(5,1);//Different pressure makes the motor move(The directions have to be tested by yourselves)
}
void backwards() {
digitalWrite(3,1);//Different pressure makes the motor move(The directions have to be tested by yourselves)
digitalWrite(5,0);//Different pressure makes the motor move(The directions have to be tested by yourselves)
}
void sTop(){
digitalWrite(3,0);//Same pressure does not make the motor move(The directions have to be tested by yourselves)
digitalWrite(5,0);//Same pressure does not make the motor move(The directions have to be tested by yourselves) }
void setup() {
Serial.begin(9600);//Set the baud(printing speed)
pinMode(3,OUTPUT);//Announce the output of pin 3
pinMode(5,OUTPUT);//Announce the output of pin 5
pinMode(trigPin,OUTPUT);//Announce the output of trigPin(the launched ultrasonic) pinMode(echoPin,INPUT);//Announce the input of echoPin(the reflected ultrasonic)
myservo.attach(5);//Annonce the servo is connected from pin 5(Not the normal pin, but the specialized pin for servo)
}
void loop() {
int duration, distance;//Create the two variables that are used to calculate the distances) digitalWrite(trigPin,HIGH);//Launch the signal to dectect the distance to something delayMicroseconds(1000);//Wait for the signal to detect
digitalWrite(trigPin,LOW);//Close the signal when the ultrasonic system's program is finished duration=pulseIn(echoPin, HIGH);//Count the number that the echoPin get, if the time is too long, the system will give a zero of the value
distance=(duration*0.034/2) ;//Change the measurement to centimeters
Serial.println(distance);//Print the centimeter values out to make sure about the ultrasonic is usable
if (distance>10){//If the distance>10
oPen();//Open the jaw(get from the subprogram)
forwards();//Go foward(get from the subprogram)
digitalWrite(3,0);//Go foward
digitalWrite(5,1);//Go foward }
else{
cLose();//Close the jaw(get from the subprogram)
sTop();//Stop the motor from moving(get from the subprogram)
digitalWrite(3,0);//Stop the motor
digitalWrite(5,0);//Stop the motor
delay(5000);//Wait for 5 seconds(to catch the object for a longer time)
digitalWrite(3,1);//Keep moving after stopping
digitalWrite(5,0);//Keep moving after stopping
delay(2000);//Going for two seconds and use the sensor to detect again
}
}
The Final Test
Link: https://www.youtube.com/watch?v=qgRmeABQYIE