Section outline

  • Setting Up Arduino with Bluetooth

    Now that you’ve learned the basics of Bluetooth and the HC-05 module, it’s time to set up the Arduino to communicate wirelessly. This section covers how to wire the module, switch between modes, and test communication using simple code.

    • 🔌 Connecting HC-05 to Arduino

      • HC-05 VCC → Arduino 5V
      • HC-05 GND → Arduino GND
      • HC-05 TX → Arduino RX (Pin 0)
      • HC-05 RX → Arduino TX (Pin 1) (use a voltage divider to step down 5V to 3.3V)

      📡 Understanding Serial Communication

      Bluetooth modules like HC-05 use UART serial communication. It is important to wire TX of one device to RX of the other and vice versa.

      • TX: Transmit line of Bluetooth
      • RX: Receive line of Bluetooth
      • Make sure baud rate matches in code (default is 9600)

      ⚙️ Upload vs. Communicate Mode

      When the HC-05 is connected to RX/TX pins of the Arduino (pins 0 and 1), the Arduino may face issues uploading code. Here's what to do:

      • During Upload: Disconnect HC-05
      • After Upload: Reconnect HC-05 to use Serial

      This is because the same pins are used for USB upload and Serial communication. If you want to avoid this, consider using SoftwareSerial (we’ll cover that later).

    • 💻 Sample Code – Send and Receive Serial Data

      Upload this code to Arduino to read Bluetooth data and respond via Serial Monitor.

      void setup() {
        Serial.begin(9600);
        Serial.println("Bluetooth ready. Waiting for data...");
      }
      
      void loop() {
        if (Serial.available()) {
          char data = Serial.read();
          Serial.print("Received: ");
          Serial.println(data);
        }
      }
      

      🔍 Testing the Communication

      1. Upload the above code to Arduino
      2. Open the Serial Monitor and set baud to 9600
      3. Connect your phone to HC-05 using a Bluetooth terminal app
      4. Send characters from your phone and see them printed in Serial Monitor

      ✅ What You Learned

      • How to wire and connect HC-05 Bluetooth module to Arduino
      • Difference between upload and communication modes
      • Tested two-way communication using a terminal app

      This setup is the heart of Bluetooth-based projects. In the next section, we’ll build a full robot using this wireless communication.