This week we will have to uses are knowledge from the previous week on arduino to help create a buggy that is able to move/ turn. Where we are provided with two stepper motor, arduino board, a LDC screen, a ultrasonic module, a frame/ housing for components, a set of wheels and wires needed for this build.
Since we have two stepper motors we will have to define each individual pin for each motor
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
}
Here is the coded to move the buggy forward
void loop() {
//step 1
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8,LOW );
digitalWrite(7,HIGH );
digitalWrite(6,HIGH );
delay(2);
//step 2
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8,HIGH );
digitalWrite(7,HIGH );
digitalWrite(6,LOW );
delay(2);
//step 3
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8,HIGH );
digitalWrite(7,LOW );
digitalWrite(6,LOW );
delay(2);
//step 4
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8,LOW );
digitalWrite(7,LOW );
digitalWrite(6,HIGH );
delay(2);
}
Here is the code to move the buggy backwards:
void loop(){
//turn 4
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8,LOW );
digitalWrite(7,LOW );
digitalWrite(6,HIGH );
delay(2);
//turn 3
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8,HIGH );
digitalWrite(7,LOW );
digitalWrite(6,LOW );
delay(2);
//step 2
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8,HIGH );
digitalWrite(7,HIGH );
digitalWrite(6,LOW );
delay(2);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8,LOW );
digitalWrite(7,HIGH );
digitalWrite(6,HIGH );
delay(2);
}
Leave a Reply