by FlyingDrMike
This is incredibly useful if you want to test your sketch in a real world environment, away from your PC. The
outcome is that your smartphone acts the same as the Arduino serial monitor on your PC. The HC-05 and HC-06
Bluetooth modules are available for around 3 on ebay and there are many free smartphone apps to choose from.
There are a few pitfalls that you will hopefully avoid by following the examples here. The free smartphone app
used here can also save the text received to a file for later use. There is no change required to your sketches as
the same serial pins are used.
I first used this when testing a device that measures the distance cars give when overtaking me on my bicycle. I
was able to record distance measurements taken 30 times a second onto my phone where they were saved into a
file. I analysed this later with video that I also recorded using a sports cam and my tracking app that gave my
speed and location.
Steps:
There are many Bluetooth apps available and many Now start BlueTerm 2. Click settings, then click
are free. I use Android phones but I expect the same Connect device and select as required. You can just
is the case for the other systems. I decided to use power up a HC-05/HC-06 module at this stage and
BlueTerm 2 as it also provides the option to log the check the pairing process if you wish (attach negative
data received to file. I also found it very supply to ground and 5v to Vcc).
straightforward to use. So go to Google Play and
request download of BlueTerm 2.
If you hare happy to use the default name and baud rate you can skip this step. The defaults are name: HC-05 or
HC-06 and baud: 9600. The benefit of re-configuring the module is that faster baud rates can be selected and the
name can be set to something more easily recognised.
The sketch to disable the Arduino serial simply has the instructions:
pinMode(0,INPUT):
pinMode(1,INPUT);
I have attached the sketch NoSerial.ino. Create a folder called NoSerial in your sketches folder and add
NoSerial.ino to this. Start the Arduino IDE, navigate to File>Sketchbook>sketches>NoSerial to open the sketch.
Select the board type and Port from the Tools menu and click the download button.
With sketch loaded we can now connect the Bluetooth module to the Arduino board. The Tx and Rx connections
are swapped compared to what we will do later as we want to communicate with the PC port for the Serial Monitor
and not the Arduino main processor. The PC Tx is connected to the Arduino Rx and vice versa.
Note that the Bluetooth modules have 3.3v levels for Tx and Rx. Hence a voltage divider should be used for the
Bluetooth Rx input when connecting to 5v systems. The Bluetooth 3.3v Tx output is usually detected fine by 5v
systems and hence can be connected directly.
I have found that a voltage divider using 3k3 and 6k8 resistors works up to 115200 serial baud rates.
The HC05 and HC06 modules have on-board voltage regulators and hence run with Vcc connected to 5v.
So connect :
3k3 resistor to D0
6k8 resistor to ground
Connect the other ends of the two resistors together, and to the Rx pin on the Bluetooth module
Connect the Bluetooth module Tx pin to D1
Connect the Bluetooth module ground pin to GND Connect the Bluetooth module ground pin to
GND
Connect the Bluetooth module Vcc pin to 5v
HC-06
These are the easiest. They set themselves into AT mode if they are not paired with any device. However the baud
setting will be whatever the normal operating baud has been set to. This is normally 9600 when supplied. If this
does not work try 38400 or the other common rates.
Connect the USB lead from PC to Arduino and start the Arduino IDE. The Bluetooth LED will flash rapidly (~4Hz)
when in AT mode.
Open the Arduino Serial monitor via Tools>Serial Monitor. Set the baud to 9600 and set No line ending.
Now enter AT and click Send. If all is working you will see OK returned to the monitor. If nothing comes back
double check the wiring and try different Baud settings.
With an OK confirming good communications we can change the name and set out own Baud rate.
Enter AT+NAMEARDUINO and click send. This sets the module name to ARDUINO. Any other text can be used.
Note no spaces in the command.
The reply should be OKsetname. This gets added to the OK sent earlier
The reply should be OK115200. If any more AT commands are to be sent the Serial Monitor baud setting must be
changed to 115200.
Other rates can be set. Baud4 is 9600, Baud5 is 19200, Baud6 38400, Baud7 57600. There are higher settings
than 115200 but check first that your PC and Arduino can accept them (mine cannot exceed 128000). Note - If you
set a rate that is too high you will not be able to communicate with it to set it back!!!
Download (https://cdn.instructables.com/ORIG/F2L/YPNP/J6WGONOY/F2LYPNPJ6WGONOY.ino)
http://www.instructables.com/ORIG/F2L/YPNP/J6WGONOY/F2LYPNPJ6WGONOY.ino
(https://cdn.instructables.com/ORIG/F2L/YPNP/J6WGONOY/F2LYPNPJ6WGONOY.ino)
Open the Arduino Serial monitor via Tools>Serial Now set a new name. Enter AT+NAME=ARDUINO
Monitor. Set the baud to 38400 and set Carriage The reply should be OK. However in my case the
Return. module reset out of AT mode (LED flashing quickly). I
could not find the cause and this also happened when
The next step is the get the board into AT mode. This using a FDTI serial connection rather than the
is where most problems arise because of differences Arduino. I got back into AT mode as before:
in the carrier boards. Disconnecting the power wire to the board and
reconnecting while the button was pressed. Later
The fundamental process is to hold the Key pin (pin checks showed that the name had been changed.
34) low a few seconds on power-up.
Next set the Baud. Enter AT+UART=115200,1,0 The
My board has a button to do this (the two additional reply should be OK. However it did sometimes jump
connection pins are EN and STATE). Disconnect the out of AT mode as above.
Vcc wire from the Bluetooth module. Then, while
holding the button pressed, reapply 5v to Vcc. The The UART setting can be checked with the
LED should flash at approximately 2 second intervals. command: AT+UART? The reply should be OK and
I hold the button until the second flash. +UART=115200,1,0
Some boards have a Key pin as one of the 6 pins to Initial test
the module. If so tie this to 3.3v during powering up.
(https://cdn.instructables.com/ORIG/FOF/VXDS/J6WGONQI/FOFVXDSJ6WGONQI.pdf)
We need to load our Arduino test sketch first. The attached BTtest.ino sends a number every 0.5s and then
increments it, rolling over to 0 from 255. Create a folder called BTtest in your sketches folder and add BTtest.ino
The Arduino serial connection is also used for downloading sketches. So the two wires to the Bluetooth module
must be disconnected so that it does not interfere.
After downloading the sketch reconnect the Bluetooth module. Note however that the Tx and Rx on the Arduino
need to be swapped compared to the earlier configuration setup.
3k3 resistor to D1
6k8 resistor to ground
Connect the other ends of the two resistors together, and to the Rx pin on the Bluetooth module
Connect the Bluetooth module Tx pin to D0
Connect the Bluetooth module ground pin to GND Connect the Bluetooth module ground pin to
GND
Connect the Bluetooth module Vcc pin to 5v
Pair the board to the smartphone if not already connected (see Install Bluetooth app above). Then start BlueTerm
2, click settings, then click Connect device and select ARDUINO. You should see the screen fill with numbers
incrementing from 0 to 255.
Mike
Download (https://cdn.instructables.com/ORIG/F3J/F31O/J6WGONPV/F3JF31OJ6WGONPV.ino)
http://www.instructables.com/ORIG/F3J/F31O/J6WGONPV/F3JF31OJ6WGONPV.ino
(https://cdn.instructables.com/ORIG/F3J/F31O/J6WGONPV/F3JF31OJ6WGONPV.ino)