This post is part I of a III part series of posts related to Arduino and Raspberry PI Wireless Bluetooth communications.
- Part II
- Part III (coming soon)
For a project I’m working on, I was searching for a method of sharing information between the Arduino and a Raspberry PI and Bluetooth came to mind. So, I start exploring.
Here’s a small example of a Wireless connection between Arduino and an Android Phone using Bluetooth.
Hardware
1x Arduino (I’m using UNO but any other will work)
1x Android phone with BlueTerm app installed
1x HC-05 or HC-06 bluetooth sensor

Connections
The connections are straight forward. Bare in mind that, we need to switch the RX and TX. It doesn’t matter which is which in the Arduino PINs, as long as we switch them in the code.
HC-05 or HC-06 | Arduino PIN |
VCC | VCC 5v |
GND | GND |
RX | 6 (will be the TX in the code) |
TX | 5 ( will be the RX in the code) |

Code
To program a bluetooth sensor with the Arduino is nothing more than use a serial connection where we send and receive commands. The bluetooth sensor will take care of sending and receiving the data, forwarding it to the serial connection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
//This sketch shows how to connect to a bluetooth device // Arduino -> bluetooth // Used with Android BlueTerm app #include <SoftwareSerial.h> //Serial library /** * Arduino connection HC-05 connection: * HC-05 | Arduino * TX | 5 * RX | 6 */ // Here, we exchange them - SoftwareSerial bt (5,6); //RX, TX (Switched on the Bluetooth - RX -> TX | TX -> RX) int LEDPin = 13; //LED PIN on Arduino int btdata; // the data given from the computer void setup() { bt.begin(9600); //Open the serial port bt.println ("Bluetooth ON. Press 1 or 0 to blink LED.."); //write to serial pinMode (LEDPin, OUTPUT); } void loop() { if (bt.available()) { //if serial is available btdata = bt.read(); //read from the serial connection if (btdata == '1') { //if 1 digitalWrite (LEDPin, HIGH); //if we get 1, turn on the LED bt.println ("LED ON!"); } if (btdata == '0') { //if we received 0, turn off the led //if 0 digitalWrite (LEDPin, LOW); bt.println ("LED OFF!"); } } delay (100); //prepare for data } |
Upload the code to the Arduino.
After uploading/connecting the Arduino, the LED on the Bluetooth Module will be blinking fast. After pairing with the phone, the LED will blink slowly.
On the Android phone, please install the BlueTerm application. This application will allow serial communication using the Bluetooth.
Now, turn on the bluetooth and pair with the module. Either is the HC-05 or HC-06 modules, the code will be 1234.
Open the application and connect to the paired device.
Once paired, start sending 0s or 1s to see the LED turning on or off.





More information
what do i have to do to pass the blue screen on blueterm? i tried to keep it close to HC-05/arduino, but nothing happens! – do i need to type something? pl help.
Hi Sunil V !
Have you paired the device with your mobile phone ? Enable local echo (in blueterm) and start typing 0’s and/or 1’s
How can I send the command “AB1200” and get it from arduino using this bluetooth ?
Hi Tolis.
Don’t now what you’re trying to do or what is the problem you’re having, but using the above code and sketch, you can send and receive commands.
Thanks for your reply. So you are saying that I can use the sketch to send commands to the arduino the are not simple “1” or “0” but can be more complex as “MOT10” ?
Yes, you can use the sketch, but you must code that part yourself.
Where it reads :
if (btdata == ‘1’)
you must put there your own strings – but remember, you must perform string comparison – I kept it simple and just compare it with ‘1’.
btdata is the variable that holds whatever comes through the serial port…
Read about serial communication in Arduino
Best regards
Thank you for your kind replies
Hi
Can you please help. How to send more complex commands like “ON” or “OFF instead of “1” or “0”.