/* The HC-05 Bluetooth module can be easily interfaced with an Arduino using the SoftwareSerial library. Here's an example code to send and receive data between an Arduino and a Bluetooth device (e.g., a smartphone) using the HC-05 module: This code sets up a simple "echo" between the Serial Monitor and the Bluetooth device. It reads data from the Bluetooth module and sends it to the Serial Monitor, and vice versa. Connect the HC-05 Bluetooth module to the Arduino as follows: VCC pin to 5V (or 3.3V, depending on your module's voltage level) GND pin to GND TX pin to digital pin 2 on the Arduino RX pin to digital pin 3 on the Arduino To connect to the HC-05 module from your smartphone, you'll need a Bluetooth Terminal app. Pair your smartphone with the HC-05 module using the default pairing code (usually "1234" or "0000"), open the Bluetooth Terminal app, and connect to the HC-05 device. You should now be able to send and receive data between your smartphone and the Arduino via the HC-05 module. Please note that you may need to adjust the pin numbers in the code depending on the specific pins you choose to use for connecting the HC-05 module to your Arduino. Additionally, when connecting the TX pin of the HC-05 module to the RX pin of the Arduino, it is recommended to use a voltage divider to reduce the voltage from 5V to 3.3V if your HC-05 module operates at 3.3V. */ #include #include const int btRxPin = 2; // Connect this pin to the TX pin of the HC-05 module const int btTxPin = 3; // Connect this pin to the RX pin of the HC-05 module SoftwareSerial btSerial(btRxPin, btTxPin); void setup() { Serial.begin(9600); btSerial.begin(9600); Serial.println("HC-05 Bluetooth Module Example"); } void loop() { // Read data from Bluetooth and send it to the Serial Monitor if (btSerial.available()) { char data = btSerial.read(); Serial.print(data); } // Read data from the Serial Monitor and send it to Bluetooth if (Serial.available()) { char data = Serial.read(); btSerial.print(data); } }