ESP32

Smart Staircase Lighting with ESP32 and mmWave Sensor | Motion-Activated LED Strip

Smart Staircase Lighting:

Smart Staircase Lighting with ESP32 and mmWave Sensor | Motion-Activated LED Strip- Since I published an article on the RD-03E mmWave Radar module, many people have requested that I use this sensor in a home automation project.




So today, let’s build a smart staircase lighting control system using the ESP32 WiFi + Bluetooth module, RD-03E mmWave sensor, and WS2811 RGB LED strip.

allpcb circuit

Smart Staircase Lighting with esp32 and mmwave sensor motion activated led strip

In this project, lights will move along with the person, making it an intermediate-level project. That’s why we will follow a step-by-step approach:

  • First, we will install the required libraries and learn how to control the RGB LED strip.
  • In Example 2, we will integrate hand gesture recognition, allowing us to switch between different colors without touching any buttons.
  • In Example 3, we’ll turn the RGB LED strip ON/OFF based on a person’s distance from the mmWave Radar module.
  • Finally, in Example 4, we are going to create a dynamic lighting system where the WS2811 RGB LED strip will light up and move along with the person as they approach or move away from the RD-03E mmWave Sensor.

So, without any further delay let’s get started!!!



Amazon Links:

RD-03E mmWave Radar Module

ESP32 WiFi + Bluetooth Module

WS2811 RGB LED Strip

Other Tools and Components:

ESP32 WiFi + Bluetooth Module (Recommended)

Arduino Nano USB C type (Recommended)

*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!

Before starting the projects, let me tell you that I have already made detailed getting started videos on the RD-03E mmWave Sensor, WS2811 RGB LED Strip, and the ESP32 Development Board, which are available on my YouTube channel “Electronic Clinic”.

RD-03E mmWave Sensor Interfacing:

Connect the OT1 and RX pins of RD-03E mmWave sensor to the ESP32 GPIO’s 16 and 17 respectively. And connect the VCC and GND pins to the 5V and GND pins on the ESP32. For the wiring you can follow this circuit diagram.

Smart Staircase Lighting using esp32 and rd 03e mmwave sensor circuit diagram



WS2811 RGB LED Strip Interfacing:

Connect the RED and WHITE wires of the WS2811 RGB LED Strip to the 12V power supply. And also connect its ground wire to the ESP32 ground. All the grounds should be connected together.

And connect the Data-in wire to the ESP32 GPIO 12.

Smart Staircase Lighting and rgb led strip with esp32 interfacing

5V Relay interfacing:

On this ESP32 development board, you can see I have also a 5V SPDT type relay. Its connected to the GPIO 13 on the ESP32. For the relay wiring you can follow this circuit diagram.

Smart Staircase Lighting and 5v relay with esp32 circuit diagram

I have already explained the sensor orientation and installation in great detail in my first article on the RD-03E mmWave Radar module.

Smart Staircase Lighting mmwave sensor rd 03e esp32 rgb led strip wiring

Anyways, this basic setup is sufficient for me. So, let’s go ahead and start with our first example.



Example 1: ESP32 & WS2811 RGB LED Strip

The purpose of Example 1 is to control an RGB LED strip using the ESP32.

In this example, we are not using the mmWave sensor.

For projects that involve multiple components, the best approach is to get each component working individually first and then, in the end, combine everything into the final code.

Programming:

First of all, you need to install the FastLED library in the Arduino IDE. For this,

  1. Copy the library name and
  2. Then go to the LIBRARY MANAGER and
  3. Paste the library name.

install fastled library for the led strip ws2811 Smart Staircase Lighting

You can see, I have already installed this library make sure to install the latest version.




ESP32 RGB LED Strip Code:

This is the same code, I used with the Arduino. I only changed the pin number. Rest of the code is exactly the same, I didn’t even change a single line of code.



ESP32 and RGB LED Strip in Action:

As you can see, we are successfully controlling the WS2811 RGB LED Strip using the ESP32.

ws2811 rgb led strip with esp32 Smart Staircase Lighting

This means that both our wiring and code are working correctly. Now, we can move on to Example 2.

Example 2: RGB LED Strip Color Change using mmWave Sensor

In Example 2, we will control the RGB LED strip using hand gestures with the RD-03E mmWave Radar module.

Color Change Code:



RGB LED Strip Color Change Code Explanation:

First, we include HardwareSerial header to communicate with the RD-03E mmWave sensor.
Then, we bring in FastLED library to control the WS2811 RGB LED strip.

Defining Serial Communication Pins

The mmWave sensor sends data over UART (Serial).
We define which ESP32 pins will receive (RX) and transmit (TX) data.

We create a HardwareSerial object to handle communication with the sensor.
The (1) means we are using **Serial1** (not the default Serial0).

Setting Up the LED Strip

We create an **array** to store the LED colors.
colorIndex helps us keep track of which color is currently active.

Defining Colors

We create an **array of colors** (Red, Green, Blue, etc.).
numColors calculates how many colors we have in colorList.

Setup Function (Runs Once)

Starts the **Serial monitor** for debugging.
Initializes the **RD-03E sensor** at a high baud rate (256000).
Sets up the **LED strip**, applies brightness, clears it, and updates.



Reading Data from the Sensor

headerDetected ensures we only process valid sensor data.
frameData[5] will store **5 bytes** from the radar module.
byteIndex keeps track of received bytes.

Calls readDistanceAndGesture() every 100ms.
Keeps checking for new radar data and updating the LED strip.

Practical demonstration:

Just by using hand gestures, I can switch between colors; there’s no need to press any button.

hand gesture controlled rgb led strip using mmwave sensor and esp32 Smart Staircase Lighting

Simply moving my hand up and down in front of the mmWave sensor allows me to change the colors.




Example 3: Staircase RGB LED Strip and mmWave Sensor

In Example 3, we will turn the RGB LED strip ON/OFF based on a person’s distance.

Let’s imagine that this LED strip is installed on a staircase. When someone enters the sensor’s range, the LED strip will turn ON; otherwise, it will remain OFF.

Additionally, we will use hand gesture to control a relay, which can be used to switch other loads as well.

Staircase RGB LED Strip Code:

I have made some changes to the code. If you carefully study it, you will understand how it works.



Staircase RGB LED Strip Code Explanation:

  1. Include Libraries

HardwareSerial Used for Serial communication with the RD-03E radar module.

FastLED Used to control the WS2811 RGB LED strip.

  1. Define Pins and Variables

 RX (16) and TX (17) are used for radar module communication.

 LED_PIN (12) controls the WS2811 LED strip.

CONTROL_PIN (13) is used to toggle an external device.

Various flags and timers are defined to handle LED and device control logic.

  1. Setup Function

Initializes Serial communication.

Sets up the FastLED library for LED strip control.

Configures GPIO 13 as an output.

  1. readDistanceAndGesture() Function

Reads data from the RD-03E mmWave sensor.

Extracts distance and gesture information.

If a gesture (0x01) is detected, toggles GPIO 13.

If a person is detected within the 0.4m – 3m range, turns the LED strip ON.

If the person moves out of range for 2 seconds, turns the LED strip OFF.

  1. Loop Function

Calls readDistanceAndGesture() repeatedly to continuously process sensor data.



Practical demonstration:

As you can see, as soon as I enter the pre-defined range, the RGB LED strip automatically turns ON and stays ON as long as I remain within the specified range. When I move out of the sensor’s range, the LED strip automatically turns OFF.

fully automated Smart Staircase Lighting using mmwave sensor

I have tested this multiple times, and there was no false triggering. For best sensor performance, make sure to fix the mmWave sensor securely to prevent any vibrations.

I also controlled the relay using hand gesture and it worked exceptionally well, you can watch it in the video given below.

Now, let’s move on to Example 4.

Example 4: Smart Staircase Lighting

In this 4th and final example, we will make the LEDs follow the person’s movement, creating an animation effect that mimics a walking path illumination

Additionally, we will use hand gestures to activate and deactivate the LED strip. You will clearly understand everything during the practical demonstration. I highly recommend to watch the video given at the end of this article.



Smart Staircase Lighting Programming:

The code is a bit long, but I have added comments with instructions, so you shouldn’t have any difficulty understanding it.

there are a few variables I need to explain so that you don’t face any confusion.

Some LEDs are behind the sensor (not useful for lighting your path); so, this variable prevents those LEDs from being turned ON.

These are the remaining LEDs in front of the sensor that we will actually control.

The RD-03E mmWave sensor cannot detect objects within the first 50 cm reliably.

Any distance below 50 cm is ignored.

The first LED turns ON at 51 cm (after the blind spot).

The maximum distance considered for LEDs control.

Any object beyond (233 cm) is ignored. You can increase or decrease this maximum distance value as per your needs.

For every 8 cm, one more LED lights up.

Now let’s watch the RD-03E mmWave Sensor and RGB LED strip based Smart Staircase Lighting control system in action.




Practical Demonstration:

As you can see, when I move in front of the sensor, the LED strip is not turning ON. This is because the LED strip is currently deactivated.

rgb led strip esp32 and mmwave sensor for Smart Staircase Lighting

So, let’s turn it ON using a hand gesture.

Now, as I move forward and backward, the LEDs will turn ON/OFF accordingly.

Smart Staircase Lighting esp32 mmwave sensor

You can modify the code as per your requirements. I’m sure you now understand how we can use the mmWave sensor to control RGB LED strips.

So, that’s all for now.



Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

Leave a Reply

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

Back to top button