0
0
Arduinoprogramming~5 mins

Sending data over Bluetooth in Arduino

Choose your learning style9 modes available
Introduction

Sending data over Bluetooth lets your Arduino talk wirelessly to other devices like phones or computers. This helps you control or share information without wires.

You want to send sensor readings from Arduino to your phone.
You want to control a robot wirelessly using a Bluetooth controller.
You want to send commands from your computer to Arduino without cables.
You want to build a wireless home automation system.
You want to transfer small data like text or numbers between devices easily.
Syntax
Arduino
Serial1.begin(9600);
Serial1.print("Hello");
Serial1.println(" World");

Use Serial1 or the serial port connected to your Bluetooth module.

begin(9600) sets the speed; match it with your Bluetooth module's baud rate.

Examples
Sends the text 'Temperature: 25' over Bluetooth.
Arduino
Serial1.begin(9600);
Serial1.print("Temperature: ");
Serial1.println(25);
Starts communication at a faster speed and sends 'Start'.
Arduino
Serial1.begin(115200);
Serial1.println("Start");
Reads one character sent from Bluetooth and prints it to the Arduino serial monitor.
Arduino
if (Serial1.available()) {
  char c = Serial1.read();
  Serial.println(c);
}
Sample Program

This program sets up a Bluetooth connection using pins 10 and 11. It listens for data from Bluetooth and prints it to the serial monitor. It also sends anything typed in the serial monitor to the Bluetooth device.

Arduino
#include <SoftwareSerial.h>

SoftwareSerial BTserial(10, 11); // RX, TX pins

void setup() {
  Serial.begin(9600);       // For serial monitor
  BTserial.begin(9600);     // For Bluetooth module
  Serial.println("Bluetooth Start");
}

void loop() {
  if (BTserial.available()) {
    char c = BTserial.read();
    Serial.print("Received: ");
    Serial.println(c);
  }

  if (Serial.available()) {
    char c = Serial.read();
    BTserial.print(c);
  }
}
OutputSuccess
Important Notes

Make sure your Bluetooth module's RX and TX pins are connected correctly to Arduino's TX and RX pins (cross connection).

Match the baud rate in begin() with your Bluetooth module's settings.

Use SoftwareSerial if your Arduino has only one hardware serial port.

Summary

Bluetooth lets Arduino send and receive data wirelessly.

Use Serial or SoftwareSerial to communicate with the Bluetooth module.

Always match baud rates and connect pins correctly for communication to work.