top of page

Arduino Uno R3+ Android+Adafruit Motor Shield v2 + Bluetooth Transceiver (HC-06) + Stepper motor (FL

This article shows how to use Arduino+Android+Adafruit+Bluetooth+stepper.The Andoid APP would be on sale or free download in google paly store soon.

In this article, the most important thing to be solved is how to run AccelStepper codes within Adafruit_MotorShield.h.

Many applications related to stepper speed control. In my research I would like to control the clockwise and anticlockwise of directions of the stepper and speed of the stepper for my patent design of reconfigurable hand.

The Ardroid interface versions are shown as follows:(the first one is android phone version, the second one is pad version)

Arduino code:

/* This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2 It won't work with v1.x motor shields! Only for the v2's with built in PWM control */ #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include <SoftwareSerial.h>

char blueToothVal; //value sent over via bluetooth int sign = 1; // either 1, 0 or -1 int spd = 100; Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Create the motor shield object with the default I2C address // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Connect a stepper motor with 400 steps per revolution (0.9degree) // to motor port #2 (M3 and M4) Adafruit_StepperMotor *myMotor = AFMS.getStepper(400, 2); // Connect a stepper motor with 400 steps per revolution (0.9degree) // to motor port #2 (M3 and M4) const byte rxPin = 2; const byte txPin = 3; // set up a new serial object SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void forwardstep() { // you can change these to DOUBLE or INTERLEAVE or MICROSTEP! myMotor->onestep(FORWARD, DOUBLE); } void backwardstep() { myMotor->onestep(BACKWARD, DOUBLE); } AccelStepper Astepper(forwardstep, backwardstep); // use functions to step void setup() { mySerial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!"); AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); OR with a different frequency, say 1KHz Astepper.setMaxSpeed(300.0); Astepper.setSpeed(0.1); } void loop() { if (mySerial.available()) //if there is data being recieved { blueToothVal = mySerial.read(); //read it if (blueToothVal == 'f') { // forward sign = 1; } if (blueToothVal == 'b') { // reverse sign = -1; } if (blueToothVal == '0') { // slow+++ spd = 1; } if (blueToothVal == '1') { // slow++ spd = 25; } if (blueToothVal == '2') { // slow+ spd = 50; } if (blueToothVal == '3') { // slow spd = 75; } if (blueToothVal == '4') { //medium spd = 100; } if (blueToothVal == '5') { // medium+ spd = 125; } if (blueToothVal == '6') { // medium++ spd = 150; } if (blueToothVal == '7') { // medium+++ spd = 200; } if (blueToothVal == '8') { // Fast spd = 250; } if (blueToothVal == '9') { // Fast+ spd = 300; } Astepper.setSpeed(sign * spd); if (blueToothVal == 's') { // stop Astepper.setSpeed(0.1); } } Astepper.runSpeed(); Astepper.run(); }

References:

http://morethanuser.blogspot.co.uk/2012/11/netdriver-openwrt.html

http://www.microcontroller-project.com/stepper-motor-controlled-with-hc06-bluetooth-module.html

http://www.instructables.com/id/ArduinoAndroid-28BYJ-48-Stepper-Motor-Control-Usin/

http://www.keuwl.com/electronics/rduino/bluet/10-stepper-motor/

https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library/blob/master/examples/Accel_ConstantSpeed/Accel_ConstantSpeed.ino

https://www.pjrc.com/teensy/td_libs_AccelStepper.html

https://learn.adafruit.com/afmotor-library-reference/af-stepper-class

http://mitappsinventor.blogspot.co.uk/2015/05/control-stepper-motor-from-android-app.html

http://www.airspayce.com/mikem/arduino/AccelStepper/

http://appinventor.mit.edu/explore/about-us.html


bottom of page