Hardware

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)

The connections

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.

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…