ESP32 Proximity-Based Led Control: Creating an Electronic Key using BLE Earbuds RSSI Technology


ESP32 Proximity-Based Led Control: Creating an Electronic Key using BLE Earbuds RSSI Technology- This is my second article on the ESP32 Bluetooth Low Energy (BLE) technology. In the previous article, I showed you how to control LEDs using a custom-made BLE Android application. In this article, I’m going to create an electronic key, and this piece promises to be incredibly useful. Here, I will be utilizing a new technology feature called RSSI. With the help of RSSI values, we can develop a home appliance control system. However, for this article, I will focus on a simpler project: turning an LED on and off. This project will involve using the ESP32’s built-in BLE alongside earbuds. When the activated earbuds come within the range of the ESP32 Bluetooth RSSI, the LEDs will light up. Conversely, when the earbuds move out of range, the LEDs will turn off. We’ll set this range according to our preference using the RSSI values, ensuring the LEDs light up only within the desired proximity. So, let’s get started on this exciting project.

About ESP32 Built-in BLE(Bluetooth low energy):

ESP32 Proximity-Based Led Control

The ESP32, a powerhouse in the world of IoT (Internet of Things), comes equipped with built-in BLE (Bluetooth Low Energy) capabilities, marking it as a highly versatile and efficient choice for modern wireless applications. This feature-rich module has garnered attention for its robust performance and multifaceted uses in various domains, from home automation to industrial control systems.


Bluetooth Version: The ESP32 supports Bluetooth v4.2 BR/EDR and BLE standards, ensuring compatibility with a wide range of BLE devices and providing backward compatibility with classic Bluetooth.

Low Energy Consumption: As the name suggests, BLE in ESP32 is designed for minimal power consumption, making it an ideal choice for battery-operated or power-sensitive applications.

Data Rate and Range: BLE on the ESP32 offers a data rate of up to 2 Mbps and a range that can extend up to 50-100 meters in open spaces, striking a balance between power efficiency and communication reach.

Modulation Capabilities: It supports Gaussian Frequency-Shift Keying (GFSK) modulation, enhancing the stability and reliability of wireless communication.

Security Features: The ESP32 BLE includes support for AES-128 encryption, ensuring secure communication and safeguarding data from unauthorized access.


Multiple Roles Support: The ESP32 can act as both a BLE client and a BLE server, enabling a wide array of use cases. As a server, it can broadcast data and respond to requests, while as a client, it can scan, connect, and exchange data with BLE devices.

Energy-Saving Modes: It features various energy-saving modes like deep sleep and light sleep, which are essential for extending battery life in IoT applications.

Integrated Antenna: The ESP32 comes with an integrated antenna and RF balun, a factor that simplifies the design and development process for wireless systems.

Broad Application Scope: BLE functionality on the ESP32 lends itself well to applications like wearables, smart home devices, health monitoring systems, and proximity sensing solutions.

Robust IoT Ecosystem: Thanks to its BLE feature, the ESP32 seamlessly integrates with other IoT technologies, enabling the creation of interconnected, smart environments.

Ease of Development: The availability of extensive development tools and a supportive community makes working with the ESP32’s BLE feature accessible for developers of all skill levels.

In essence, the ESP32 with its BLE capability is not just a module; it’s a gateway to the future of wireless technology, embodying efficiency, versatility, and security. Its specifications and features make it a go-to choice for innovators and developers looking to create cutting-edge, low-power, and highly connected solutions.

About Bluetooth Low Energy RSSI: Functionality and Features

Bluetooth Low Energy (BLE), a pivotal technology in the world of wireless communication, employs the Received Signal Strength Indicator (RSSI) as a core metric.

Understanding How BLE RSSI Works

RSSI in the context of BLE provides a measurement of the signal strength received by a BLE device. Expressed in decibels relative to a milliwatt (dBm), this metric is crucial in determining the proximity and connection quality between BLE devices. The working mechanism of BLE RSSI involves several steps:

Signal Reception: As a BLE device receives a signal from another BLE-enabled device, it measures the strength of this incoming signal.

RSSI Value Calculation: The BLE device computes the RSSI value, reflecting the power of the received signal. Typically, the value ranges from -100 dBm (weak signal) to 0 dBm (strong signal).

Signal Strength Interpretation: The calculated RSSI value provides an insight into the signal strength, where a value closer to 0 indicates a stronger signal, essential for establishing a robust BLE connection.

Dynamic Adaptation: BLE devices can dynamically adapt their behaviors based on RSSI values, optimizing connection stability and power efficiency.

Features of BLE RSSI

Proximity Detection: BLE RSSI is widely used for proximity detection in applications like smart key finders, indoor navigation, and contextual location-based services. It allows devices to estimate their relative distance based on signal strength.

Connection Optimization: By monitoring RSSI values, BLE devices can optimize their connection parameters like transmission power and data rate, ensuring efficient communication and battery usage.

Beacon Functionality: In BLE beacon technology, RSSI plays a crucial role in determining the proximity of beacons to receiving devices, enabling applications like retail marketing and asset tracking.

Network Topology Management: BLE mesh networks leverage RSSI to manage network topology, helping in routing decisions and enhancing overall network performance.

Signal Quality Assessment: RSSI is used to assess the quality of BLE links, which is fundamental in scenarios where stable and reliable communication is critical.

User Experience Improvement: Applications that rely on BLE, such as wearable devices and smart home gadgets, use RSSI to improve user experience by ensuring seamless connectivity and interaction.

Energy-Saving Strategies: BLE devices can employ RSSI-based strategies to enter low-power modes when out of range, contributing to energy conservation.

In summary, BLE RSSI stands as a vital component in the BLE ecosystem. Its ability to measure signal strength and aid in proximity estimation elevates the functionality of BLE devices, making them smarter and more efficient. From enhancing user experience to optimizing network performance, the role of RSSI in BLE technology is multifaceted and indispensable in the era of IoT and wireless connectivity.

Difference between Classic Bluetooth and Bluetooth Low Energy (BLE)

ESP32 Proximity-Based Led Control

Bluetooth technology has evolved significantly since its inception, branching into Classic Bluetooth and Bluetooth Low Energy (BLE). Each serves distinct purposes and is tailored to different applications. Below is an overview of their differences, followed by a comparative table.

Classic Bluetooth

Classic Bluetooth, often simply referred to as Bluetooth, is designed for continuous, high-speed data transmission. It’s ideal for applications that require consistent data streaming, such as audio streaming in headsets or file transfers between devices. Classic Bluetooth consumes more power due to its higher data rate and continuous connection.

Bluetooth Low Energy (BLE)

Bluetooth Low Energy, a subset of Bluetooth 4.0 and later versions, is optimized for low power consumption and short bursts of data transmission. It’s particularly suited for applications where energy efficiency is paramount, like in wearable devices, health monitors, and smart home products. BLE devices can operate for months or even years on small batteries due to their low power usage.

Feature Classic Bluetooth Bluetooth Low Energy (BLE)
Range Generally up to 100 meters (Class 1 devices) Similar, but optimized for shorter ranges
Data Rate Up to 2-3 Mbps Up to 1 Mbps
Application Throughput Higher, suitable for continuous data streaming Lower, optimized for small packets of data
Active Slaves Supports multiple active slaves (7+ in a piconet) Typically single connection with lighter overhead
Frequency Operates at 2.4 GHz ISM band Same, 2.4 GHz ISM band
Security Secure, with various authentication and encryption modes Similar security features with LE Secure Connections
Robustness Good interference handling Enhanced with adaptive frequency hopping
Latency Typically around 100 ms 6 ms to 30 ms, lower latency for quick operations
Time Lag Noticeable in some applications (e.g., audio/video sync) Reduced time lag, suitable for real-time applications
Voice Capable Yes, widely used for audio transmission Not inherently designed for voice transmission
Network Topology Point-to-point, broadcasting, supports scatternet Point-to-point, broadcasting, and mesh networking
Power Consumption Higher due to continuous connectivity Significantly lower, optimized for battery life
Peak Current Consumption Higher, depends on usage Lower, ideal for devices with small batteries

About Proximity-Based Led Control Project:

This project ingeniously combines the capabilities of the ESP32 microcontroller, renowned for its Bluetooth Low Energy (BLE) features, with the unique use of earbuds as an electronic key to control LEDs. The cornerstone of this project is the utilization of RSSI (Received Signal Strength Indicator) technology, a method that harnesses the power of signal strength to trigger actions in smart devices.

The ESP32 microcontroller is at the heart of this venture. Known for its compactness, efficiency, and BLE support, the ESP32 is an ideal choice for projects requiring wireless communication and low power consumption. Its BLE functionality is particularly crucial for this project, as it allows for seamless communication with the earbuds, which act as the key in this innovative setup.

The earbuds, an everyday accessory, are repurposed in this project to serve as a smart key. When paired with the ESP32 via BLE, the earbuds’ presence and proximity are detected based on their RSSI values. RSSI, a metric that measures the strength of a wireless signal received from any device, is pivotal in determining how close the earbuds are to the ESP32. In this setup, as the earbuds come within a predefined range of the ESP32, the RSSI value reaches a threshold that triggers the LEDs to turn on.

This project is not just a demonstration of controlling LEDs. It is a foray into the potential of RSSI in everyday applications. By setting different RSSI thresholds, one could control when the LEDs light up or turn off, creating a dynamic and interactive environment. This has practical applications in various fields, such as home automation, where the presence of a person (carrying the earbuds) in a room could automatically trigger lighting, thereby enhancing energy efficiency and user convenience.

Moreover, the project underscores the versatility of the ESP32 and the practicality of using RSSI for proximity detection. It’s a proof of concept that simple, everyday items like earbuds can be transformed into smart, interactive tools. The “BLE Electronic Key” project, therefore, stands as an innovative blend of technology and creativity, opening doors to new possibilities in the world of smart devices and home automation.


ESP32 Microcontroller

LED (Light Emitting Diode)


Connection Wires



*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

ESP32 Proximity-Based Led Control Circuit diagram:

ESP32 Proximity-Based Led Control

In this circuit, I am using an ESP32 microcontroller to control an LED using BLE earbuds rssi. Here’s how the connections are set up:

The longer leg (anode) of the LED is connected to the GPIO pin of the ESP32 (in this case, it is connected with GPIO 27) via a yellow wire. This GPIO pin will be set as an output and toggled high or low in the ESP32 code to turn the LED on or off.

The shorter leg (cathode) of the LED is connected to one end of the 330ohm resistor.

The other end of the resistor is connected to the ground (GND) pin on the ESP32 via the black wire.

When the ESP32 receives a signal from the earbuds that meets the RSSI threshold criteria, it will execute the code to set the GPIO pin high, providing voltage to the LED and illuminating it. When the earbuds are out of range, the GPIO pin will be set low, cutting off the voltage to the LED, causing it to turn off.

The exact value of the resistor can vary depending on the LED’s requirements and the voltage provided by the ESP32 GPIO pin. Typically, a 220-ohm to 1-kilohm resistor is used for standard LEDs with a 3.3V supply from the ESP32.

ESP32 Proximity-Based Led Control Program:

Code Explanation:

This Arduino sketch is designed to use ESP32 built-in Bluetooth Low Energy (BLE) technology to locate a specific BLE-enabled device, like earbuds, and control an LED based on the signal strength from that device. The program begins by including the necessary BLEDevice.h library for BLE functions. It then defines the LED’s pin number and sets the Bluetooth address of the target device, which in this case is an address representing earbuds. Additionally, it establishes an RSSI (Received Signal Strength Indicator) threshold that determines whether the LED should be on or off depending on the signal strength.

In the setup() function, which runs once at startup, the LED pin is set as an output, and serial communication is initiated for debugging and monitoring purposes. The BLE functionality is also initialized here. The core of the program lies in the loop() function, which continuously repeats after setup(). It creates a BLE scanner and sets it to actively scan for better speed, though this consumes more power. The Arduino then scans for BLE devices for a short duration of 3 seconds.

During this scan, if the program finds a device whose address matches the predefined Earbuds’ address, it checks the signal strength (RSSI). If the RSSI is above the set threshold, indicating proximity, the LED is turned on. Otherwise, the LED remains off. If the specific device isn’t found in the scan, the LED is turned off. After each scanning cycle, there’s a brief pause of 100 milliseconds before the next scan begins. This continuous scanning process serves to monitor the presence of the specified device and visually indicate its proximity through the LED’s state.

Practical Demonstration:

Let’s now test the project, as you can see, I have connected my components as per the circuit diagram. You can see the LED is off because the earbuds have not been activated yet.

ESP32 Proximity-Based Led Control

And when the earbuds are activated, the LED turns on, as you can see.

ESP32 Proximity-Based Led Control



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button