×
Assignments About Home Final Project
☰ MENU


Topic 8: Electronic output devices



During class we learnt how to controll buzzers and LED strips and how to run stepper motors and servo motors. For this week assignment I decided to build a small machine run by two stepper motors, which will be part of my final project.


I needed my machine to have four wheels in order to be as stable as possible because in my final project the machine will need to carry other objects; since I didn't want to use too many motors I decided to have the two front wheels connected to motors and leave the back two wheels free to move.

git1

I connected the two stepper motors to my Metro board and I wrote an arduino program to run both of them:

          


                            #include < Stepper.h >

                            const int stepsPerRevolution = 200;  

                            Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
                            Stepper myStepper2(stepsPerRevolution, 3, 4, 5, 6);

                            void setup() {

                             // set the speed at 80 rpm:
                             myStepper.setSpeed(80);
                             // initialize the serial port:
                             Serial.begin(9600);
                            }

                            void loop() {

                            myStepper.step(400);
  
                            myStepper.step(400);
                            delay(10);

 
                            }

However arduino can not run two motors at the same time so this is what happened:



So I changed the program to make each motor go for one step and changed the delay to make it very small. In this way the rotation of the motors is so fast that it seemed like both motors were moving continuously.
This is my new program:

          


#include < Stepper.h >
const int stepsPerRevolution = 200;  

// initialize the stepper library 
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 3, 4, 5, 6);



void setup() {
  // set the speed 
  myStepper1.setSpeed(80);
   myStepper2.setSpeed(80);
  Serial.begin(9600);

}

void loop() {

  myStepper2.step(1), myStepper1.step(1); 
 //one step clockwise
 
  delay(1);

 }

git2

When I put my motors inside the box I noticed that they were placed in opposite direction so one was running clockwise and the other counterclockwise so I had to change the program again:

          


#include < Stepper.h >
const int stepsPerRevolution = 200;  

// initialize the stepper library 
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 3, 4, 5, 6);



void setup() {
  // set the speed 
  myStepper1.setSpeed(80);
   myStepper2.setSpeed(80);
  Serial.begin(9600);

}

void loop() {

  myStepper2.step(1), myStepper1.step(-1); 
 //one step clockwise
 
  delay(1);

 }


This time the motors were running correctly so I built my machine using a cardboard box, some wood sticks (to keep the motors in the correct position), insulant tape and a straw.

git3

I had used 5 volts to power my stepper motors and when I started the machine I saw that the motors were not able to move the wheels because the machine was too heavy.
So I looked at the datasheet to understand if there was something wrong with my circuit.

git4

Looking at the datasheet I discovered that the recommended voltage for this motor was 12 Volts so I needed more power to correctly run the motors, since I wasn't sure if 12 Volt were too much for the metro board I solved the problem by connecting to my circuit two powerbanks in series:

git5

This is my final circuit:

git6

In this video you can see my machine working:



Here are some arduino program to make the machine move in different directions:

          
            // THIS PROGRAM MAKES THE MACHINE MOVE FORWARD AND BACK

#include < Stepper.h >

const int stepsPerRevolution = 200;  

// initialize the stepper library 
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 3, 4, 5, 6);



void setup() {
  // set the speed 
  myStepper1.setSpeed(80);
   myStepper2.setSpeed(80);
  Serial.begin(9600);

}

void loop() {
  // step one revolution  in one direction:

 if (millis()%10000 > 5000  ) {
 
  myStepper2.step(1), myStepper1.step(-1); 
 //move forward
 
  delay(1);
 }
 else {
 
  myStepper2.step(-1), myStepper1.step(1); 
 //turn
 
  delay(1);
 }

 

 }


// THIS PROGRAM MAKES THE MACHINE TURN EVERY SIX SECONDS

#include < Stepper.h >
const int stepsPerRevolution = 200;  

// initialize the stepper library 
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 3, 4, 5, 6);



void setup() {
  // set the speed 
  myStepper1.setSpeed(80);
   myStepper2.setSpeed(80);
  Serial.begin(9600);

}

void loop() {
  // step one revolution  in one direction:

 if (millis()%10000 > 1000  &&  millis()%10000 < 4000) {
 
  myStepper2.step(1), myStepper1.step(-1); 
 //stepper1 clockwise
 
  delay(1);
 }
 else {
 
  myStepper2.step(1), myStepper1.step(1); 
 //stepper1 clockwise
 
  delay(1);
 }

 

 }