Posts Tagged ‘Bluetooth Communication’
Bluetooth Communication with Arduino
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 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…