Web
Analytics
 
 

Getting started with the HM-10: Easy Arduino Bluetooth integration for iOS and Android!


Back in the day, before BLE 4.0, finding a Bluetooth solution to control your Arduino projects that was...


1. Free

2. Available for iOS and Android

3. Feature Rich

4. Stable with 20+ robots running around


...was tricky to find! That is, until recently. Thanks to recent updates in BLE hardware, and smartphone-based software, getting started using Bluetooth for your Arduino projects has never been easier. In this getting started guide I'll walk you through all of the steps you'll need to get you started controlling your Arduino projects with Bluetooth using the app "dabble". Then we'll look at how to take our Bluetooth data and put it to work by programming the ACBR Rover robot with the dabble Gamepad module. If you'd like to watch the process in its entirety we've got a video tutorial available here:





Part One: The Materials!

Now in order to get started controlling your Arduino projects wirelessly, you'll need a few things.


1. HM-10 (or AT-09, CC2540 they both work just fine as well)

2. Arduino (this tutorial will work for any board in the Arduino family)

3. Jumper Wires


Part Two: The Wiring!

So the HM-10 has 6 pins, but for this tutorial, we're going to focus on the middle four pins, as those are the only pins we'll need to get our Arduino talking to our Smartphone.



Our wiring, in terms of getting the HM-10 connected to our Arduino, is really straight forward. Here it is as a simple wiring diagram.




Wiring:

VCC --> 5V

GND --> GND

TXD --> D2

RXD --> D3




In the video, I wired the two up using two mini breadboards, but it really doesn't matter how you choose to connect the wires.


If you have one of our ACBR Rover Robotics kits, you can wire it in straight to your bot, like this!



Once we have the HM-10 Connected to our Arduino, it's time to take a look at the Dabble Library! In order to get the example I have written working, you'll need to download the library file, and follow all of my steps here!


Part Three: The Example Code!

Step One: Head to the following link https://github.com/STEMpedia/Dabble

Step Two: Once you have the GitHub page for the dabble library open, hit the "Clone or download" button, and select "Download Zip"


Step Three: Open up the Arduino IDE and click on the "Sketch" Tab, then select "Include Library" and finally "Add .ZIP Library". Then, all you'll need to do is select the library Zip file you downloaded in step two, and you're all set!


Once you have the library file installed, copy the "Rover Dabble Example Basic" example sketch here, and paste it in a new code window.


/*  Hey guys! So the wiring here is really easy.  Your bluetooth module 
    wiring is as follows: Vcc goes to 5v, GND goes to GND, Tx goes to 
    D2, and RX goes to D3. 
*/

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <Dabble.h>
int enR = 3;   //These are the pins for our motor driver IC
int inAR = 4;
int inBR = 5;
int enL = 6;
int inAL = 7;
int inBL = 8;

void setup() 
{
  pinMode(enR, OUTPUT);
  pinMode(inAR, OUTPUT); 
  pinMode(inBR, OUTPUT);
  pinMode(enL, OUTPUT);
  pinMode(inAL, OUTPUT); 
  pinMode(inBL, OUTPUT);
  Serial.begin(250000);    // Set your Serial Monitor is set at 250000
  Dabble.begin(9600);      // This is the baude rate of the HM-10
}

void loop() {
Dabble.processInput();  // This line is crucial in grabbing our data  
  
  if (GamePad.isUpPressed())       
  {
    Serial.println("Forward");
    analogWrite(enR, 255);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, HIGH);
    analogWrite(enL, 255);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, HIGH);
  }

  else if (GamePad.isDownPressed())
  {
    Serial.println("Backward");
    analogWrite(enR, 255);
    digitalWrite(inAR, HIGH);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 255);
    digitalWrite(inAL, HIGH);
    digitalWrite(inBL, LOW);
  }

  else if (GamePad.isLeftPressed())
  {
    Serial.println("Left");
    analogWrite(enR, 255);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, HIGH);
    analogWrite(enL, 255);
    digitalWrite(inAL, HIGH);
    digitalWrite(inBL, LOW);
  }

  else if (GamePad.isRightPressed())
  {
    Serial.println("Right");
    analogWrite(enR, 255);
    digitalWrite(inAR, HIGH);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 255);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, HIGH);
  }
  else 
  {
    Serial.println("Stopped");
    analogWrite(enR, 0);
    digitalWrite(inAR, LOW);
    digitalWrite(inBR, LOW);
    analogWrite(enL, 0);
    digitalWrite(inAL, LOW);
    digitalWrite(inBL, LOW);
  }
}

Once you have the code all set, you'll want to plug in your Arduino, and upload your code! We haven't paired our HM-10 to our phone yet, so we'll come back to our code here in a second.


Part Four: The Dabble App

Now that we have our HM-10 wired up, if we have our Arduino plugged into our computer, we should see a blinking light on the HM-10, this means we have power, but we're waiting for a connection. If you don't see any lights, check your wiring. If you see the light, then you're ready to download the Dabble app! Head to the app store on your iPhone or Android, and download the Dabble app.


Once you have the app open, your screen should look just like this! One thing I noticed when running this app on an iPhone, is that many of the features found on the Android App are not available. Now, I'm fairly confident this does not mean they are paid features but are simply still being developed for iOS. We're going to be using the Gamepad module, which is available on both platforms, so there shouldn't be an issue. To connect to your HM-10, you'll want to tap on the "electrical plug" looking icon and select your module, it will more than likely be labeled "BT05". Tap on the device you want to connect and you're all set!


Next, select the "Gamepad" module, and you should see a screen just like this. (Some really cool extra features can be found by tapping the icon that looks like two small boxes, but we won't cover that here)


Alright! Now that we have a connection, it's time to head back over to the Arduino IDE, and open up our Serial Monitor! Make sure you still have the code from our previous step open, and your Arduino plugged in and connected. To open the Serial Monitor you'll want to click on the small magnifying glass icon in the upper right-hand corner of the screen.

If everything went as planned, as you press the up, down, left, and right buttons, you should see the corresponding text appear on the screen! Now if you have the wired up to on of our ACBR Rover Robots, then you can start driving right away! If you have a different robot you'll want to swap out our motor driver code inside of our conditional statements and replace it with yours.



We hope you enjoyed this tutorial! There are other apps that are compatible with Arduino, and there are also dozens of other fun projects you can create using Bluetooth and Arduino, so keep hacking! The example code we have here is really basic and meant to get you started. I'd highly suggest adding in commands for the other buttons, there are all kinds of crazy stuff you can do. If you have any questions check out our video, or feel free to comment on this tutorial! Good luck, and remember... anyone can build robots!




2,895 views0 comments

Recent Posts

See All