13.- App moves a Stepper motor.
p9A0i_bluetooth_pasopaso.aia (3.1 KB)
-
In a servo you order:
set 34º
set 12º
set 96º, it is not necessary to know the previous position. -
In a stepper motor, you order:
set 20 step clockwise
set 80 step anticlockwise, it is necessary to know the previous position to place it in a new position. -
I will use: Stepper motor 28BYJ-48 ULN2003
-
It is convenient to power this motor through an external source, in this experimental example I will feed it with the 5 V of Arduino.
- This code needs Stepper library.
// Juan A. Villalpando
// http://kio4.com/appinventor/9A0_Resumen_Bluetooth.htm
#include <Stepper.h>
#define STEPS 64
// Secuencia 1-3-2-4
Stepper motor(STEPS, 8, 10, 9, 11);
char caracter;
void setup() {
Serial.begin(9600);
motor.setSpeed(200);
}
void loop() {
if( Serial.available() ) {
caracter = Serial.read();
Serial.print(caracter);
if(caracter == '1'){motor.step(60);}
if(caracter == '2'){motor.step(-60);}
if(caracter == '3'){motor.step(510);}
if(caracter == '4'){motor.step(-510);}
if(caracter == '5'){motor.step(1020);}
if(caracter == '6'){motor.step(-1020);}
if(caracter == '7'){motor.step(2040);}
if(caracter == '8'){motor.step(-2040);}
if(caracter == 'A'){motor.step(100);}
if(caracter == 'B'){motor.step(-100);}
}
}