아두이노 나노 ESP32 블루투스 플로터 예제 BLE를 통한 실시간 데이터 시각화 튜토리얼
개요
이 예제는 BLE(블루투스 로우 에너지)를 사용하여 Arduino Nano ESP32에서 DIYables Bluetooth STEM 앱으로 실시간 데이터를 스트리밍하여 라이브 시각화를 제공합니다. 스마트폰에서 센서 데이터, 파형, 다중 채널 데이터를 실시간 그래프로 표시하세요. 데이터 로깅, 신호 분석, 센서 보정, 과학 실험에 적합합니다.
참고: Arduino Nano ESP32는 BLE만 지원하며 클래식 블루투스는 지원하지 않습니다. DIYables 블루투스 앱은 BLE를 통해 Android와 iOS 모두에서 작동합니다.

기능
- 다중 채널 플로팅: 최대 6개의 데이터 채널 동시 표시
- 설정 가능한 축: 커스텀 제목, 레이블, Y축 범위
- 범례 레이블: 각 데이터 채널에 이름 지정
- 샘플 제한: 표시할 최대 샘플 수 설정
- 빠른 스트리밍: 초당 최대 10회 업데이트 (100ms 간격)
- Android 및 iOS 지원: BLE는 두 플랫폼 모두 호환
- 페어링 불필요: BLE는 수동 페어링 없이 연결
필요한 하드웨어
| 1 | × | 아두이노 나노 ESP32 | 쿠팡 | 아마존 | |
| 1 | × | USB 케이블 타입-A to 타입-C (USB-A PC용) | 쿠팡 | 아마존 | |
| 1 | × | USB 케이블 타입-C to 타입-C (USB-C PC용) | 아마존 | |
| 1 | × | (추천) 아두이노 나노용 스크루 터미널 확장 보드 | 쿠팡 | 아마존 | |
| 1 | × | (추천) 아두이노 나노용 브레이크아웃 확장 보드 | 쿠팡 | 아마존 | |
| 1 | × | (추천) 아두이노 나노 ESP32용 전원 분배기 | 쿠팡 | 아마존 |
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
Arduino Nano ESP32 코드
빠른 시작
- Arduino Nano ESP32가 처음이신가요? 아두이노 나노 ESP32 - 소프트웨어 설치를 참조하세요.
- USB로 Arduino Nano ESP32를 컴퓨터에 연결하세요.
- Arduino IDE를 열어주세요.
- Arduino Nano ESP32 보드와 올바른 COM 포트를 선택하세요.
- 왼쪽 사이드바에서 라이브러리 아이콘을 클릭하세요.
- "DIYables Bluetooth"를 검색하고 DIYables의 DIYables Bluetooth 라이브러리를 선택하세요.
- 설치를 클릭하세요.

- 종속성 설치 메시지가 나타나면 모두 설치를 클릭하세요.

BLE 코드
- Arduino IDE에서 파일 예제 DIYables Bluetooth ArduinoBLE_Plotter를 열거나, 코드를 편집기에 붙여 넣으세요.
/*
* DIYables Bluetooth Library - ESP32 BLE Plotter Example
* Works with DIYables Bluetooth STEM app on Android and iOS
*
* This example demonstrates the Bluetooth Plotter feature:
* - Real-time data plotting via Bluetooth
* - Plot multiple data series simultaneously
* - Configurable plot settings
*
* Tutorial: https://diyables.io/bluetooth-app
* Author: DIYables
*/
#include <DIYables_BluetoothServer.h>
#include <DIYables_BluetoothPlotter.h>
#include <platforms/DIYables_Esp32BLE.h>
// BLE Configuration
const char* DEVICE_NAME = "ESP32BLE_Plotter";
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 instances
DIYables_Esp32BLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID);
DIYables_BluetoothServer bluetoothServer(bluetooth);
// Create Plotter app instance
DIYables_BluetoothPlotter bluetoothPlotter;
// Variables for generating sample data
unsigned long lastPlotTime = 0;
const unsigned long PLOT_INTERVAL = 100;
float phase = 0;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("DIYables Bluetooth - ESP32 BLE Plotter Example");
// Initialize Bluetooth server with platform-specific implementation
bluetoothServer.begin();
// Add plotter app to server
bluetoothServer.addApp(&bluetoothPlotter);
// Configure plotter settings
bluetoothPlotter.setPlotTitle("Sensor Data");
bluetoothPlotter.setAxisLabels("Time", "Value");
bluetoothPlotter.setYAxisRange(-15, 30);
bluetoothPlotter.setMaxSamples(100);
bluetoothPlotter.setLegendLabels("Sine", "Cosine", "Tangent");
// Set up connection event callbacks
bluetoothServer.setOnConnected([]() {
Serial.println("Bluetooth connected!");
});
bluetoothServer.setOnDisconnected([]() {
Serial.println("Bluetooth disconnected!");
});
bluetoothPlotter.onDataRequest([]() {
Serial.println("App requested plot data");
});
Serial.println("Waiting for Bluetooth connection...");
}
void loop() {
bluetoothServer.loop();
if (millis() - lastPlotTime >= PLOT_INTERVAL) {
lastPlotTime = millis();
float sine = sin(phase);
float cosine = cos(phase);
float tangent = tan(phase) * 0.3;
bluetoothPlotter.send(sine, cosine, tangent);
Serial.print(sine, 2);
Serial.print(" ");
Serial.print(cosine, 2);
Serial.print(" ");
Serial.println(tangent, 2);
phase += 0.1;
if (phase > 2 * PI) {
phase = 0;
}
}
delay(10);
}
- 업로드를 클릭하여 스케치를 보드에 플래시하세요.
- 시리얼 모니터를 열어주세요.
- 시리얼 모니터 출력은 다음과 같아야 합니다:
8
Serial.println("Hello World!");
Message (Enter to send message to 'Arduino Nano ESP32' on 'COM15')
New Line
9600 baud
DIYables Bluetooth - Plotter Example
Waiting for Bluetooth connection...
모바일 앱
참고: DIYables 블루투스 앱은 BLE를 통해 Android와 iOS 모두에서 작동합니다. 수동 페어링이 필요 없습니다.
- DIYables 블루투스 앱을 실행하세요.
- 처음 실행 시 다음 권한을 허용하세요:
- 근처 기기 (Android 12+) / 블루투스 (iOS) — 블루투스 기기 스캔 및 연결에 필요
- 위치 (Android 11 이하에만 해당) — 구형 Android 버전에서 BLE 스캔에 필요
- 기기에서 블루투스가 활성화되어 있는지 확인하세요.
- 홈 화면에서 연결을 탭하세요. 앱이 BLE 기기를 스캔합니다.

- 스캔 결과에서 "Arduino_Plotter"를 탭하세요.
- 연결 후 홈 화면으로 돌아가 플로터 앱을 여세요.

홈 화면의 설정 아이콘을 탭하여 앱을 표시하거나 숨길 수 있습니다. 자세한 내용은 DIYables 블루투스 앱 사용 설명서를 참조하세요.
- 사인, 코사인, 탄젠트 파형의 실시간 플롯이 나타납니다.

Arduino IDE의 시리얼 모니터를 다시 확인하면 다음과 같이 표시됩니다:
8
Serial.println("Hello World!");
Message (Enter to send message to 'Arduino Nano ESP32' on 'COM15')
New Line
9600 baud
Bluetooth connected!
Sending plot data...
Sine: 0.00, Cosine: 10.00, Tangent: 0.00
창의적인 커스터마이징 - 프로젝트에 코드 적용하기
플롯 외관 설정
// Set plot title
bluetoothPlotter.setPlotTitle("My Sensor Data");
// Set axis labels
bluetoothPlotter.setAxisLabels("Time", "Value");
// Set Y-axis range
bluetoothPlotter.setYAxisRange(-100, 100);
// Set maximum samples to display
bluetoothPlotter.setMaxSamples(200);
// Set legend labels for each channel
bluetoothPlotter.setLegendLabels("Temperature", "Humidity", "Pressure");
데이터 포인트 전송
// Send a single value
bluetoothPlotter.send(sensorValue);
// Send two values
bluetoothPlotter.send(temperature, humidity);
// Send three values
bluetoothPlotter.send(value1, value2, value3);
// Send up to six values
bluetoothPlotter.send(ch1, ch2, ch3, ch4, ch5, ch6);
데이터 요청 처리
bluetoothPlotter.onDataRequest([]() {
Serial.println("App requested data");
// App just connected or needs initial config
});
프로그래밍 예제
온도 및 습도 로거
DIYables_BluetoothPlotter bluetoothPlotter(bluetoothServer);
void setup() {
bluetoothPlotter.setPlotTitle("Environment Monitor");
bluetoothPlotter.setAxisLabels("Time", "Value");
bluetoothPlotter.setYAxisRange(0, 100);
bluetoothPlotter.setMaxSamples(100);
bluetoothPlotter.setLegendLabels("Temp (°C)", "Humidity (%)");
}
void loop() {
bluetoothServer.loop();
static unsigned long lastTime = 0;
if (millis() - lastTime >= 1000) {
lastTime = millis();
float temp = readTemperature();
float humidity = readHumidity();
bluetoothPlotter.send(temp, humidity);
}
}
아날로그 입력 플로터
void loop() {
bluetoothServer.loop();
static unsigned long lastTime = 0;
if (millis() - lastTime >= 100) {
lastTime = millis();
int a0 = analogRead(A0);
int a1 = analogRead(A1);
int a2 = analogRead(A2);
bluetoothPlotter.send(a0, a1, a2);
}
}
문제 해결
일반적인 문제
1. 앱에서 기기가 보이지 않음
- 보드에 전원이 공급되고 스케치가 업로드되었는지 확인하세요
- 스마트폰에서 블루투스가 활성화되어 있는지 확인하세요
- Android 11 이하에서는 위치 서비스도 활성화하세요
2. 플롯이 업데이트되지 않음
- 데이터가 loop() 내에서 전송되는지 확인하세요
- bluetoothServer.loop()가 호출되는지 확인하세요
- 앱이 플로터 화면에 있는지 확인하세요
3. 데이터가 잘못되거나 노이즈가 있음
- 센서 배선 및 읽기값을 확인하세요
- Y축 범위가 데이터 범위와 맞는지 확인하세요
- 데이터에 스무딩이나 필터링 적용을 고려하세요
4. 플롯 제목이나 레이블이 표시되지 않음
- 연결되기 전에 setup()에서 플롯 설정을 지정하세요
- 필요 시 onDataRequest 콜백을 사용하여 설정을 다시 전송하세요
5. 업로드 실패 또는 보드 인식 불가
- 보드 매니저를 통해 최신 Arduino Nano ESP32 보드 패키지를 설치하세요
- 다른 USB 케이블이나 포트를 시도해 보세요
프로젝트 아이디어
- 환경 모니터링 (온도, 습도, 기압)
- 가속도계/자이로스코프 데이터 시각화
- 아날로그 센서 보정 도구
- 신호 분석 및 비교
- 과학 실험 데이터 로거
다음 단계
블루투스 플로터 예제를 완료한 후 다음을 살펴보세요:
- 블루투스 테이블 — 구조화된 데이터 표시
- 블루투스 모니터 — 텍스트 기반 데이터 출력
- 블루투스 온도 — 게이지 스타일 온도 표시
- 블루투스 다중 앱 — 플로터와 다른 앱 위젯 결합