Goal: Our goal is to build and program a robot to follow a black line by itself. We had to build the robot ourselves and figure out how to program it. Research & Imagining: We looked online to figure out how to connect all of the wires and taped the sensors and batteries down. The biggest affect on our design came from the wires and their limited length leading us to place the motor controller in the center of the robot and the batteries on the front and back of the robot. The size of the line also affected our design by leading us to placing the sensors 2.5 cm apart so they can accurately follow the line. I haven't used an Arduino before, but I know how to program in HTML and Python which helped me program the robot. Plan: We looked at videos on how to wire the robots which helped us figure out where to place all of the components on the robot. We also researched how to create the program for the robot to control the motors and identify when the sensors were being activated. Create: We used the process outlined on the flow chart to keep the robot following the line. When one of the sensors senses black, it then turns that direction until it senses white to get it back on the line. If both sensors sense white then it proceeds to drive straight. Otherwise the motors both stop. To set up the robot we connected the motor wires from the Arduino to the motor controller through three wires for each motor. A wire to turn the motor forwards one to turn it backwards and one to determine the speed of the rotation. The motor controller also connects to a ground and power pins on the Arduino. The sensors each connect to a ground, power, A, and regular pins on the Arduino. One to provide power, one to provide input, one to provide output, and one to provide the ground. We set the robot up with the motor controller in the center of the robot, because the motor wires were to short for us to put it anywhere else. The sensors are in the front in order for the robot to sense the line in front of it in order for it to adjust to follow the line. We placed the Arduino in back, because we didn't have another spot on the robot where it would fit and the wires were long enough not to be an issue. Finally, we placed the batteries next to the Arduino and above the motor controller, so the wires connecting them to the different components can reach. Test: Throughout testing we have tweaked small details in the code like motor speed for driving straight as well as for turning. our robot is able to accurately follow straight lines as well as curves below 90 degrees. Throughout testing we have tried to reduce this issue, but while we have been able to get it to do some 90 degree turns, it will usually get off track when faced with extremely sharp turns or with multiple 90 degree turns. If I were to do this project again I would design the robot to be able to follow these sharp turns. Code // Black Line Follower int IR1=4; //Right sensor int IR2=11; //left Sensor // motor one int enA = 5; //Right motor int MotorAip1=6; int MotorAip2=7; // motor two int enB = 10 ; //Left motor int MotorBip1=9; int MotorBip2=8; void setup() { pinMode(enA, OUTPUT); pinMode(enB, OUTPUT); pinMode(IR1,INPUT); pinMode(IR2,INPUT); pinMode(MotorAip1,OUTPUT); pinMode(MotorAip2,OUTPUT); pinMode(MotorBip1,OUTPUT); pinMode(MotorBip2,OUTPUT); } void loop() { if(digitalRead(IR1)==HIGH && digitalRead(IR2)==HIGH) //IR will not glow on black line { //Stop both Motors digitalWrite(MotorAip1,LOW); digitalWrite(MotorAip2,LOW); digitalWrite(MotorBip1,LOW); digitalWrite(MotorBip2,LOW); analogWrite (enA, 0); analogWrite (enB, 0); } else if(digitalRead(IR1)==LOW && digitalRead(IR2)==LOW) //IR not on black line { //Move both the Motors digitalWrite(MotorAip1,HIGH); digitalWrite(MotorAip2,LOW); digitalWrite(MotorBip1,HIGH); digitalWrite(MotorBip2,LOW); analogWrite (enA, 82); analogWrite (enB, 65); } else if(digitalRead(IR1)==LOW && digitalRead(IR2)==HIGH) { //Tilt robot towards left by stopping the left wheel and moving the right one digitalWrite(MotorAip1,HIGH); digitalWrite(MotorAip2,LOW); digitalWrite(MotorBip1,LOW); digitalWrite(MotorBip2,HIGH); analogWrite (enA, 87); analogWrite (enB, 87); delay(50); } else { //Tilt robot towards right by stopping the right wheel and moving the left one digitalWrite(MotorAip1,LOW); // If I want to turn right then the speed of the right wheel should be less than that of the left wheel, here, let a be the right wheel digitalWrite(MotorAip2,HIGH); digitalWrite(MotorBip1,HIGH); digitalWrite(MotorBip2,LOW); analogWrite (enA, 87); analogWrite (enB, 87); delay(50); } } |