This project details constructing a practical and efficient automated lighting system using a DFRobot mmWave Human Detection Sensor, a DFRobot Beetle ESP32 C6 board, and a relay. This system offers a hands-free, energy-saving solution for various applications.
Use Case:Imagine a hallway in your home. Currently, you have to manually switch the light on and off every time you pass through 🚶♀️🚶♂️. This system automates this process, making it more convenient and energy-efficient. When you walk into the hallway, the sensor detects your presence, triggering the light to turn on. The light stays on briefly as you leave before automatically switching off, ensuring safety and conserving energy 🔋.
JLCPCB is a leading PCB prototype and fabrication manufacturer. Here’s why you should consider them for your next project:
Fast Turnaround: JLCPCB offers rapid PCB prototyping with build times as short as 24 hours. Whether you’re iterating on designs or need quick prototypes, they’ve got you covered.
Low Cost: Their pricing starts from just $2 for 1-4 layer PCBs (100x100mm size). Plus, they provide competitive rates for higher-layer counts.
Advanced Smart Factories: JLCPCB leverages fully automatic equipment and smart factories, ensuring both efficiency and quality.
PCB Assembly Services: Need assembly? JLCPCB offers PCB assembly starting at $8 for 5 PCs. They have over 560,000 in-stock parts and provide free DFM file checks.
Flex PCBs and Mechatronic Parts: They support flexible PCBs and offer mechatronic parts with cost savings of up to 68%.
Quality Assurance: Certified to ISO 9001:2015, ISO 14001:2015, and IPC-6012E standards, JLCPCB guarantees industry benchmarks.
Explore their services and experience the power of JLCPCB’s integrated solutions! 🚀
JLCPCB is Trusted by 5.4M Engineers Worldwide! Get a High-quality PCB Prototype for Just $2! Sign up to Get $80 Coupons: https://jlcpcb.com/?from=pradeep
Step 1️⃣ : Materials 🔧DFRobot mmWave Human Detection Sensor: This sensor uses millimeter-wave technology to detect movement and presence within a specified range. It provides accurate and reliable detection, even in low-light conditions 🔦.
DFRobot Beetle ESP32 C6: This microcontroller board is the brain of the system. It processes data from the sensor, controls the relay, and executes the desired logic. The ESP32 C6 offers powerful processing capabilities, Wi-Fi and Bluetooth connectivity, and a user-friendly development environment 💻.
Relay Module (5V): The relay acts as a switch, controlled by the ESP32 C6. It allows the microcontroller to control high-voltage devices like light fixtures, which are typically beyond the direct control of the ESP32.
Jumper Wires: These wires are used to connect the different components on the breadboard.
USB Cable: This is used to power the Beetle ESP32 C6 and upload the code.
Breadboard (optional): A breadboard provides a convenient way to connect the components temporarily for testing and prototyping.
Step 2️⃣ : Software 💻Arduino IDE (with ESP32 support): This is the development environment used to write and upload the code to the ESP32 C6.
Connect the mmWave Sensor:
- Connect the VCC pin of the sensor to the 5V pin on the Beetle ESP32 C6.
- Connect the GND pin of the sensor to the GND pin on the Beetle ESP32 C6.
- Connect the TX pin of the sensor to the RX pin on the Beetle ESP32 C6.
- Connect the RX pin of the sensor to the TX pin on the Beetle ESP32 C6.
Connect the Relay Module:
- Connect the VCC pin of the relay module to the 3.3 V pin on the Beetle ESP32 C6.
- Connect the GND pin of the relay module to the GND pin on the Beetle ESP32 C6.
- Connect the IN pin of the relay module to a digital output pin on the Beetle ESP32 C6 (e.g., GPIO 4).
Connect the Light Fixture:
- Connect the light fixture to the NO (Normally Open) terminal of the relay module.
- Connect the other terminal of the light fixture to the neutral wire of your power source.
#include "DFRobot_HumanDetection.h"
DFRobot_HumanDetection hu(&Serial1);
int led = 15;
int relay = 4;
void setup() {
pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, /*rx =*/17, /*tx =*/16);
Serial.println("Start initialization");
while (hu.begin() != 0) {
Serial.println("init error!!!");
delay(1000);
}
Serial.println("Initialization successful");
hu.configLEDLight(hu.eHPLed, 1); // Set HP LED switch, it will not light up even if the sensor detects a person when set to 0.
hu.sensorRet(); // Module reset, must perform sensorRet after setting data, otherwise the sensor may not be usabl
Serial.println();
Serial.println();
}
void loop() {
Serial.print("Existing information:");
switch (hu.smHumanData(hu.eHumanPresence)) {
case 0:
Serial.println("No one is present");
break;
case 1:
Serial.println("Someone is present");
break;
default:
Serial.println("Read error");
}
Serial.print("Motion information:");
switch (hu.smHumanData(hu.eHumanMovement)) {
case 0:
Serial.println("None");
break;
case 1:
Serial.println("Still");
break;
case 2:
Serial.println("Active");
break;
default:
Serial.println("Read error");
}
Serial.print("Body movement parameters: ");
Serial.println(hu.smHumanData(hu.eHumanMovingRange));
Serial.println("-----------------------");
if (hu.smHumanData(hu.eHumanMovingRange) > 1) {
digitalWrite(led, HIGH);
digitalWrite(relay, LOW);
}
else {
digitalWrite(led, LOW);
digitalWrite(relay, HIGH);
}
}
Step 5️⃣ : Explanation 🛡Libraries: The code includes the necessary libraries for the mmWave sensor.
#include "DFRobot_HumanDetection.h"
Pin Definitions: The code defines the pins used for the relay.
int led = 15;
int relay = 4;
Variables: The code defines variables to store human activity.
switch (hu.smHumanData(hu.eHumanPresence)) {
case 0:
Serial.println("No one is present");
break;
case 1:
Serial.println("Someone is present");
break;
default:
Serial.println("Read error");
}
Serial.print("Motion information:");
switch (hu.smHumanData(hu.eHumanMovement)) {
case 0:
Serial.println("None");
break;
case 1:
Serial.println("Still");
break;
case 2:
Serial.println("Active");
break;
default:
Serial.println("Read error");
}
Serial.print("Body movement parameters: ");
Serial.println(hu.smHumanData(hu.eHumanMovingRange));
Serial.println("-----------------------");
Setup Function:
- Initializes serial communication for debugging.
- Sets the relay pin as output and turns off the relay initially.
- Initializes the mmWave sensor with the correct UART port.
Loop Function:
- Reads the distance measurement from the sensor.
- Checks if a person is detected within the specified threshold. If yes, it turns on the relay (light on) and updates the last detection time.
- Check if the delay time has elapsed since the last detection. If yes, it turns off the relay (light off).
if (hu.smHumanData(hu.eHumanMovingRange) > 1) {
digitalWrite(led, HIGH);
digitalWrite(relay, LOW);
}
else {
digitalWrite(led, LOW);
digitalWrite(relay, HIGH);
}
Step 6️⃣ : Instructions 📃- Connect the components: Connect the sensor, relay module, and light fixture as described in the setup section.
- Upload the code: Upload the provided code to the Beetle ESP32 C6 using the Arduino IDE.
- Power up the system: Connect the Beetle ESP32 C6 to a power source using the USB cable.
- Test the system: Walk in front of the mmWave sensor. The light should turn on when you are detected and turn off after the delay time.
Distance Threshold: Adjust the threshold in the code (threshold < 1) to match the desired detection range.
Delay Time: Modify the delay time (delay time = 10000) to set the duration for which the light stays on after the last detection.
Multiple Lights: Expand the code to control multiple lights by adding additional relay modules and corresponding pins.
Dimming: Incorporate a dimming feature by using a PWM output pin to control the brightness of the light fixture.
Color Changing: Integrate a color-changing LED strip and control its color based on the detection events.
Step 8️⃣ : Note 💫- This project is a basic example and can be further customized to suit your specific requirements.
- Ensure that the power supply for the relay module and the light fixture is appropriate.
- Always follow proper safety precautions when working with electrical components.
This project successfully demonstrated the creation of an automated light system using a DFRobot mmWave Human Detection Sensor, a DFRobot Beetle ESP32 C6 board, and a relay. By combining these components, we were able to build a system that automatically turns on a light when a person is detected and turns it off after a set delay when no one is present. 💡
This project highlights the potential of using readily available technology to create practical and efficient solutions for everyday problems. The automated lighting system offers numerous benefits, including:
Convenience: No more manually switching lights on and off, making life easier and more comfortable. 🚶♀️🚶♂️
Energy Efficiency: The system only turns on the light when needed, reducing energy consumption and saving money. 🔋
Safety: The light automatically turns on when someone enters a room, improving visibility and reducing the risk of accidents. 🚧
Furthermore, the project provides a solid foundation for further experimentation and customization. By modifying the code and adding additional features, you can expand the functionality of the system to control multiple lights, dim the brightness, change the color of the light, or even integrate with other smart home devices. 🏠
This project serves as a valuable example of how technology can be used to improve our lives and create a more efficient and sustainable future. With its simplicity, versatility, and potential for further development, this automated lighting system is a great starting point for anyone interested in exploring the world of smart home automation. 🤖
Comments
Please log in or sign up to comment.