📱 LED control using Arduino, Bluetooth module and Android-smartphone
For the project you will need:
- Arduino UNO;
- 3 resistors per 300Ω;
- 1 resistor per 150Ω;
- Light-emitting diode;
- Bluetooth module (HC-06 or other);
- Android smartphone;
- SPP Bluetooth Apk application (in this example, unWired Lite);
- Some programming skills in C.
Connect HC-06 to Arduino
Bluetooth is a type of wireless connection that transmits data using radio waves. It is often used in phones for calling and data transmission. This cheap and reliable form of communication, which is perfect for remote control of external devices using Arduino.
The HC-06 4 module connects to the Arduino using 4 pins:
RXD is used to receive data from the Arduino; TXD - sends data to the Arduino board; VCC is the contact for the power supply (3.3 V to 6.6 V); GND is the land.
Pay attention to the contact RXD. Some Bluetooth modules work from 5 V, but the one used in this project works with a power supply of 3.3 V. At the same time, the Arduino TX sends a 5 V control signal, so a voltage divider is needed.
Voltage divider with R1 = 300Ω:
Vout = R2 / (R2 + R1) * Vin
3.3 = R2 / (R2 + 300) * 5
3.3 * R2 + 990 = 5 * R2
R2 = 990 / 1.7
R2 ~ 600Ω
If you have another resistor:
R2 = (3.3 * R1) /1.7Ω
Connect the module HC-06 to the Arduino (see picture):
Arduino ------------- HC-06
RX ------------------- TXD
TX ------------------- RXD
+ 5V ----------------- VCC
GND ---------------- GND
Sketch for Arduino
The sketch for this project is very simple. All he has to do is check if there is data on the serial port.
When using an Android smartphone with the corresponding spp Bluetooth apk, the command is sent to Bluetooth (RX / TX). At the same time, the Bluetooth module establishes communication with the Bluetooth of our Android using a profile called SPP (Serial Port Profile). It emulates the USB connection of our Arduino and Android.
We initialize all contacts and variables.
#define led 8
The data transfer rate of the HC-06 module defaults to 9600 baud. Function code void setup:
void setup ()
pinMode (led, OUTPUT);
In the sketch, two functions. Their names speak for themselves.
App for android UnWired Lite
unWired is an application that allows you to connect to the Arduino bluetooth module. This is not the only such application, so you can use another if you want.
Before starting the application, connect the Bluetooth module.
The first screen of the application is shown in the figure below. Select ‘Dispositivos Pareados’. All devices connected to the smartphone should appear. Among these devices, select the Bluetooth module that we connected before.
On the second screen (Fig. 2), you will directly enter commands for sending via Bluetooth. In our case, these are two commands - LO to turn on the LED and LF - to turn off the LED.
Now you know how to configure the operation of the Bluetooth module and the Arduino and how to remotely transmit commands to the board.
You can equally well receive data from the Arduino and display it in the android application. To do this, you just need to slightly change the function in the sketch.