/* HC-05 Bluetooth Module — Combined Sample Sketch Tishvi Docs · guide.tishvi.com Wiring (Arduino UNO R3): HC-05 VCC -> Arduino 5V HC-05 GND -> Arduino GND HC-05 TXD -> Arduino D2 (direct — 3.3V registers as HIGH) HC-05 RXD -> Arduino D3, via a voltage divider: D3 -> R1 (1kΩ) -> RXD -> R2 (2kΩ) -> GND (never wire RXD straight to a 5V pin) LED -> Arduino pin 13 (built-in LED works fine) What it does: - Bridges Serial Monitor <-> Bluetooth so you can confirm the module is wired correctly (type in either window, see it in the other). - Also listens for '1' / '0' over Bluetooth to turn the LED on/off. Pairing: Default PIN is usually 1234 or 0000. Use a Bluetooth serial terminal app (e.g. "Serial Bluetooth Terminal" on Android) to connect and send characters. Baud rate: 9600 — this is the HC-05's default DATA mode baud rate. If you've changed it with an AT+UART command, update BTSerial.begin() below to match. Library: SoftwareSerial — built into the Arduino IDE, no installation needed. */ #include SoftwareSerial BTSerial(2, 3); // RX, TX — D2<-HC-05 TXD, D3->HC-05 RXD const int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); BTSerial.begin(9600); Serial.println("HC-05 ready. Pair with 'HC-05' on your phone (PIN 1234 or 0000)."); Serial.println("Send '1' or '0' over Bluetooth to control the LED."); } void loop() { // Anything received over Bluetooth... if (BTSerial.available()) { char c = BTSerial.read(); // ...is echoed to the Serial Monitor for debugging Serial.write(c); // ...and checked for LED commands if (c == '1') { digitalWrite(ledPin, HIGH); BTSerial.println("LED ON"); } else if (c == '0') { digitalWrite(ledPin, LOW); BTSerial.println("LED OFF"); } } // Anything typed in Serial Monitor is sent out over Bluetooth if (Serial.available()) { BTSerial.write(Serial.read()); } }