Arduino Nano ESP32 - DIYables Bluetooth App Chat
Overview
This example implements a two-way text messaging interface on the Arduino Nano ESP32 using BLE (Bluetooth Low Energy) via the DIYables Bluetooth STEM app. Send and receive text messages between the Arduino and a smartphone in real time. Suitable for command-line interfaces, remote control via text, serial bridges, and interactive debugging.
Note: The Arduino Nano ESP32 supports BLE only — Classic Bluetooth is not supported. The DIYables Bluetooth App works on both Android and iOS with BLE.

Features
- Two-Way Messaging: Send and receive text messages in real time
- Command Handling: Process text commands received from the app
- Serial Bridge: Forward messages between Serial Monitor and Bluetooth
- Custom Responses: Auto-reply with echoes or processed data
- Android & iOS Support: BLE is compatible with both platforms
- No Pairing Required: BLE connects without manual pairing
- Low Power: BLE consumes less power than Classic Bluetooth
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Arduino Nano ESP32 Code
Detailed Instructions
- New to the Arduino Nano ESP32? Start with the Arduino Nano ESP32 getting started guide.
- Connect the Arduino Nano ESP32 to your computer via USB.
- Open Arduino IDE.
- Select the Arduino Nano ESP32 board and the correct COM port.
- Click the Libraries icon in the left sidebar.
- Search for "DIYables Bluetooth" and select the DIYables Bluetooth library by DIYables.
- Click Install.

- When prompted to install dependencies, click Install All.

BLE Code
- In Arduino IDE, open File Examples DIYables Bluetooth ArduinoBLE_Chat, or paste the code into the editor.
- Click Upload to flash the sketch to the board.
- Open the Serial Monitor.
- The Serial Monitor output should look like:
Mobile App
Note: The DIYables Bluetooth App works on both Android and iOS with BLE. No manual pairing is required.
- Launch the DIYables Bluetooth App.
- On first launch, grant the following permissions:
- Nearby Devices (Android 12+) / Bluetooth (iOS) — required to scan and connect to Bluetooth devices
- Location (Android 11 and below only) — required by older Android versions to scan for BLE
- Ensure Bluetooth is enabled on your device.
- Tap Connect on the home screen. The app will scan for BLE devices.

- Tap "Arduino_Chat" in the scan results.
- After connecting, return to the home screen and open the Chat app.

Tap the settings icon on the home screen to show or hide apps. See the DIYables Bluetooth App User Manual for details.
- Type a message in the chat input field and tap send.

Now look back at the Serial Monitor on Arduino IDE. You will see:
- The Arduino echoes the message back, and the reply appears in the app chat.
Creative Customization - Adapt the Code to Your Project
Handle Chat Messages
Use the onChatMessage() callback to receive and process messages from the app. Define custom command words as needed — the Arduino responds accordingly:
Add additional else if blocks for each command. For example, use LED_ON / LED_OFF to control a pin or READ to trigger a sensor reading.
Send Messages from Arduino
Serial-to-Bluetooth Bridge
Forward messages between Serial Monitor and Bluetooth:
Handle Connection Events
How to Use the Chat
App Interface
The Chat app in the DIYables Bluetooth App provides:
- Message List: Displays sent and received messages with timestamps
- Text Input: Type messages to send to the Arduino
- Send Button: Tap to transmit 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()
- The reply appears in the app chat window
Programming Examples
Command Handler with Relay Control
Sensor Query System
Periodic Status Updates
Advanced Programming Techniques
Multi-Word Command Parsing
Chat Logger with Timestamps
Troubleshooting
Common Issues
1. Device not visible in the app
- Confirm the board is powered on and the sketch is uploaded
- Verify Bluetooth is enabled on your phone
- On Android 11 and below, enable Location services as well
- Try restarting Bluetooth on your phone
2. Messages not received by the Arduino
- Check the Bluetooth connection status in the app
- Confirm the onChatMessage callback is registered correctly
- Review the Serial Monitor for error messages
3. Arduino replies not appearing in the app
- Verify bluetoothChat.send() is being called
- Confirm bluetoothServer.loop() appears in the main loop
- Check the connection state with bluetooth.isConnected()
4. Serial Monitor shows garbled text
- Confirm the baud rate in Serial Monitor matches Serial.begin(9600)
- Verify the correct board is selected in Arduino IDE
5. Connection drops frequently
- Reduce distance to the Arduino
- Check for interference from other BLE devices
- Ensure a stable USB power supply
6. Upload fails or board not recognized
- Install the latest Arduino Nano ESP32 board package via Board Manager
- Try a different USB cable or port
- Press the reset button 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:
Combine with Bluetooth Table
Chat commands to control what data is shown in the table:
Next Steps
After completing the Bluetooth Chat example, explore:
- Bluetooth Monitor — One-way status message streaming
- Bluetooth Slider — Analog value control
- Bluetooth Table — Structured data display
- Multiple Bluetooth Apps — Combine chat with other app widgets
Support
For additional help:
- Check the API Reference documentation
- Visit DIYables tutorials
- Arduino community forums