Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversFall ResetAmazon USFall reset deals: check better picks before checkoutAmazon US: today's deals, useful picks and quick comparisons.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Blog

ESP32 Smart Home Motion-Activated Lighting System: A Safe, Flexible DIY Build

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

An ESP32 motion-activated lighting system can turn a hallway, stairwell, closet, bathroom, or utility area on when movement is detected and off after inactivity. The most practical design is an ESP32 running ESPHome, connected to a PIR or mmWave sensor and a low-voltage LED driver. Home Assistant is optional: it adds schedules, dashboards, scenes, multiple lights, and brightness rules, while the ESP32 can still perform the basic local action.

For a first installation, use a low-voltage LED strip or lamp controlled through a logic-level MOSFET. Do not connect an LED strip directly to an ESP32 GPIO, and do not treat an uncertified relay module as a safe mains-voltage installation.

What the system should do

Define the behavior before choosing hardware:

  • Motion turns the light on.
  • Continued movement keeps it on.
  • A configurable period without motion turns it off.
  • The light may operate only when the room is dark.
  • Brightness may change between daytime, evening, and overnight.
  • A manual button or override can keep the light on or temporarily disable automation.
  • Basic operation should continue during a Home Assistant, internet, or Wi-Fi outage whenever immediate local lighting matters.

A PIR sensor detects movement-related changes, not guaranteed occupancy. Someone sitting still may eventually be treated as inactive. If that is unacceptable, use an mmWave presence sensor or combine mmWave with PIR.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the architecture

Requirement Standalone ESP32 ESPHome + Home Assistant
Works when Home Assistant is offline Yes Only if local fallback logic is included
Works without Wi-Fi Yes after provisioning Local device logic can still run, but hub communication cannot
Multi-room coordination Limited Excellent
Schedules, scenes, dashboards, and history Limited Yes
Initial complexity Lower Higher
Best use One room or one light Whole-home automation

These designs are not mutually exclusive. Put the fast motion-to-light behavior on the ESP32, then let Home Assistant add night rules, occupancy logic, centralized control, and scenes. ESPHome devices use a native API connection with Home Assistant rather than relying only on periodic polling. See the Home Assistant blueprint documentation for reusable automation templates.

#1 Best Overall
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (3PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • ESP32 is a safe, reliable, and scalable to a variety of applications

Choose the sensor

PIR: the best first build

A PIR sensor is inexpensive, low-power, and simple to connect to a GPIO input. It works well in hallways, stairways, closets, and other pass-through areas where people are expected to move.

PIR limitations include missed detection when someone remains still, sensitivity to placement and temperature, and false triggers from sunlight, HVAC airflow, radiators, curtains, or pets. Mount it so people cross its detection zones rather than walk directly toward it.

mmWave: better for stationary occupants

mmWave presence sensors can detect people more continuously than PIR and are better suited to bathrooms, bedrooms, offices, and rooms where someone may sit still. ESPHome documents radar-related devices including LD2410, LD2450, LD2412, DFRobot radar, and Seeed mmWave devices in its component catalog.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

mmWave sensors cost more, often use UART, require tuning, and can detect activity outside the intended zone. Room geometry and reflective surfaces affect results. Choose mmWave when “the light turns off while I am still here” is the main problem; do not assume it is automatically better for every room.

Hardware for a safe low-voltage build

Required parts

  • ESP32 development board, such as an ESP32-DevKitC or compatible board.
  • PIR sensor with an output voltage compatible with the selected ESP32 input.
  • 5-V or 12-V LED strip, puck light, or lamp.
  • Logic-level N-channel MOSFET module suitable for the LED voltage and maximum current.
  • Separate regulated power supply sized for the LED load.
  • Inline fuse close to the low-voltage power source.
  • Enclosure, terminal connectors, and appropriately sized wiring.

Espressif describes the ESP32-DevKitC as an entry-level development platform with accessible GPIO and USB prototyping support. “ESP32” is a family, not one universal board: verify the exact board pinout, bootstrapping pins, voltage regulation, and available GPIO before wiring.

Optional parts

  • LDR, BH1750, or another ambient-light sensor for lux-based activation.
  • Physical push button for manual hold or disable control.
  • mmWave sensor for presence detection.
  • Level shifter when the chosen LED technology requires a higher logic-level signal.

Wiring the low-voltage circuit

PIR wiring

A typical arrangement is:

  • PIR VCC to the sensor-rated supply.
  • PIR GND to ESP32 GND.
  • PIR OUT to an ESP32 GPIO input.

Do not assume every inexpensive PIR module has a safe 3.3-V output. Confirm the module’s electrical specifications before connecting OUT to the ESP32.

Rank #2
ELEGOO 3PCS ESP-32 Dev Boards, ESP-WROOM-32, USB-C, WiFi Bluetooth 4.2
  • Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
  • Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
  • Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
  • USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
  • Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision

MOSFET-controlled LED strip

Use a low-side switching arrangement:

  • LED supply positive to LED strip positive.
  • LED strip negative to the MOSFET drain or output.
  • MOSFET source or ground to the power-supply ground.
  • ESP32 GPIO to the MOSFET gate or driver input.
  • ESP32 GND connected to the LED power-supply ground.

The GPIO provides a control signal; it does not power the strip. Size the supply for the strip’s maximum current, keep high-current wires short and suitably thick, use an inline fuse, and initially test with a short strip or current-limited supply. Poor supplies, long wires, unsuitable MOSFETs, and inadequate grounding can cause flicker or ESP32 resets.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Household-voltage warning

For an AC lamp, the ESP32 should control a properly rated, preferably certified relay or smart relay. The ESP32 must never connect directly to mains wiring. Household-voltage work requires an appropriate enclosure, strain relief, insulation, separation between mains and SELV wiring, load-rated components, and compliance with local electrical rules. Disconnect power before working, and do not rely on software as the only safety mechanism. Keep the main tutorial low-voltage unless the installation is being completed by a qualified person.

Install ESPHome

The easiest starting point is the ESPHome integration or Device Builder associated with Home Assistant; command-line installation is also available for experienced users. Flash the first firmware over USB, then use Wi-Fi and OTA updates after the device is working. Keep a USB recovery path available.

Create the device, select the actual board identifier, enter Wi-Fi credentials, and open the logs after flashing. ESPHome syntax and board support change over time, so compare the configuration with the component documentation for the release installed on your system.

Minimal local motion-light configuration

This example keeps the control loop on the ESP32. It uses GPIO27 for a PIR and GPIO25 for PWM control of a MOSFET-driven low-voltage light.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
esphome:
  name: hallway-motion-light
  friendly_name: Hallway Motion Light

esp32:
  board: esp32dev
  framework:
    type: esp-idf

logger:
api:
ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "Hallway Motion Fallback"
    password: !secret fallback_password

captive_portal:

output:
  - platform: ledc
    pin: GPIO25
    id: hallway_pwm

light:
  - platform: monochromatic
    name: "Hallway Light"
    id: hallway_light
    output: hallway_pwm
    restore_mode: ALWAYS_OFF
    default_transition_length: 300ms

binary_sensor:
  - platform: gpio
    name: "Hallway Motion"
    id: hallway_motion
    device_class: motion
    pin:
      number: GPIO27
      mode:
        input: true
    filters:
      - delayed_off: 30s
    on_press:
      then:
        - light.turn_on:
            id: hallway_light
            brightness: 100%
    on_release:
      then:
        - light.turn_off:
            id: hallway_light
            transition_length: 500ms

The delayed_off filter keeps the motion entity active for 30 seconds after the last detected motion. Each new motion event effectively extends the active period, so the light turns off after inactivity rather than after a fixed time from the first movement. Adjust the delay for the room; a stairway may need less time than a bathroom.

Rank #3
ELEGOO ESP-32 Super Starter Kit with Tutorial Compatible with Arduino IDE
  • Powerful ESP-32 Board: Unlock the world of Internet of Things (IoT) and advanced electronics with the heart of this kit: the ESP-32 board. It features a powerful dual-core processor, integrated Wi-Fi and Bluetooth 4.2, making it perfect for building connected, smart devices that communicate with your phone or the cloud. It's fully compatible with the Arduino IDE for easy programming.
  • Super Starter Kit: This kit contains over 35 different modules and electronic components, including sensors, displays, motors, and input devices. From LEDs and buttons to an OLED screen, servo motor, and keypad, you have everything needed to explore a vast range of projects in one box.
  • Step by Step Online Tutorial: Jump right in with our detailed, beginner-friendly tutorial. Access 30+ projects with complete code, clear circuit diagrams, and step-by-step instructions. Learn the fundamentals of electronics, coding, and how to utilize the ESP-32's unique capabilities without any prior experience.
  • Hands-on Learning for All Skill Levels: Perfect for students, makers, engineers, and hobbyists. Start with basic circuits and coding, then progress to intermediate and advanced IoT applications. Build practical projects like weather stations, smart home controllers, remote-controlled devices, and interactive gadgets. The skills you learn are the foundation for real-world innovation.
  • Quality & Great Support: Elegoo is committed to quality. We provide a clear, detailed tutorial guide, refined code, and a well-organized component kit. All modules are carefully selected for reliability and ease of use. Our dedicated technical support team and active online community are ready to help you succeed in your learning journey.

For a relay-controlled on/off load, use a GPIO switch instead:

switch:
  - platform: gpio
    name: "Hallway Relay"
    id: hallway_relay
    pin: GPIO25
    restore_mode: ALWAYS_OFF

Replace the light actions with switch.turn_on: hallway_relay and switch.turn_off: hallway_relay. Some relay modules are active-low and may require inverted: true, but test startup behavior before enabling that option. A wrongly inverted relay can energize the load during reset.

ESPHome documents GPIO binary sensors, light entities, transitions, effects, and output platforms at esphome.io/components and esphome.io/components/light.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add Home Assistant rules

When the ESPHome device exposes its motion and light entities, Home Assistant can add a darkness condition and coordinate other devices. In the interface, go to Settings → Automations & scenes, create an automation, select the motion sensor as the trigger, select the light as the action, add a sun, illuminance, time, or occupancy condition, and choose an appropriate automation mode. Use Developer Tools → States and the automation trace while testing.

alias: Hallway light on motion at night
description: Turn on the hallway light when motion is detected after dark
triggers:
  - trigger: state
    entity_id: binary_sensor.hallway_motion
    to: "on"
conditions:
  - condition: sun
    after: sunset
    before: sunrise
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway_light
    data:
      brightness_pct: 45
      transition: 0.3
  - wait_for_trigger:
      - trigger: state
        entity_id: binary_sensor.hallway_motion
        to: "off"
  - action: light.turn_off
    target:
      entity_id: light.hallway_light
    data:
      transition: 0.5
mode: restart

Home Assistant labels and YAML schema can change between releases. If this example does not validate, use the visual editor and consult the current Home Assistant documentation. A timer-based automation is another robust pattern: motion turns the light on and starts or restarts a timer; timer completion turns it off.

Darkness, brightness, and manual control

Sun-based conditions

A sunset-to-sunrise condition is simple and requires no additional sensor, but it estimates darkness. Add a sun elevation or time condition if the room’s use demands a narrower schedule.

Rank #4
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (1 PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos;ESP32 is a safe, reliable, and scalable to a variety of applications
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • 1PCS 30Pin ESP32 Development Board 2.4GHz WiFi Dual Cores Microcontroller Integrated with Antenna RF Low Noise Amplifiers Filters

Lux-based conditions

An ambient-light sensor is more accurate when daylight varies significantly or when the sensor and light are in different locations. Shield the sensor from the controlled light. Otherwise the light can raise the measured lux, trigger an off decision, and create a feedback loop.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Brightness presets

  • Daytime: roughly 80–100%.
  • Evening: roughly 30–60%.
  • Overnight: roughly 5–20%, preferably warm white.

These are comfort starting points, not universal standards. A hallway near bedrooms may need a much dimmer overnight level than a workshop.

Manual override

Provide a physical button, an input_boolean helper, a manual-hold timer, or a smart-switch state condition. Without an override, someone may turn the light off manually only for motion to turn it back on immediately.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Commissioning checklist

Before powering the light

  • Confirm the exact ESP32 board and pinout.
  • Confirm PIR output voltage compatibility.
  • Confirm common ground on the low-voltage side.
  • Check LED polarity and MOSFET terminals.
  • Verify that the supply voltage matches the light.
  • Verify supply current capacity and fuse selection.
  • Inspect every connection for shorts.

First test

  1. Flash over USB.
  2. Open ESPHome logs and confirm startup.
  3. Confirm Wi-Fi connection if networking is used.
  4. Walk across the PIR’s field of view.
  5. Confirm the motion entity changes to on.
  6. Confirm the light turns on.
  7. Stop moving and wait for the configured delay.
  8. Confirm the light turns off.
  9. Repeat with the room already bright.

Also test power-up, firmware updates, Wi-Fi loss, Home Assistant restart, router restart, ESP32 reset, and a brief power interruption. For motion lighting, ALWAYS_OFF is often more predictable than restoring a previous on-state, but verify the exact behavior of the selected ESPHome component and installed release.

Troubleshooting by symptom

No motion events

Check VCC, ground, and OUT wiring; confirm the sensor output voltage; inspect the selected GPIO; wait for the PIR’s startup stabilization period; and watch the ESPHome logs. Reposition the sensor so people cross its detection zones.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

False triggers

Move the sensor away from direct sunlight, HVAC vents, radiators, moving curtains, plants, and pets. Reduce sensitivity or detection range where the module supports it. Add a short debounce or delayed-on filter, improve power grounding, and separate sensor wiring from high-current LED switching paths.

Best Value
HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Ultra-Low power consumption, works perfectly with the Arduino IDE
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • ESP32 is a safe, reliable, and scalable to a variety of applications

The light never turns off

Check whether motion remains continuously active, whether the delayed-off period is too long, or whether another automation is turning the light back on. Temporarily disable Home Assistant actions and inspect the motion entity state.

The light turns off too soon

Increase the timeout, use a restartable timer, add a second PIR, or change to mmWave presence sensing. A PIR cannot reliably prove that a motionless person has left.

LED flicker or ESP32 resets

Check the power supply under full load, MOSFET logic-level suitability, common ground, wire size, polarity, and fuse arrangement. Keep high-current wiring short and logic wiring away from switching paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Compilation or connection failure

For compilation errors, check indentation, entity IDs, board name, and syntax changes in the installed ESPHome version. Remove optional sections and re-add them one at a time. For connection problems, verify 2.4-GHz Wi-Fi availability where applicable, credentials, router isolation, VLAN/firewall rules, mDNS behavior, and the fallback access point. Reflash by USB when necessary.

Motion appears in Home Assistant but the light does not respond

Confirm the action targets the correct entity, test the light manually, check availability and attributes, temporarily remove the darkness condition, and inspect the automation trace. Another automation or a manual override may be taking precedence.

Commercial and DIY routes

The cheapest educational route is an ESP32 board, PIR, short low-voltage LED strip, MOSFET driver, and suitable supply. A guided option is the Apollo Automation ESPHome Starter Kit, which includes an ESP32-C6-based controller with plug-in PIR and addressable RGB LED modules and is intended for low-voltage learning and prototyping, not permanent high-power or mains installations.

For a whole-home system, Home Assistant Green is a dedicated host with Home Assistant preinstalled; see the official Home Assistant Green page for current regional pricing and availability. Readers who want finished ESPHome-oriented sensors can review Apollo Automation’s product range, including its DIY collection. Generic components can work well, but verify electrical ratings, logic compatibility, enclosure requirements, certifications, seller quality, and return policies rather than relying on an unverified marketplace listing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Final recommendation

For one hallway or closet, build a local ESP32 + PIR + MOSFET system and keep the light control on the device. Add Home Assistant only when you need schedules, lux rules, dashboards, scenes, or multiple rooms. Use mmWave when stationary occupancy is the central requirement. Keep the first installation low-voltage, enclose the electronics, test outage behavior, and treat mains switching as a separate qualified electrical project.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.