Bluetooth is a form of short-range, low power wireless communication technology that allows devices such as Smartphones, laptops and other devices to transmit and receive data wirelessly over a short distance. The purpose of using Bluetooth is to replace cables that connect devices and also make the communication between them safe and secure.
Bluetooth was invented by the telecoms vendor Ericsson in 1994 It uses 2.4GHz frequency band ,it is same as some other wireless technologies, such as cordless phones and WiFi routers. It creates a 10 meter radius wireless network, known as a personal area network (PAN) or piconet, which can network between two to eight devices. This short-range network allows you to perform activities like send a page to your printer which might be in different room than yours , play music from playlist of your mobile to speakers, home automation etc. .
The HC05 Bluetooth Module
The HC-05 module is an easy-to-use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup. Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) with data transfer rate of 3Mbps on complete 2.4GHz radio transceiver and baseband.
evive has dedicated Bluetooth (HC05) headers which requires you to just connect the HC05 Bluetooth module.
Bluetooth can be interfaced using Serial communication. Serial Communication transfers data as one bit at a time. The speed with which it transmits the data is called baud rate, which is expressed in bits per second (bps).
Widely used baud-rates are:
In serial Communication, there are two wires, namely Tx (Transmitter) and Rx (Receiver). They are always cross connected (Tx —> Rx and Rx —> Tx).
To set up the Bluetooth, you must transmit a set of commands known as the AT commands.
AT commands for any device can be found in the datasheet of a device. AT commands are English words which are most likely UPPERCASE letters and they respond in OK, Error or Answer.
In this example, you will use the HC-05 Bluetooth 2.0 module.You will setup the Bluetooth device by changing its Name, Password, and Baud-rate.
Set Bluetooth in AT mode
- Upload the code to evive (DO NOT connect Bluetooth).
- Turn off evive ( Remove the cable or turn power switch OFF).
- Plug Hc-05 in evive.
- Press and hold the push button on Hc-05 module.
- Switch evive ON.
- Release the push button now if the led on Hc-05 starts blinking with a time difference of approx 2 seconds this means that Hc-05 successfully went into AT mode.
- In AT mode bluetooth always communicates at baud of 38400 and with each command it is mandatory to send ‘\r’ and ‘\n’ while using HC-05 module. For example if you want to send command “AT+NAME=evive” then it should be sent like “AT+NAME=evive\r\n”. This will be more clear from example given below.
Working of code
- As mentioned in point above that bluetooth always communicates at baudrate of 38400 in AT mode hence baud of communication between evive and bluetooth is set to 38400 in command Serial3.begin(38400);”
- Once the bluetooth goes in AT mode it gets AT commands from evive to change name, password and baudrate of evive. AT Command for displaying address of bluetooth is also given.
- As soon as code is uploaded open Serial monitor set the baud rate of serial monitor to the value written in Serial.begin().
- evive continuously sends one type of AT command until it gets response from Hc-05. As evive gets proper response it sends next command. For each command sent to Hc-05 if it responds successfully, its response is printed on Serial monitor.
- As soon as bluetooth gets “AT+INIT\r\n” command from code it exits from AT mode and goes in pairing mode.
- Pin-13 also turns on. This suggests that bluetooth has been configured successfully as per the commands given in the code.When bluetooth is in pairing mode the led of bluetooth blinks fast showing that it is ready to get paired.
- Actually “AT+INIT\r\n” is for getting bluetooth in pairing mode. But this command works on some only some firmware versions of bluetooth.
Arduino IDE Sketch
Below is the Arduino IDE sketch:
You can enter your own AT commands by uploading the code given below. After uploading code open serial monitor set “No line ending” to “Both NL and CR” in serial monitor. Then start giving your desired AT command.