After creating the dropControllerBT app and realizing how much easier controlling the dropController device is through the app I started to think about creating a PC app. I haven’t done any PC programming for many years and so I looked at what various options are currently available. Visual Basic kept being recommended for ease of use and quick development. Visual Basic comes as part of Microsoft’s Visual Studio Suite and I initially download and played with Visual Studio Express which in turn lead to Visual Studio Community. Both are free for personal use.
Just had a problem with the sites database and had to restore from a backup. Lost some data and some comments.
Updated on 06.08.2016
Controlling an Arduino over Bluetooth from Android using App Inventor 2
Here is an example of controlling the Arduino over Bluetooth using a HC-06 bluetooth module and an Android app. The example uses an Arduino Nano but other Arduinos will work just as well. A HC-05 module can be used stead of the HC-06.
The Android app was created in app inventor and the aia file can be downloaded at the bottom of the page.
Update: This is a very old guide and there are much better examples available. If I were to to this again I would use one of the ESP8266 libraries that simplify the whole process. Libraries are available from the following links:
WiFi (ESP8266WiFi library)
Here is my first attempt at a web server using the ESP8266. It includes a request count and also a text input field.
Enter your name and hit submit
Just started to play with the ESP8266-01 modules. Purchased from Taobao.
These, I believe, are version 2 and have the LEDs near the antenna. When first started they identify themselves as [Vendor:www.ai-thinker.com Version:0.9.2.4] and are version 018000902-AI03. This is a custom firmware from ai-thinker.
There seems to be quite a few different versions of similar modules. And the same module could have one of several firmwares.
In a previous post I showed how the HC-05 can auto connect to other Bluetooth devices by setting the HC-05 to pair with any device using CMODE=1. This is quick and easy but does not give any control over which other device the HC-05 connects to.
In this post I show how to set up the HC-05 to always connect to the same HC-06. For this we use PAIR, BIND, and LINK.
I am using 2 separate Arduino IDEs; version 1.6.3 which is installed, and version 1.0.5 which I run from a folder (it is the non install version). This allows me to use 2 IDEs at the same time, each connected to a different Arduino. It also gives me 2 serial monitors, one for each Arduino.
The modules used are the zs-040 versions of the HC-05 and the HC-06.
The HC-05 has 2 AT modes which I refer to as “mini” AT mode and “full” AT mode and some commands only work when in “full” AT mode. To enter “full” AT mode pin 34 needs to be HIGH and kept HIGH. To accomplish this I have made a connection from pin 34 to +3.3v. See the diagram below (or after the jump).
If you are not sure about the different AT modes take a look at Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE
If you are not familiar with how the HC-06 and HC-05 work it may be worth while checking out some of the other posts:
HC-05 and HC-06 zs-040 Bluetooth modules
Arduino and HC-06 (ZS-040)
Arduino With HC-05 Bluetooth Module in Slave Mode
Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Easy Method Using CMODE
Making a connection Between a HC-05 and a HC-06: Method 1
Using the CMODE command we have an easy way to connect the HC-05 and the HC-06. When the HC-O5 is configured to pair with any address (AT+CMODE=1) it should connect to a HC-06 automatically. No binding etc is required.
I am using the zs-040 modules and other modules should be the same. If you have issues check the data sheet for your modules.
The Set Up
I am using 2 different Arduino IDEs; version 1.0.5 and version 1.6.3 but this not required. You can run 2 instances of the same IDE which then allows yo to have 2 serial monitor open at the same time.
The Arduino connected to the HC-05 is on COM8 and the Arduino using the HC-06 is on COM17
The zs-040 breakout boards are now being used for many different modules and you may not have the exact same boards as those shown below. Recently I received some new zs-040 HC06s and HC-05s that have a slightly different daughter board and a very different firmware. On the new HC-05s pin34 has to be pulled HIGH before connecting power to enter AT mode. Bringing pin 34 HIGH after powering the modules has no effect.
AT mode allows you to interrogate the BT module and to change some of the settings; things like the name, the baud rate, whether or not it operates in slave mode or master mode. When used as a master device AT commands allow you to connect to other Bluetooth slave devices.
There are many slightly different HC-05 modules, the modules I have are marked ZS-040 and have an EN pin rather than a KEY pin. They also have a small button switch just above the EN pin. They are based on the EGBT-045MS Bluetooth module.
Update: I now also have boards marked fc-114. See:
HC-05 FC-114 and HC-06 FC-114. First Look
HC-05 FC-114 and HC-06 FC-114. Part 2 – Basic AT commands
HC-05 FC-114 and HC-06 FC-114. Part 3 – Master Mode and Auto Connect
On the zs-040 modules there are 2 AT modes. I do not know if this is intentional but some commands only work when pin34 is HIGH. Other commands work when pin 34 is either HIGH or LOW. This fooled me for quite a while. For this post I have called the different modes “mini” AT mode and “full” AT mode.
To activate AT mode on the HC-05 zs-040 modules we can:
– 1. Hold the small button switch closed while powering on the module.
– 2. Set pin 34 HIGH (3.3v) when power on.
– 3. Close the small push button switch after the HC-05 is powered.
– 4. Pull pin 34 HIGH after powering the HC-05.
Enters AT mode with the built in AT mode baud rate of 38400. The baud rate cannot be changed by the user.
This method allows the module to enter AT mode on start but but does not keep pin 34 HIGH and uses the “mini” AT mode.
Enters AT mode with the built in AT mode baud rate of 38400. The baud rate cannot be changed by the user.
If you keep pin 34 HIGH you will enable the “full” AT mode which allows all AT commands to be used.
If you let pin 34 return LOW after power on then “mini” AT mode will be enabled.
Enters “mini” AT mode using the user defined communication mode baud rate.
Enters “full” AT mode using the user defined communication mode baud rate.
If pin 34 is kept HIGH then the HC-05 enters the “full” AT mode. If pin 34 is brought HIGH and returned to LOW it will put the module in to “mini” AT mode.
* added 21.07.2015
Method 1 and 2 are good in that you know the baud rate – it will always be 38400. This could be useful if you have modules other people have used or if you forget what communication mode baud rate you have previously set.
Method 3 and 4 adds convenience. You can enter AT mode, make changes and return back to communication mode without switching sketches and messing around with different baud rates.
Arduino and HC-05 in communication mode
Updated on 18.07.2015.
There are now newer HC-06s and HC-05s that use the zs-040 breakout boards. These new modules have a LED (usually blue) at the top left of the Bluetooth daughter board and have a different firmware to the below. See HC-06 hc01.comV2.0 for an introduction to the HC-06. I haven’t written up details on the HC-05 yet.
Here is the zs-040 version of the popular HC-05. The HC-05 is based on the EGBT-045MS Bluetooth module. It can operate as either a slave device or a master device. As a slave it can only accept connections. As a master it can initiate a connection.
The EGBT-045MS Bluetooth modules (the smaller daughter board) is a 3.3v device. The HC-05 break out board has a 3.3v regulator that allows an input voltage of 3.6v to 6v but the TX and RX pins are still 3.3v. This means you can use the 5V out from the Arduino to power the boards but you cannot connect the Arduino directly to the HC-05 RX pin.
For the HC-05 RX pin (data in) we need to convert the Arduinos 5V to 3.3v. A simple way to do this is by using a voltage divider made from a couple of resistors. In my case I use a 1K ohm resistor and a 2K ohm resistor.
As a quick guide to the voltage divider; 1K + 2K = 3K. 1K is a third of 3K so it reduces the voltage by a third.
One third of 5V is 1.66 and 5-1.66 = 3.33 which is what we want. Putting the resistors the other way would reduce the voltage by 2 thirds.
For more information on voltage dividers have a look at the Sparkfun tutorial
Since the Arduino will accept 3.3 volts as HIGH you can connect the HC-05 TX pin (data out) directly to the Arduino RX pin (The 5V Arduino takes a voltage of 3V or more as HIGH).
This post follows on from Turning a LED on and off with an Arduino, Bluetooth and Android. Part II
Now that we have two way communication working let’s add a couple more LEDs and two more switches.
In the first part I showed how to control a single LED from an app created in App Inventor. This worked OK but was very limited. You could control only 1 LED and the control was one way; from the app to the Arduino. What if you want to have 2 way control of the LED and to be able to also control the LED from the Arduino side? What if you want to control more than 1 LED?
In this guide we look at adding two-way communication. Here we control an LED but you could have it doing anything.
In first example you could only control the LED from the Android app, here we extend the example so that we can also control the LED at the Arduino side. When the LED is turned on or off by the Arduino we want the button in the app to update to show the correct LED status.
The first example used methods only suitable for controlling one LED, this time we will try to make it so the Arduino sketch and also the AI2 app can be easily scaled and so once you have the basic app in place adding extra buttons and controls should be fairly straight forward.
Although I use a HC-06 in the below examples the HC-05 in slave mode can also be used.
Using MITs app inventor it is fairly easy to create an app that can turn a LED on and off from an Android device.
This is a fairly simply example of sending commands to the Arduino to turn a LED either on or off. The Android app sends ascii codes to the Arduino via the HC-06 BT module; “ON” for on and “OF” for off.
Load the app, connect to the HC-06 and then use the LED button to turn the LED on and off.
The HC-06 is a slave only BT module that is fairly easy to use with the Arduino using serial communication. Once it is connected it simply relays what it receives by bluetooth to the Arduino and whatever it receives from the Arduino it sends to the connected device. There are several slightly different versions of the HC-06, however, all seem to use the same firmware and have the same AT commands. The ones I have are labelled as zs-040. I also have some HC-05s which share the same PCB and are also labelled as zs-040.
The HC-06 defaults to AT mode at power on. This is indicated by a rapidly flashing LED. After the HC-06 is connected to another device the LED stops flashing and is constant on.
Update: If you have modules that have a blue LED in the top left hand corner then you have a newer model with a slightly different firmware although they should operate the same.
I recently bought some HC05s and HC-06 Bluetooth modules. These are pretty standard, especially when using with the Arduino and I was surprised at how easy it was to get basic serial communication working. There are several slightly different modules available. The ones I have are marked zs-040. The zs-040 boards differ from some of the other modules in that they have a EN pin rather than a KEY pin.