Sony Arouje

a programmer's log

Bluetooth Communication with Arduino

leave a comment »

I am in the process of redesigning my Raspberry Pi based Aeroponic controller, in my new system I am using Arduino. This time I decided to use Bluetooth instead of WiFi to communicate between my mobile app and Arduino controller. Later I will write a different post explaining about the new design. In this post I will explain how to communicate to Arduino via Bluetooth.

 

Arduino Bluetooth connection

I bought a HC-05 Bluetooth module from Ebay, it’s a very low cost module. The connection is pretty simple. See the connection below. I am using Arduno Nano in my new design.

connection_v2_bb

 

Connection Details

  • Nano VCC to BT VCC
  • Nano GND to BT GND
  • Nano RXD to BT TXD
  • Nano TXD to BT RXD

In my sketch I used Softserial and I assign D2 and D3 as RXD and TXD respectively.

I haven’t used the EN and KEY pin in the Bluetooth module. You might want to use EN pin, if you want to enter into AT mode to issue any commands to BT module.

Arduino Sketch

#include <SoftwareSerial.h> SoftwareSerial soft(2,3);// RX, TX void setup() { soft.begin(9600); Serial.begin(9600); } void loop() { if(soft.available()){ String serialData = soft.readString(); Serial.println(serialData); //echo bluetooth data to serial writeAck(); } } void writeAck(){ uint8_t payload[]="ACK|0|\n"; soft.write(payload,sizeof(payload)); }

 

It’s a very simple sketch to receive the data from Bluetooth module and echo to Serial, also send and Acknowledgment back to the caller.

You can test the program by issuing some text from Hyperterminal or any other similar app. I wrote an Android app to issue command via Mobile bluetooth.

 

Happy coding…

Advertisements

Written by Sony Arouje

March 4, 2016 at 1:26 pm

Posted in Arduino

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: