Arduino and Visual Basic Part 3: Controlling an Arduino

I am still very new to Visual Basic and I have been surprised at how quickly you can develop working apps. My first attempt resulted in a very basic app to receive data from the Arduino which taught me the basics of serial communication in VB. The next step is two way communication and controlling the Arduino from the VB program. I already have a similar project arduinoBTcontrol, where the Arduino is controlled from an Android app over Bluetooth. So all I need do is tweek the Arduino sketch and recreate the Android app in VB.

Continue reading

Arduino and Visual Basic Part 2: Receiving Data From the Arduino

This post continues from Arduino and Visual Basic Part 1: Receiving Data From the Arduino

In the previous post we received a stream of data from the Arduino and displayed it inside a Visual Basic text box. This is all well and good but we did not know what the data was, we simply received it and displayed it.

The next step is to send data that has some kind of meaning and display it in an appropriate field. This could be a temperature, a wind speed, a switch state or anything else. In the following example I am using a 1 wire temperature probe (it’s actually got 2 wires…), a potentiometer and a button switch.

Continue reading

Arduino and Visual Basic Part 1: Receiving Data From the Arduino

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.

Continue reading


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.

arduinoBTcontrol - breadboard

The Android app was created in app inventor and the aia file can be downloaded at the bottom of the page.

Continue reading

Arduino & ESP8266 Webserver

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.

ESP8266 webpage

Enter your name and hit submit

ESP8266 webpage 2

Continue reading

FTDI + ESP8266

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 [ Version:] 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.

Continue reading

Connecting 2 Arduinos by Bluetooth using a HC-05 and a HC-06: Pair, Bind, and Link

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

Continue reading

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


Continue reading

Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE

Updated 19.07.2015
Updated 26.07.2015
Updated 30.10.2015

Update 2016-08-01
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.

HC-05 zs-040

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.

Method 1.
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.

Method 2.
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.

Method 3.*
Enters “mini” AT mode using the user defined communication mode baud rate.

Method 4.*
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.

Continue reading

Arduino With HC-05 Bluetooth Module in Slave Mode

Arduino and HC-05 in communication mode

Updated on 18.07.2015.

Updated 01.12.2016
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.

HC-05 zs-040

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).

Continue reading

Turning a LED on and off with an Arduino, Bluetooth and Android. Part II: 2 way control

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.

Arduino-AI2-Bluetooth_1LED_01In 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.

Continue reading