Autonomous Muscat Tire Car

By Nicholas Allen, Ian Muscat, Moe Kawar

basic description:

Our project is a car that moves forwards, backwards, stops, turns left and right all by itself.

How our program works:

the program uses 4 digital pins to control two separate motors which we set as outputs in the setup. In the void loop depending on the high low in the code the motor will either go forward when it is high low, backwards low high, or not move low low. To have it turn right you must have motor A move forwards and motor B backwards. Vice versa for it to turn left. Using shortcuts we can slim the code down to only one line commands instead of rewriting the same code every time we want to move a certain way.

Link to youtube video of our final working

http://www.youtube.com/watch?v=QUg63jfyD1E

Code:

int motorA1 = 2; // sets motor A to the arduino to digital pins 4 and 2 int motorA2 = 4; int motorB1 = 9; //sets motor B to the digital pins 9 and 8 int motorB2 = 8; void setup() { pinMode(motorA1, OUTPUT); //establishes the motors as outputs pinMode(motorA2, OUTPUT); pinMode(motorB1, OUTPUT); pinMode(motorB2, OUTPUT); } void loop() { reverse(2000); //tells car to go in reverse for 2 seconds pause(1000); //tells the car to stop for 1 second reverse(1000); //tells car to reverse for 1 second turnleft(400); //turn left for .4 seconds forward(3000); //tells car to go forward for 3 seconds turnright(400); //tells car to turn right for .4 seconds forward(1000); } //tells car to go forward for 1 secondvoid reverse(int time) //creates the shortcut of reverse to stand for entire code in {} { digitalWrite(motorA1, LOW); //makes motor A go in reverse by reversing the power digitalWrite(motorA2, HIGH); digitalWrite(motorB1, LOW); //makes motor B go in reverse by reversing the power digitalWrite(motorB2, HIGH); delay(time); } //sets delay to what ever time is void pause(int time) //creates pause shortcut { digitalWrite(motorA1, LOW); digitalWrite(motorA2, LOW); digitalWrite(motorB1, LOW); digitalWrite(motorB2, LOW); //turns power off to both motors delay(time); } //sets delay to what ever time is void forward(int time) //creates forward shortcut { digitalWrite(motorA1, HIGH); digitalWrite(motorA2, LOW); //gives power to motor digitalWrite(motorB1, HIGH); digitalWrite(motorB2, LOW); delay(time); } //sets delay to what ever time isvoid turnleft(int time) { digitalWrite(motorB1, HIGH); //motor moving forward digitalWrite(motorB2, LOW); digitalWrite(motorA1, LOW); //motor moving in reverse digitalWrite(motorA2, HIGH); delay (time); } //sets delay to what ever time isvoid turnright(int time) { digitalWrite(motorB1, LOW); //motor moving in reverse digitalWrite(motorB2, HIGH); digitalWrite(motorA1, HIGH); //motor moving forward digitalWrite(motorA2, LOW); delay (time); } //sets delay to what ever time is

Problems encountered:

one problem that we encountered when doing our final was the initial wring of the car with the h bridge and where the wires for the motor went which we resolved by researching and finding that we needed to have the H bridge inverted on the other side. Another problem was getting the HIGH and LOW in the proper spot to have the motors work. fixed through trial and error using different combinations till it was right.

Additions:

if we had more time and resources we would have liked to add sensors to sense when it was close to objects and turn around or avoid them. One other thing i would try to do better was to have it turn more accurate.