Introduction: Control the Stepper Motor With Bluetooth

Picture of Control the Stepper Motor With Bluetooth

I want to make a small car with stepper motors and use my smart phone to control it. Searching on the internet for many days, I find a perfect app called 'GoBLE'. Its interface is similar as a game controller. Bluno is also what I want. It's a development board that integrates a TI CC2540 Bluetooth 4.0 chip.So, I can control the speed and direction of the car with these two stuff. (Maybe I can use LattePanda to do this project! (Still working on it)

And here's my car model. A little simple. Anyway, it can run.

Step 1: What I Need

Picture of What I Need

Hardware:

  • Arduino Bluno x1
  • Dual Bipolar Stepper Motor Shield x1
  • Stepper motor x2

Software:

  • Arduino IDE
  • GoBLE

Step 2: GoBLE

Picture of GoBLE

You can download the GoBLE from the App Store.

Don’t forget to load GoBLE library before you download the testing code!

GoBLE Wiki Link

Step 3: Bluno

Picture of Bluno

Bluno integrates a TI CC2540 BT 4.0 chip with the Arduino UNO development board. It allows wireless programming via BLE, supports Bluetooth HID, AT command to config BLE and you can upgrade BLE firmware easily. Bluno is also compatible with all Arduino Uno pins which means any project made with Uno can directly go wireless!

Step 4: Test the Motor

Picture of Test the Motor

First, let's try to run the motor. I find a nice driver from DFRobot that is compatible with the Arduino Bluno. In the Wiki, there's a sample code for the stepper motor. Upload to the board. You can see the motor is running.

You can change the direction and speed by setting the time delay and direction pin.

/*<br>This sample code is for testing the 2 stepper motors 
The rotation velocity can be adjusted by the code switch 
Microcontroller: Arduino UNO  
*/
int M1dirpin = 7;  //Motor X direction pin
int M1steppin = 6; //Motor X step pin
int M1en=8;  //Motor X enable pin
int M2dirpin = 4;  //Motor Y direction pin
int M2steppin = 5; //Motor Y step pin
int M2en=12;  //Motor Y enable pin

void setup()
{
  pinMode(M1dirpin,OUTPUT);
  pinMode(M1steppin,OUTPUT);
  pinMode(M1en,OUTPUT);
  pinMode(M2dirpin,OUTPUT);
  pinMode(M2steppin,OUTPUT);
  pinMode(M2en,OUTPUT);
  
  digitalWrite(M1en,LOW);// Low Level Enable
  digitalWrite(M2en,LOW);// Low Level Enable
  
}
void loop()
{
    int j;
  delayMicroseconds(2);
  digitalWrite(M1dirpin,LOW);
  digitalWrite(M2dirpin,LOW);
  for(j=0;j<=5000;j++){
    digitalWrite(M1steppin,LOW);
    digitalWrite(M2steppin,LOW);
    delayMicroseconds(2);
    digitalWrite(M1steppin,HIGH); //Rising step
    digitalWrite(M2steppin,HIGH);
    delay(1);
  }
}

Step 5: Test the GoBLE

Picture of Test the GoBLE

Now, let's try to use 'GoBLE' to control the speed of the motor. In the GoBLE Wiki, download the library first. The testing code named GoBLE_Test.ino can be found in the software package. It enables you to check the signal from your iPhone on PC. Have a try!

In the picture we can see the data received from the app. Then we can try to control the speed of the motor!

Step 6: Control the Stepper Motor

Picture of Control the Stepper Motor

Here's the code:

#include 
#include "GoBLE.h"
int joystickX;
int M1dirpin = 4;   
int M1steppin = 5; 
int M1en=12;        
bool motorEnableFlag;
  
Metro blink1Metro = Metro(1000);   
Metro blink2Metro = Metro(0);    
void setup() {
  // put your setup code here, to run once:
  pinMode(M1dirpin,OUTPUT);
  pinMode(M1steppin,OUTPUT);
  pinMode(M1en,OUTPUT);
  Goble.begin();
  Serial.begin(115200);
}
void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(joystickX);
   if(Goble.available())
    {
      joystickX = Goble.readJoystickX();
      if (joystickX > 128)
       {
        digitalWrite(M1dirpin,LOW);
        joystickX=255-joystickX;
       }
       else if (joystickX<128)
        {
          digitalWrite(M1dirpin,HIGH);
          joystickX=joystickX-1;
          }
          if (joystickX==128)
          motorEnableFlag=false;
          else
          motorEnableFlag=true;
 
    }
Metro blink2Metro = Metro(joystickX/50);     
if(blink1Metro.check()){
 Serial.println(joystickX);
  }  
    if(blink2Metro.check()&&motorEnableFlag){  
    digitalWrite(M1steppin,LOW);
   digitalWrite(M1steppin,HIGH);  

 }  
}

I do this in a multi-threaded way. One for receiving app data, one for sending digital to motor.

Step 7: To Be Continued!

Next time I will use 2 motors to make a car.

Thank you for watching this post!

Comments

About This Instructable

1,054views

19favorites

Bio: Green hand in arduino
More by 375668457:Azure API: Face Detection+RecognitionProcessing: Interactive Project on a super small computerCommuncation: LattePanda⇌Leonardo
Add instructable to: