Bluetooth

A Bluetooth sensor is a device that communicates with the TX/RX pins of the Arduino and, of course, it receives data using the Bluetooth communication protocol. Counter to all the previous sensors. it is extremely easy to be burned by simply connecting the wrong wires. The Bluetooth sensor that we will be using is called HC06 and it looks like this:

It usually consists of six pins, but we use only four of them. If you look closer to the pinout, you will see that the actual pins (the pins to the edges are not used) are 3.3V, GND, TX, and RX. Notice that if you connect the GND to the power of the Arduino it will instantly burn and there is no way back. Also, if for any reason the 5V pin or the GND pin touches an area of the Arduino that must not touch, it may also burn. So, place it as far as possible from the Arduino, do not test the pinout connections, and, if possible, plug it to a breadboard so that it will be safe. Obviously, the power is a 3.3V or 5V. The following screenshot shows how to connect the Bluetooth module with your Arduino:

For those who wonder why should you use a Bluetooth module with the Arduino and not just use the Bluetooth of the Raspberry Pi board, well if you use the Bluetooth of the Raspberry Pi board, then you will not be able to fully use the default pins.

The following code can be used to test your connections; you can read from the Arduino what the serial receives:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0,1);
String Data = "";

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
//Serial.println("Hello world");
}

void loop() // run over and over
{
while (mySerial.available() > 0)
{
//Serial.println("Something is available");
char character = mySerial.read(); // Receive a single character from the software serial port
Data.concat(character); // Add the received character to the receive buffer

if (character == ' ')
{
//Serial.print("Received: ");
Serial.println(Data);

// Add your code to parse the received line here....

// Clear receive buffer so we're ready to receive the next line
Data = "";
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224