Wireless Notes
Complete Bluetooth LED control project using BLE ESP32, RGB LED, GATT profile, and mobile app with step-by-step guide demonstrating BLE wireless communication concepts for beginners.
Build a complete Bluetooth Low Energy (BLE) project that lets you control RGB LEDs from your smartphone. This hands-on project demonstrates core BLE concepts including GATT services, characteristics, advertising, and low-power wireless communication.
Project Overview and Objectives
| Aspect | Detail |
|---|---|
| Objective | Control RGB LED colors via phone over BLE |
| Technology | Bluetooth Low Energy (BLE 5.0) |
| Hardware | ESP32 DevKit, Common Cathode RGB LED, 3x 220Ω resistors, Breadboard, Jumper wires |
| Software | Arduino IDE 2.0+, nRF Connect app (Android/iOS) |
| Key Concepts | BLE services, characteristics, GATT profile, advertising, frequency hopping |
| Difficulty | Beginner |
| Estimated Time | 4-6 hours |
The primary learning goal here is not just making an LED glow — it is understanding the wireless protocol stack that makes the communication possible. Every smartphone interaction with a BLE device follows the same architecture we will implement.
Understanding BLE Architecture
Before we start building, let us understand the BLE communication model. BLE operates very differently from classic Bluetooth. While classic Bluetooth maintains a continuous connection (like a phone call), BLE works in short bursts (like sending text messages). This is why your fitness tracker battery lasts months instead of hours.
BLE Protocol Stack
BLE uses a layered architecture. At the bottom, the Physical Layer operates in the 2.4 GHz ISM band, using 40 channels with 2 MHz spacing. Above that, the Link Layer handles advertising, scanning, and connection management. The most important layer for our project is the Generic Attribute Profile (GATT), which defines how data is organized and exchanged.
GATT Structure Explained
GATT organizes data in a hierarchical structure. Think of it like a filing cabinet. A Profile contains one or more Services (like drawers in the cabinet). Each Service contains Characteristics (like folders in the drawer). Each Characteristic holds actual data values (like documents in the folder).
| ├── Service | "LED Control" (Custom UUID: 12345678-1234-1234-1234-123456789abc) |
| │ ├── Characteristic | "Color" (UUID: ...01) |
| │ │ └── Value | [R, G, B] (3 bytes, 0-255 each) |
| │ ├── Characteristic | "Power" (UUID: ...02) |
| │ │ └── Value | [0 or 1] (1 byte, ON/OFF) |
| │ └── Characteristic | "Brightness" (UUID: ...03) |
| │ └── Value | [0-100] (1 byte, percentage) |
Hardware Circuit Design
Components Required
| Component | Quantity | Purpose |
|---|---|---|
| ESP32 DevKit V1 | 1 | BLE-capable microcontroller |
| Common Cathode RGB LED | 1 | Visual output with color mixing |
| 220Ω Resistors | 3 | Current limiting for each LED color |
| Breadboard | 1 | Prototyping connections |
| Jumper Wires | 6-8 | Circuit connections |
| USB Cable | 1 | Programming and power |
Circuit Connections
The RGB LED has four pins: one common cathode (ground) and three anodes for Red, Green, and Blue. Each anode connects through a 220Ω current-limiting resistor to an ESP32 GPIO pin. We use GPIO 25 for Red, GPIO 26 for Green, and GPIO 27 for Blue. The common cathode connects directly to ESP32 GND.
The current limiting resistor is essential. Without it, the LED would draw excessive current and potentially damage both the LED and the ESP32 GPIO pin. At 3.3V with a 220Ω resistor, each channel draws approximately 15mA, which is well within the ESP32's 40mA per-pin limit.
Software Implementation
Arduino IDE Setup
First, install the ESP32 board package in Arduino IDE. Go to File → Preferences → Additional Board Manager URLs and add the Espressif URL. Then install "ESP32 by Espressif Systems" from the Board Manager. Select "ESP32 Dev Module" as your board.
BLE Server Code Structure
The code creates a BLE server on the ESP32 that advertises itself and waits for a phone to connect. Here is the logical flow:
- Initialize BLE — Set device name and create server
- Create Service — Define our custom LED Control service with its UUID
- Add Characteristics — Create Color, Power, and Brightness characteristics with Read/Write properties
- Start Advertising — Begin broadcasting so phones can discover us
- Handle Callbacks — When phone writes new values, update the LED accordingly
Key Code Concepts
The BLE library uses callback classes to handle events. When a client (your phone) writes a new color value to the Color characteristic, the onWrite callback fires. Inside this callback, we parse the three bytes (R, G, B) and apply them to the LED using PWM (Pulse Width Modulation) via the analogWrite function.
PWM is crucial here because LEDs are either ON or OFF — there is no "half brightness" in hardware. PWM rapidly switches the LED on and off. A 50% duty cycle means the LED is on half the time, appearing at 50% brightness to our eyes. The ESP32 supports 8-bit PWM resolution, giving us 256 brightness levels (0-255) per color channel.
BLE Communication Flow
Here is what happens when you tap a color on your phone:
- Phone scans — Discovers ESP32 advertising as "LED_Controller"
- Connection established — Phone becomes the Central, ESP32 is the Peripheral
- Service discovery — Phone reads the GATT table to find available services
- Write operation — Phone writes RGB values [255, 0, 128] to Color characteristic
- Callback triggered — ESP32's onWrite function executes
- LED updates — PWM outputs change, LED displays purple (Red + Blue mix)
The entire process from tap to LED color change takes approximately 7.5 milliseconds on BLE 5.0 — faster than human perception.
Wireless Concepts Demonstrated
| Concept | How It Appears in This Project |
|---|---|
| BLE Advertising | ESP32 broadcasts packets every 100ms until phone connects |
| GATT Protocol | Hierarchical Service/Characteristic data organization |
| 2.4 GHz ISM Band | Shared unlicensed spectrum, same as WiFi |
| Frequency Hopping | BLE hops across 37 data channels to avoid interference |
| Low Power Design | BLE sleeps between connection events, extending battery life |
| Connection Intervals | Negotiated timing between phone and ESP32 (7.5ms to 4s) |
| MTU Negotiation | Maximum data packet size agreed during connection |
Testing with nRF Connect App
The nRF Connect app (by Nordic Semiconductor) is the best tool for BLE development. After uploading code to ESP32, open nRF Connect on your phone. You will see "LED_Controller" in the scan results. Tap Connect, then navigate to the custom service. You can write hex values directly to characteristics.
For example, writing FF0000 to the Color characteristic should turn the LED pure red. Writing 00FF00 gives green, and 0000FF gives blue. Writing FF00FF produces magenta through additive color mixing.
Troubleshooting Common Issues
| Problem | Likely Cause | Solution |
|---|---|---|
| Device not appearing in scan | Advertising not started | Check BLE initialization sequence |
| LED not lighting up | Wrong pin connections | Verify GPIO numbers match code |
| Only one color works | Resistor missing on other channels | Check all three resistor connections |
| Connection drops frequently | Interference from WiFi | Move away from WiFi router |
| Dim LED output | High resistance value | Use 220Ω instead of 1kΩ |
Extensions and Improvements
Once the basic project works, consider these enhancements to deepen your learning:
- Custom mobile app — Build an Android app with MIT App Inventor or Flutter that shows a color wheel
- Multiple LEDs — Control an LED strip using WS2812B addressable LEDs
- Animations — Add a characteristic for pattern selection (breathing, rainbow, strobe)
- Security — Implement BLE pairing with passkey authentication
- Power optimization — Add deep sleep mode when no client is connected for 5 minutes
Key Takeaways
- BLE operates fundamentally differently from classic Bluetooth — designed for low power, intermittent data transfer
- GATT provides a standardized way to organize and exchange data between BLE devices
- The Central (phone) initiates connections; the Peripheral (ESP32) advertises and waits
- Frequency hopping across 40 channels provides robustness against interference
- PWM enables smooth brightness control despite LEDs being binary (on/off) devices
- BLE 5.0 supports data rates up to 2 Mbps, but our project needs minimal bandwidth
- The same architecture powers commercial products like smart bulbs, fitness trackers, and wireless sensors
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Bluetooth LED Control Project BLE Arduino ESP32 App.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Wireless Communications topic.
Search Terms
wireless-communications, wireless communications, wireless, communications, projects, bluetooth, led, control
Related Wireless Communications Topics