Let's connect a wireless Bluetooth module to the Arduino and learn how to receive data from it and transfer data to it from a computer.
Necessary
- - Arduino;
- - bluetooth module;
- - computer;
- - connecting wires.
Instructions
Step 1
There are many implementations of Bluetooth modules. Each has its own characteristics, but in general they are all very similar. Consider a representative of the HC-06 bluetooth module.
This module operates at frequencies from 2.40 GHz to 2.48 GHz and supports the bluetooth specification version 2.1 + EDR (lower power consumption, increased data security and easy connection of Bluetooth devices). Stable reception with the module is guaranteed within 10 meters.
The purpose of the pins of the bluetooth module is as follows:
- VCC and GND - "plus" and "minus" of the module power supply, voltages from 3, 6 to 6 volts are supported;
- TX and RX - transmitter and receiver of the module;
- MCU-INT (Status) is a status output;
- Clear (Reset) - reset and restart of the module, in this case it is carried out by a low logic level.
The last two conclusions may not be involved; you can often find modules without these conclusions at all.
Step 2
Let's connect the bluetooth module to the Arduino according to the diagram below. Please note that the transmitter (Tx) of the Arduino is connected to the receiver (Rx) of the module, and vice versa.
The Status pin displays a high level when the module is paired with another bluetooth device, and low when it is not paired. You can read its value by connecting it to the Arduino pin and assigning it the pinMode (pinStatus, INPUT) operating mode and thus find out the state of the module. But the status indicator does not work correctly on all modules, so we will not use it in this example.
Step 3
The result should be something like the photo.
Step 4
Let's write such a sketch and load it into the Arduino memory. We will read the data coming from the bluetooth module and process it. In this case, when the "1" symbol comes from the module, we will light the LED, and when "0" arrives, turn it off.
We turn on the assembled circuit with the Arduino and the bluetooth module connected to it. A correctly connected module immediately enters the connection standby mode, which will be indicated by a rhythmically blinking status LED.
Step 5
Now you need to add the bluetooth device to the list of trusted devices. Turn on Bluetooth on your computer, go to Settings -> Devices -> Bluetooth. We make sure that our bluetooth module is visible to the computer. Select it from the list and click the Link button. In the dialog box, enter the default password 1234. If the addition is successful, the device will appear in the list with the Paired mark.
If you want to connect to your bluetooth module from your smartphone, then the procedure is the same: turn on bluetooth on your smartphone, detect the module connected to the Arduino, pair with it.
Step 6
To connect to the bluetooth module, you can use various programs that can be connected to the COM port. For example, such as HyperTerminal, PuTTY, Tera Term, Termite and others. They are all free and freely distributed on the Internet.
The convenience of TeraTerm is that it automatically lists the COM ports that are assigned to your computer's bluetooth module. Launch the program, select the Serial connection, select the corresponding bluetooth COM port from the list, click OK.
In case of an error during connection, the program will display a corresponding notification. If the connection of your computer with the bluetooth module was successful, then you will see a black terminal field in front of you.
Enter the number 1 from the keyboard in this field - and the LED on pin 13 of the Arduino will light up, enter 0 - it will go out.
Step 7
Similarly, you can connect to the bluetooth module from your smartphone. Download a bluetooth terminal application such as Bluetooth Terminal. Connect to the module and enter commands 0 or 1.
Thus, we learned how to connect via bluetooth to the Arduino and transfer data to it.