Difficulty Level: Intermediate
In this project, we will set up Bluetooth communication between an Arduino and a smartphone (or another Bluetooth-enabled device) using the HC-05 Bluetooth module. The setup can be expanded to control devices, send data, or monitor sensor readings wirelessly.
Connect the HC-05 Bluetooth module to the Arduino as follows:
Optionally, you can connect an LED to pin 13 of the Arduino with a 220Ω resistor to test communication.
For Bluetooth communication, we will use the SoftwareSerial library to enable serial communication on digital pins of the Arduino.
The Arduino sketch below sets up a basic Bluetooth communication system where messages sent from the Bluetooth terminal app will control an LED:
#include
// Create a SoftwareSerial object for HC-05
SoftwareSerial BTSerial(10, 11); // RX, TX
char data; // Variable to store received data
void setup() {
// Start serial communication with Arduino and HC-05
Serial.begin(9600);
BTSerial.begin(9600);
// Set pin 13 as output (for controlling LED)
pinMode(13, OUTPUT);
Serial.println("Waiting for Bluetooth input...");
}
void loop() {
// Check if data is received from the Bluetooth module
if (BTSerial.available()) {
data = BTSerial.read(); // Read the incoming data
Serial.print("Received: ");
Serial.println(data);
// Control LED based on received data
if (data == '1') {
digitalWrite(13, HIGH); // Turn on LED
Serial.println("LED ON");
BTSerial.println("LED ON");
} else if (data == '0') {
digitalWrite(13, LOW); // Turn off LED
Serial.println("LED OFF");
BTSerial.println("LED OFF");
}
}
}
To communicate with the Arduino over Bluetooth, install a Bluetooth terminal app on your smartphone (e.g., "Bluetooth Terminal" on Android or "Bluetooth Serial" on iOS).
Once the wiring is complete and the code is uploaded, follow these steps:
This basic setup can be expanded to control more complex systems such as motors, home appliances, or other devices. You can also modify the code to send sensor data from the Arduino to the smartphone for wireless monitoring.
In this project, we have established basic communication between an Arduino and a smartphone using Bluetooth. The HC-05 Bluetooth module makes it easy to add wireless functionality to your projects, enabling you to control devices or receive data remotely.