![Picture](/uploads/1/1/2/9/11290722/20160920-124427.jpg?250)
(A DC motor is any of a class of electrical machines that converts direct current electrical power into mechanical power. The most common types rely on the forces produced by magnetic fields.)
Tutorial
Materials:
1. Arduino board
2. Bridge board
3. Jumper wires
4. 9 volt battery (optional)
I began by observing and comparing the schematic to the video in the tutorial website. My first set up got parts of the lights on the bridge board lit up, however, the stepper motor wasn't working. At first I thought it was supposed to turn manually like how POT controls the servo motor, however, Mr. Robert told me that the stepper motor is supposed to turn in phrases and is automatic. I also had a problem-- my Arduino wouldn't connect to the port. By adjusting the loose wires, I realized that the two wires that connects to the bridge board is the culprits. When I remove them, the Arduino is able to connect to the port. But without them connected to the bridge board, the circuit wouldn't be complete. So what I did was I tried to hold it in place (that didn't work), then I tried switch the two wires around (this completed the circuit, but the stepper motor still wouldn't function).
/* make BYJ-48 step motor rotating clockwise and counter clockwise
* project tutorial see http://osoyoo.com/?p=201
*/
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left=4095;
long time;
void setup()
{
Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// delay(1000);
}
void loop()
{
while(steps_left>0){
currentMillis = micros();
if(currentMillis-last_time>=1000){
stepper(1);
time=time+micros()-last_time;
last_time=micros();
steps_left--;
}
}
Serial.println(time);
Serial.println("Wait...!");
delay(2000);
Direction=!Direction;
steps_left=4095;
}
void stepper(int xw){
for (int x=0;x<xw;x++){
switch(Steps){
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}
SetDirection();
}
}
void SetDirection(){
if(Direction==1){ Steps++;}
if(Direction==0){ Steps--; }
if(Steps>7){Steps=0;}
if(Steps<0){Steps=7; }
}