element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs MIT AppInventor, HC06 and Arduino: much improved method of sending data via Bluetooth - Part 1, The Arduino Side
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: neilk
  • Date Created: 14 Feb 2018 12:10 PM Date Created
  • Views 786 views
  • Likes 7 likes
  • Comments 2 comments
  • arduino uno
  • mit_app_inventor
  • blue tooth
  • arduino_tutorials
  • hc-06
Related
Recommended

MIT AppInventor, HC06 and Arduino: much improved method of sending data via Bluetooth - Part 1, The Arduino Side

neilk
neilk
14 Feb 2018

My early Blogs about moving data between Arduino and Android apps developed using MIT AppInventor were posted back in 2014. Since then I've learned a little more about some of the features of AppInventor and also how to use Arduino SoftwareSerial.

 

Connecting the Arduino UNO to the HC06 Bluetooth Adapter

 

My 2014 Blogs had the HC06 TXD and RXD connections "piggy-backed" onto the hardware UART of the UNO - pins RXD/D0 and TXD/D1.

 

Note that the signal to the RXD input of the HC06 must be restricted to around 3.3v; the 5v TXD/D1 line from the UNO is connected via a simple potential divider to the RXD input of the HC06.

 

At the time I first worked on this, there was some advice around to suggest that piggy-backing would not work. However, it  worked OK for me and also for other people!

 

image

 

 

Or you can use a breadboard:

image

 

(Author's note - I've also learned a bit of fritzing since 2014/15!)

(Thanks to http://forum.fritzing.org/t/bluetooth-hc-06/2487 for the HC06 fritzing image - I had to import it)

 

When I returned to using a HC06 recently, I found that I couldn't upload sketches whilst the HC06 was piggy-backed onto the UNO UART. I put this down to the enormous changes that have taken place in the Arduino IDE since 2014 - I am just speculating.

 

Since I don't (yet) own an Arduino Mega, with its luxurious 4 hardware UARTs, I had no option but to move on to using Software Serial on the UNO.  I've chosen to use pin D3/RXD and pin D4/TXD:

image

 

Of course, the above schematic is somewhat idealised. In reality I am using a mini-breadboard stuck to a proto-shield, which then plugs into the Uno, something like this:

 

image

 

 

 

 

 

 

 

The HC06 is actually plugged vertically into the breadboard, rather than lying on its side as this schematic suggests.

 

Unfortunately, I can't find a fritzing image which accurately depicts my proto-shield, so this schematic looks as thought the mini-breadboard is stuck to the top of the Uno.

 

 

 

 

 

 

 

 

And the final reveal:

image

 

 

 

 

 

 

 

As can be seen, the proto-shield (a pre-R3 arduino shield) also carries a reset button and 2 LEDs.

 

 

 

 

 

 

 

 

 

 

Developing the Software - Arduino

 

Here is a very simple sketch to send data from the keyboard to the HC06. The data items are echoed to the serial monitor and also sent to the HC06 by SoftwareSerial. Note that an HC06 is delivered set to 9600 baud, although you can configure it for higher or lower baud rates

 

#include 
#define rxPin 3                          // define SoftwareSerial rx data pin
#define txPin 4                          // define SoftwareSerial tx data pin
SoftwareSerial blueTooth(rxPin, txPin);  // create instance of SoftwareSerial


void setup()
{
  Serial.begin(9600);                   // Start hardware Serial
  blueTooth.begin(9600);                // Start SoftwareSerial
}
void loop()
{
    char c;
     if (Serial.available())
     {
       c = Serial.read();
       Serial.print(c);                 // Write the character to the Serial Monitor
       blueTooth.write (c);             // Write the character to Bluetooth
     }
}

 

I always like to check my work as I go along - go too far down the track and debugging can become tortuous! The objective here is for the Arduino to transmit data, via the HC06, to an App running on an Android device - the App to be developed in AppInventor. Before we get into developing the App, let's establish that the Arduino and the HC06 are happily working together and the sketch is doing what we want.

 

You can do this quite easily with a terminal emulator, like Tera Term, provided your PC has Bluetooth. I have done this on Windows 7 and Windows 8; unfortunately my Windows 10 PC doesn't have Bluetooth.

 

However, since the target is an Android device, 'phone or tablet, it's very easy to use an App called Blue Term, which is free to download from Google Play.

 

The setup process is as follows:

  1. Make sure the Arduino and HC06 are powered up - LED on HC06 should be flashing.
  2. Pair the HC06 to your phone - the default pairing code is 1234.
  3. Start the Blue Term App.
  4. In the top right hand corner it shows not connected.
  5. In the bottom right hand corner, press the 3 dots symbol and click Connect Device.
  6. Blue Term will scan and give you a list of all the paired devices - there may only be one!
  7. Click on HC-06
  8. The top right hand corner will show connecting and then connected-HC-06. The HC06 LED will stop flashing.
  9. In the Arduino IDE, open the Serial Monitor, setting the terminator to both NL and CR.
  10. Type a test string on the PC keyboard and then press Return.
  11. The string should appear in the Blue Term window on the Android device. (if the text is difficult to read, press the 3 dot symbol again, select preferences and then Font Size - the largest seems to 20pt, which is still quite small!
  12. If it doesn't work then start checking connections TXD and RXD, the potential divider, the resistor values, the Arduino Sketch etc etc.

 

It is pointless to move on to developing the Android App until the Arduino/HC06/Arduino Sketch is working!

 

_________________________________________________________________________

EDITED ON 23 May 2018 - I've just noticed that line 1 of the sketch has been corrupted! It should read:

 

#include <SoftwareSerial.h>

 

Apologies for that

 

 

  • Sign in to reply

Top Comments

  • genebren
    genebren over 5 years ago +1
    Interesting project. Do you have any specific plans for what you would like to do with this project? Or is this more of a learning exercise? Thank you for sharing your project, maybe some day I will get…
  • neilk
    neilk over 5 years ago in reply to genebren

    Thanks, Gene. The project I am working on is a Cadence monitor for my exercise bike. to show Actual and Average Cadence during exercise. The unit on the bike only shows Actual Cadence during exercise and then gives you the Average Cadence when you terminate the session.

     

    So, I have it almost working, but realised during the development that my earlier blog posts about basic Bluetooth comms between Arduino and AppInventor Apps weren't as good as they could have been - the benefit of continued learning - and that there were some better techniques available in AppInventor which would make the App much more reliable.

     

    The next blog post will show the development of a simple App, using AppInventor, to receive and display the data, beginning to use some of those better techniques.

     

    I then hope to go on and show how the AppInventor App and the Arduino Sketch can be developed to allow bi-directional communications. My Cadence project has this already, allowing the App to send a reset to the Arduino to restart the Average Cadence calculation.

     

    The Arduino is a great platform and a UNO can be had very cheaply - even the clones are pretty reliable.

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 5 years ago

    Interesting project.  Do you have any specific plans for what you would like to do with this project?  Or is this more of a learning exercise? Thank you for sharing your project, maybe some day I will get the bug and try an Arduino project.

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube