tutorial
Arduino Bluetooth Basic Tutorial
Bluetooth is a technology for wireless communication. It is designed to replace cable connections. It uses serial communication to communicate with devices. It communicates with the microcontroller using the serial port (USART). Usually, it connects small devices like mobile phones, PDAs and TVs using a short-range wireless connection to exchange documents. It uses the 2.45GHz frequency band. The connection can be point-to-point or multi-point where the maximum range is 10 meters. The transfer rate of the data is 1Mbps.
HC-05 Bluetooth module provides switching mode between master and slave mode which means it able to use neither receiving nor transmitting data.
HC-05 Specifications:
- Bluetooth protocol: Bluetooth Specification v2.0+EDR
- Frequency: 2.4GHz ISM band
- Modulation: GFSK(Gaussian Frequency Shift Keying)
- Emission power: ≤4dBm, Class 2
- Sensitivity: ≤-84dBm at 0.1% BER
- Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
- Security: Authentication and encryption
- Profiles: Bluetooth serial port
- Power supply: +3.3VDC 50mA
- Working temperature: -20 ~ +75Centigrade
- Dimension: 26.9mm x 13mm x 2.2 mm
- It is IEEE 802.15.1 standardized protocol, through which one can build wireless Personal Area Network (PAN). It uses frequency-hopping spread spectrum (FHSS) radio technology to send data over the air.
Pin Description:
It has 6 pins,
1. Key/EN: It is used to bring Bluetooth module in AT commands mode. By default, this pin operates in data mode. Key/EN pin should be high to operate Bluetooth in command mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode.HC-05 module has two modes,
- Data mode: Exchange of data between devices. Baud rate is 9600bps in data mode.
- Command mode: It uses AT commands which are used to change the setting of HC-05. Baud rate is 38400bps in command mode.
2. VCC: Connect 5 V or 3.3 V to this Pin.
3. GND: Ground Pin of the module.
4. TXD: Connect with Microcontroller RXD pin of Microcontroller. Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin)
5. RXD: Connect with Microcontroller TXD pin of Microcontroller. Received data will be transmitted wirelessly by Bluetooth module.
6. State: It tells whether the module is connected or not. It acts as a status indicator.
Connection:
The circuit is so simple and small, there are only a few connections to be made
Arduino Pins Bluetooth Pins
RX (Pin 0) ———-> TX
TX (Pin 1) ———-> RX
5V ———-> VCC
GND ———-> GND
1. Connect Power Supply (based on the datasheet of modules) for Bluetooth and Microcontroller which you are using.
2. Connect TXD pin of HC-05 Bluetooth module to RXD pin of Microcontroller.
3. Connect RXD pin of HC-05 Bluetooth module to TXD pin of Microcontroller.
4. Common grounding should be needed for both modules.
Note:
Don’t Connect RX to RX and TX to TX of Bluetooth to Arduino you will receive no data, Here TX means Transmit and RX means Receive.
Working Principle:
HC 05/06 works on serial communication. Here the android app is designed sending serial data to the Bluetooth module when a certain button is pressed. The Bluetooth module at other end receives the data and send to Arduino through the TX pin of the Bluetooth module (RX pin of Arduino). The Code fed to Arduino checks the received data and compares.
If a LED is connected to the Arduino, and if we press any button on the app the data will be transmitted to the module. If received data is 1 the LED turns on turns OFF when received data is 0.
Connection Diagram:
Note:
Arduino uses
serial port for reading/writing programs to the flash memory. These are the
same UART (Tx/Rx) pins. If these pins are connected to some external peripheral
like Bluetooth or any other module the Tx/Rx pins cannot be used for
programming the Arduino as they appear unavailable to the computer terminal.
Hence, you need to disconnect the Tx and Rx pins of device which is connected to the Arduino before uploading the code.
Code:
char data = 0; //Variable for storing received data
void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data & store into data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n");
}
}
Output:
If 1 is received, then Led glows.
If 0 is received, then Led stops glowing.
No comments:
Post a Comment