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.
Sending data over Bluetooth in 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.
Serial1.begin(9600); Serial1.print("Temperature: "); Serial1.println(25);
Serial1.begin(115200); Serial1.println("Start");
if (Serial1.available()) {
char c = Serial1.read();
Serial.println(c);
}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.
#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); } }
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.
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.