Introduction
The HC-05 is a popular Bluetooth module that allows for serial communication between Arduino and other devices like smartphones.
Wiring
| HC-05 Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| TX | Pin 2 (RX) |
| RX | Pin 3 (TX) |
Note: Use a voltage divider (2kΩ and 1kΩ) on the HC-05 RX pin as it expects 3.3V logic.
The Code
#include <SoftwareSerial.h>
SoftwareSerial bt(2, 3); // RX, TX
void setup() {
bt.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
if (bt.available()) {
char data = bt.read();
if (data == '1') digitalWrite(13, HIGH);
else if (data == '0') digitalWrite(13, LOW);
}
}