The Bluetooth Chat example provides a two-way text messaging interface accessible through the DIYables Bluetooth STEM app. Designed for Arduino UNO R4 WiFi using BLE (Bluetooth Low Energy) to send and receive text messages between your Arduino and smartphone in real time. Perfect for command-line interfaces, remote control via text commands, serial bridges, and interactive debugging.
Note: The Arduino UNO R4 WiFi only supports BLE (Bluetooth Low Energy). It does not support Classic Bluetooth. The DIYables Bluetooth App supports both BLE and Classic Bluetooth on Android, and BLE on iOS. Since this board uses BLE, the app works on both Android and iOS.
Features
Two-Way Messaging: Send and receive text messages in real time
Command Handling: Process text commands from the mobile app
Serial Bridge: Forward messages between Serial Monitor and Bluetooth
Custom Responses: Auto-reply with echoes or processed data
Works on Android & iOS: BLE is supported on both platforms
No Pairing Required: BLE auto-connects without manual pairing
Low Power: BLE consumes less power than Classic Bluetooth
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. Additionally, some of these links are for products from our own brand, DIYables .
Connect the Arduino UNO R4 WiFi board to your computer using a USB cable.
Launch the Arduino IDE on your computer.
Select Arduino UNO R4 WiFi board and the appropriate COM port.
Navigate to the Libraries icon on the left bar of the Arduino IDE.
Search "DIYables Bluetooth", then find the DIYables Bluetooth library by DIYables
Click Install button to install the library.
You will be asked for installing some other library dependencies
Click Install All button to install all library dependencies.
BLE Code
On Arduino IDE, Go to File Examples DIYables Bluetooth ArduinoBLE_Chat example, or copy the above code and paste it to the editor of Arduino IDE
/* * DIYables Bluetooth Library - Bluetooth Chat Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Chat feature: * - Two-way text messaging via Bluetooth * - Receive messages from mobile app * - Send messages to mobile app * * Compatible Boards: * - Arduino UNO R4 WiFi * - Arduino Nano 33 BLE / BLE Sense * - Arduino Nano 33 IoT * - Arduino MKR WiFi 1010 * - Arduino Nano RP2040 Connect * - Any board supporting the ArduinoBLE library * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status and messages * 3. Use DIYables Bluetooth App to connect and chat * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */#include <DIYables_BluetoothServer.h>#include <DIYables_BluetoothChat.h>#include <platforms/DIYables_ArduinoBLE.h>// BLE Configurationconst char* DEVICE_NAME = "Arduino_Chat";const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214";const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214";const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214";// Create Bluetooth instancesDIYables_ArduinoBLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID);DIYables_BluetoothServer bluetoothServer(bluetooth);// Create Chat app instanceDIYables_BluetoothChat bluetoothChat;// Variables for periodic messagesunsignedlong lastMessageTime = 0;constunsignedlong MESSAGE_INTERVAL = 10000; // Send message every 10 secondsint messageCount = 0;voidsetup() {Serial.begin(9600);while (!Serial);Serial.println("DIYables Bluetooth - Chat Example");// Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin();// Add chat app to server bluetoothServer.addApp(&bluetoothChat);// Set up connection event callbacks bluetoothServer.setOnConnected([]() {Serial.println("Bluetooth connected!"); bluetoothChat.send("Hello! Arduino is ready to chat."); }); bluetoothServer.setOnDisconnected([]() {Serial.println("Bluetooth disconnected!"); messageCount = 0; });// Set up callback for received chat messages bluetoothChat.onChatMessage([](const String& message) {Serial.print("Received: ");Serial.println(message);// Echo the message backString response = "Echo: "; response += message; bluetoothChat.send(response);// You can add custom command handling hereif (message.equalsIgnoreCase("ping")) { bluetoothChat.send("pong!"); } elseif (message.equalsIgnoreCase("status")) { bluetoothChat.send("Arduino is running normally"); } elseif (message.equalsIgnoreCase("time")) {String timeMsg = "Uptime: "; timeMsg += String(millis() / 1000); timeMsg += " seconds"; bluetoothChat.send(timeMsg); } });Serial.println("Waiting for Bluetooth connection..."); Serial.println("Type 'ping', 'status', or'time' in the app to test commands");}void loop() {// Handle Bluetooth server communications bluetoothServer.loop();// Send periodic status message (only when connected)if (bluetooth.isConnected() && millis() - lastMessageTime >= MESSAGE_INTERVAL) { lastMessageTime = millis(); messageCount++;String statusMsg = "Status update #"; statusMsg += String(messageCount); statusMsg += " - All systems operational"; bluetoothChat.send(statusMsg);Serial.print("Sent: ");Serial.println(statusMsg); }// Optional: Read from Serial and send to Bluetoothif (Serial.available()) {String serialMsg = Serial.readStringUntil('\n'); serialMsg.trim();if (serialMsg.length() > 0 && bluetooth.isConnected()) { bluetoothChat.send(serialMsg);Serial.print("Sent from Serial: ");Serial.println(serialMsg); } }delay(10);}
Click Upload button on Arduino IDE to upload code to Arduino UNO R4 WiFi
Open the Serial Monitor
Check out the result on Serial Monitor. It looks like the below:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
DIYables Bluetooth - Chat Example
Waiting for Bluetooth connection...
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
Mobile App
Install the DIYables Bluetooth App on your smartphone: Android | iOS
Note: The DIYables Bluetooth App supports both BLE and Classic Bluetooth on Android, and BLE on iOS. Since the Arduino UNO R4 WiFi uses BLE, the app works on both Android and iOS. No manual pairing is needed for BLE — just scan and connect.
Open the DIYables Bluetooth App
When opening the app for the first time, it will ask for permissions. Please grant the following:
Nearby Devices permission (Android 12+) / Bluetooth permission (iOS) - required to scan and connect to Bluetooth devices
Location permission (Android 11 and below only) - required by older Android versions to scan for BLE devices
Make sure Bluetooth is turned on on your phone
On the home screen, tap the Connect button. The app will scan for BLE devices.
Find and tap "Arduino_Chat" in the scan results to connect.
Once connected, the app automatically goes back to the home screen. Select the Chat app from the app menu.
Note: You can tap the settings icon on the home screen to hide/show apps on the home screen. For more details, see the DIYables Bluetooth App User Manual.
Type a message in the chat input and tap send
Now look back at the Serial Monitor on Arduino IDE. You will see:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Bluetooth connected!
Received: Hello
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2
The Arduino echoes your message back, and you can see the reply in the app chat
Creative Customization - Adapt the Code to Your Project
Handle Chat Messages
Use the onChatMessage() callback to receive and process messages typed in the app. You can define any custom command words that make sense for your project — the Arduino will react accordingly:
You can add as many custom commands as you need by adding more elseif blocks. For example, add LED_ON / LED_OFF to control a pin, or READ to trigger a sensor reading — any word you type in the app becomes a command.
Send Messages from Arduino
// Send a text message to the appbluetoothChat.send("Hello from Arduino!");// Send sensor readingfloat temp = readTemperature();bluetoothChat.send("Temperature: " + String(temp, 1) + " °C");
Serial-to-Bluetooth Bridge
Forward messages between Serial Monitor and Bluetooth:
// In loop():if (Serial.available()) {String serialMsg = Serial.readStringUntil('\n'); serialMsg.trim();if (serialMsg.length() > 0 && bluetooth.isConnected()) { bluetoothChat.send(serialMsg);Serial.print("Sent from Serial: ");Serial.println(serialMsg); }}
Handle Connection Events
bluetoothServer.setOnConnected([]() {Serial.println("Bluetooth connected!"); bluetoothChat.send("Hello! Arduino is ready to chat.");});bluetoothServer.setOnDisconnected([]() {Serial.println("Bluetooth disconnected!");});
How to Use the Chat
App Interface
The chat interface in the DIYables Bluetooth App provides:
Message List: Shows sent and received messages with timestamps
Text Input: Type messages to send to the Arduino
Send Button: Tap to send the message
Communication Flow
Type a message in the app ? Arduino receives it via onChatMessage() callback
Arduino processes the message and optionally sends a reply via bluetoothChat.send()
/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-diyables-bluetooth-app-chat *//* * DIYables Bluetooth Library - Bluetooth Chat Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Chat feature: * - Two-way text messaging via Bluetooth * - Receive messages from mobile app * - Send messages to mobile app * * Compatible Boards: * - Arduino UNO R4 WiFi * - Arduino Nano 33 BLE / BLE Sense * - Arduino Nano 33 IoT * - Arduino MKR WiFi 1010 * - Arduino Nano RP2040 Connect * - Any board supporting the ArduinoBLE library * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status and messages * 3. Use DIYables Bluetooth App to connect and chat * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */#include <DIYables_BluetoothServer.h>#include <DIYables_BluetoothChat.h>#include <platforms/DIYables_ArduinoBLE.h>// BLE Configurationconst char* DEVICE_NAME = "Arduino_Chat";const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214";const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214";const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214";// Create Bluetooth instancesDIYables_ArduinoBLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID);DIYables_BluetoothServer bluetoothServer(bluetooth);// Create Chat app instanceDIYables_BluetoothChat bluetoothChat;// Variables for periodic messagesunsignedlong lastMessageTime = 0;constunsignedlong MESSAGE_INTERVAL = 10000; // Send message every 10 secondsint messageCount = 0;voidsetup() {Serial.begin(9600);while (!Serial);pinMode(LED_BUILTIN,OUTPUT);digitalWrite(LED_BUILTIN,LOW);Serial.println("DIYables Bluetooth - Chat Example");// Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin();// Add chat app to server bluetoothServer.addApp(&bluetoothChat);// Set up connection event callbacks bluetoothServer.setOnConnected([]() {Serial.println("Bluetooth connected!");delay(500); bluetoothChat.send("Hello! Arduino is ready to chat."); }); bluetoothServer.setOnDisconnected([]() {Serial.println("Bluetooth disconnected!"); messageCount = 0; });// Set up callback for received chat messages bluetoothChat.onChatMessage([](const String& message) {Serial.print("Received: ");Serial.println(message);String cmd = message; cmd.toUpperCase(); cmd.trim(); if (cmd == "LED ON") {digitalWrite(LED_BUILTIN, HIGH); bluetoothChat.send("LED is now: ON"); Serial.println("LED turned ON"); } elseif (cmd == "LED OFF") {digitalWrite(LED_BUILTIN, LOW); bluetoothChat.send("LED is now: OFF"); Serial.println("LED turned OFF"); }elseif (cmd == "UPTIME") {unsignedlong sec = millis() / 1000;intmin = sec / 60; sec %= 60;String uptimeMsg = "System Uptime: " + String(min) + "m " + String(sec) + "s"; bluetoothChat.send(uptimeMsg); }elseif (cmd == "BLINK") { bluetoothChat.send("Blinking LED 3 times...");for(int i=0; i<3; i++) {digitalWrite(LED_BUILTIN, HIGH); delay(200);digitalWrite(LED_BUILTIN, LOW); delay(200); } bluetoothChat.send("Done!"); }elseif (cmd == "STATUS") {int state = digitalRead(LED_BUILTIN);String statusMsg = "Current LED Status: "; statusMsg += (state == HIGH) ? "ON" : "OFF"; bluetoothChat.send(statusMsg); }elseif (cmd == "HELP") {String help = "Available CMDs:\n- LED ON/OFF: Control LED\n- STATUS: Check LED state\n- UPTIME: Check time\n- BLINK: Blink LED\n"; bluetoothChat.send(help); } else { bluetoothChat.send("Invalid CMD. Type 'HELP' to see list."); } }); Serial.println("Waiting for Bluetooth connection...");}void loop() {// Handle Bluetooth server communications bluetoothServer.loop();// Optional: Read from Serial and send to Bluetoothif (Serial.available()) {String serialMsg = Serial.readStringUntil('\n'); serialMsg.trim();if (serialMsg.length() > 0 && bluetooth.isConnected()) { bluetoothChat.send(serialMsg);Serial.print("Sent from Serial: ");Serial.println(serialMsg); } }delay(10);}
Troubleshooting
Common Issues
1. Cannot find the device in the app
Make sure the Arduino UNO R4 WiFi is powered on and the sketch is uploaded
Ensure your phone's Bluetooth is enabled
On Android 11 and below, also enable Location services
Try restarting Bluetooth on your phone
2. Messages not received by Arduino
Check Bluetooth connection status in the app
Verify the onChatMessage callback is set up correctly
Check Serial Monitor for any error messages
3. Arduino replies not showing in app
Ensure bluetoothChat.send() is being called
Check that bluetoothServer.loop() is called in the main loop
Verify connection is still active with bluetooth.isConnected()
4. Serial Monitor shows garbled text
Ensure baud rate in Serial Monitor matches Serial.begin(9600)
Check that the correct board is selected in Arduino IDE
5. Connection drops frequently
Move closer to the Arduino (reduce distance)
Check for interference from other BLE devices
Ensure stable USB power supply
6. Upload fails or board not recognized
Install the latest Arduino UNO R4 board package via Board Manager
Try a different USB cable or port
Press the reset button on the board before uploading
Project Ideas
Communication
Text command interface for home automation
Serial-to-Bluetooth bridge for wireless debugging
Remote sensor query system
Interactive quiz or trivia game
Control Systems
Voice-to-text relay control
Multi-device command router
Configuration manager via chat commands
Firmware version reporter
Logging & Monitoring
Event logger with timestamps
Alarm notification system
Status report generator
Diagnostic chat bot
Integration with Other Bluetooth Apps
Combine with Bluetooth Monitor
Use chat for commands and monitor for continuous output:
Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!