First Milestone
My First Milestone for the Floor Cleaning Robot was to assemble the chassis and to completely wire the circuit. The circuit is built around an Arduino Uno, as several parts are intricately wired to it. For example, a Motor Driver is necessary in order to control the motors used to move the robot. Also, an Ultrasonic Sensor holds its place as a vital ingredient of the circuit. It acts as a set of eyes, as it measures distance with high accuracy and consistent readings.
Second Milestone
For my Second Milestone, I soldered the circuit (and mounted it to the chassis), wrote the code, and tested the robot. In order for the circuit to be durable and functional, I had to solder the wires that went from the motor driver to the motors. After each solder, I used a multimeter to see if there was a connection between the 2 sources. The soldering process was challenging, as getting the perfect connection took various attempts. Once my circuit was fully complete, I wrote the code of the project. I essentially coded the ultrasonic sensor to trigger and send information to the robot if it detected an obstacle within 10 centimeters ahead of it. Specifically, I told the robot to make a right turn whenever it receives this information from the ultrasonic sensor. Also, the robot was coded to move forwards whenever something wasn’t in its way. My full code is shown in the picture to the left. Finally, I mounted my circuit onto the chassis and tested the robot. It turned out that the robot was successfully avoiding walls and making turns.
#define enA 3 //enable pin of motor a | |
#define in1 8 // left pin of motor a | |
#define in2 7 // right pin of motor a | |
#define enB 5 | |
#define in3 6 | |
#define in4 4 | |
#define trigPin 12 | |
#define echoPin 13 | |
int motorSpeedA = 0; | |
int motorSpeedB = 0; | |
long duration; | |
int distance; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(enA, OUTPUT); | |
pinMode(enB, OUTPUT); | |
pinMode(in1, OUTPUT); | |
pinMode(in2, OUTPUT); | |
pinMode(in3, OUTPUT); | |
pinMode(in4, OUTPUT); | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
// Begin Serial communication at a baudrate of 9600: | |
Serial.begin(9600); | |
} | |
void loop() { | |
// clear the trigPin by setting it LOW: | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(5); | |
// Trigger the sensor by setting the trigPin high for 10 microseconds: | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
//Read the echoPin, pulseIn() returns the duration in microseconds: | |
duration = pulseIn(echoPin, HIGH); | |
//Calculate the distance: | |
distance = duration*0.034/2; | |
//Print the distance on the Serial Monitor (Ctrl+Shift+M) | |
Serial.print("Distance = "); | |
Serial.print(distance); | |
Serial.println("cm"); | |
if (distance < 10) { | |
digitalWrite(in1, HIGH); // turn left pin of motor a to high | |
digitalWrite(in2, LOW); // turn right pin of motor a to high | |
analogWrite(enA, 150); // set speed of motor A | |
digitalWrite(in3, LOW); // turn left pin of motor b to low | |
digitalWrite(in4, HIGH); // turn right pin of motor b to high | |
analogWrite(enB, 150); // set speed of motor B | |
} | |
else { | |
digitalWrite(in1, HIGH); // turn left pin of motor a to high | |
digitalWrite(in2, LOW); // turn right pin of motor a to low | |
analogWrite(enA, 150); // set speed of motor A | |
digitalWrite(in3, HIGH); // turn left pin of motor b to high | |
digitalWrite(in4, LOW); // turn right pin of motor b to low | |
analogWrite(enB, 150); // set speed of motor B | |
} | |
} |
Third Milestone
My Third Milestone consists of rearranging the circuit, upgrading the parts, and wiring a sound sensor. To create more space on the chassis, I removed the breadboard and rearranged the parts of the circuit. I mounted the ultrasonic sensor on the front of the robot so that it could still detect obstacles. The Arduino and motor driver were arranged in a less cramped fashion. Also, I upgraded the 4-battery pack to a 6-battery pack, greatly increasing the overall voltage. To clean the floor, I added a brush to the front of the robot. Additionally, as the start of a future modification, I wired a sound sensor to the Arduino. I will eventually code it to detect a hand clap and tell the motor driver to make a turn.