Hack a PIR Motion Sensor with an ESP8266
With an ESP8266, you can hack a PIR motion sensor. In this project, we'll connect an ESP8266 to a commercial (mains-powered) motion sensor and change it so that it logs data whenever it d…

Know the mission before touching a wire.
Understand what you are making, prepare the right tools, and make the workbench safe.
Project details
Hack a PIR Motion Sensor with an ESP8266 is a iot project. With an ESP8266, you can hack a PIR motion sensor. In this project, we'll connect an ESP8266 to a commercial (mains-powered) motion sensor and change it so that it logs data whenever it d…
- Source pages
- 1034-1040
- Named parts
- 7
- Build goal
- Working, tested prototype
Tools you need
- Digital multimeter
- Wire stripper and side cutters
- Soldering iron with a fine tip
- Current-limited bench supply
- Computer with a data-capable USB cable
Use eye protection, good lighting, and a clean insulated surface throughout the build.
Safety precautions
- Disconnect every power source before changing a connection.
- Check component polarity, pinout, and supply voltage twice.
- Use a current limit for the first power-up.
- This project may involve hazardous voltage. Work only with qualified supervision and proper isolation.
Gather, identify, and understand every part.
Use the standardized inventory, then open What's this? to learn each part's role, advantages, limitations, handling, and specifications.
What's this?Image, role, pros, cons, handling & specifications

Putting the wires together
A named project component whose exact role is defined by the source circuit and build guide.
What it does hereIt performs a documented electrical, control, interface, or construction function in this project.
Buy / compare this part ↗Advantages
- Selected for this project
- Can be checked independently
- Supports modular troubleshooting
Limitations
- Substitutes may differ
- Generic names can hide variants
- Pinouts and ratings vary
Handling
- Compare the received part with the source
- Keep it labelled
- Do not force connectors or adjusters
Specifications to verify
- Use the exact model, value, package, and rating listed for Putting the wires together; similar-looking parts are not always interchangeable.
- Confirm dimensions, ratings, connection method, polarity, and environmental limits.
What's this?Image, role, pros, cons, handling & specifications

Putting the ESP8266 code on paper and uploading it
A programmable controller that reads inputs, makes decisions, and drives the project's outputs.
What it does hereIt is the control centre and must use the documented board, pin map, supply, and logic level.
Buy / compare this part ↗Advantages
- Reprogrammable and reusable
- Large learning ecosystem
- Complex behaviour remains changeable
Limitations
- GPIO voltage and current are limited
- Some pins affect boot or communication
- Loads normally need a driver
Handling
- Disconnect power before rewiring
- Avoid static discharge
- Never power motors, relays, or pumps directly from GPIO
Specifications to verify
- Use the exact model, value, package, and rating listed for Putting the ESP8266 code on paper and uploading it; similar-looking parts are not always interchangeable.
- Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
What's this?Image, role, pros, cons, handling & specifications

ESP8266
A programmable controller that reads inputs, makes decisions, and drives the project's outputs.
What it does hereIt is the control centre and must use the documented board, pin map, supply, and logic level.
Buy / compare this part ↗Advantages
- Reprogrammable and reusable
- Large learning ecosystem
- Complex behaviour remains changeable
Limitations
- GPIO voltage and current are limited
- Some pins affect boot or communication
- Loads normally need a driver
Handling
- Disconnect power before rewiring
- Avoid static discharge
- Never power motors, relays, or pumps directly from GPIO
Specifications to verify
- Use the exact model, value, package, and rating listed for ESP8266; similar-looking parts are not always interchangeable.
- Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
What's this?Image, role, pros, cons, handling & specifications

PIR sensor
A sensor converts a physical condition into an electrical signal the circuit can measure.
What it does hereIt provides project input as an analogue, digital, resistive, frequency, or calibrated signal.
Buy / compare this part ↗Advantages
- Adds real-world awareness
- Can usually be tested independently
- Often supports calibration
Limitations
- Readings can drift
- Placement affects results
- Some sensors need warm-up or calibration
Handling
- Protect the sensing surface
- Observe supply voltage and polarity
- Keep signal leads away from noisy power wiring
Specifications to verify
- Use the exact model, value, package, and rating listed for PIR sensor; similar-looking parts are not always interchangeable.
- Confirm supply range, output type, measurement range, accuracy, response time, and pin order.
What's this?Image, role, pros, cons, handling & specifications

NEAR
A named project component whose exact role is defined by the source circuit and build guide.
What it does hereIt performs a documented electrical, control, interface, or construction function in this project.
Buy / compare this part ↗Advantages
- Selected for this project
- Can be checked independently
- Supports modular troubleshooting
Limitations
- Substitutes may differ
- Generic names can hide variants
- Pinouts and ratings vary
Handling
- Compare the received part with the source
- Keep it labelled
- Do not force connectors or adjusters
Specifications to verify
- Use the exact model, value, package, and rating listed for NEAR; similar-looking parts are not always interchangeable.
- Confirm dimensions, ratings, connection method, polarity, and environmental limits.
What's this?Image, role, pros, cons, handling & specifications

NEUTRAL
A named project component whose exact role is defined by the source circuit and build guide.
What it does hereIt performs a documented electrical, control, interface, or construction function in this project.
Buy / compare this part ↗Advantages
- Selected for this project
- Can be checked independently
- Supports modular troubleshooting
Limitations
- Substitutes may differ
- Generic names can hide variants
- Pinouts and ratings vary
Handling
- Compare the received part with the source
- Keep it labelled
- Do not force connectors or adjusters
Specifications to verify
- Use the exact model, value, package, and rating listed for NEUTRAL; similar-looking parts are not always interchangeable.
- Confirm dimensions, ratings, connection method, polarity, and environmental limits.
What's this?Image, role, pros, cons, handling & specifications

ESP8266-01 - controller board / IC
A programmable controller that reads inputs, makes decisions, and drives the project's outputs.
What it does hereIt is the control centre and must use the documented board, pin map, supply, and logic level.
Buy / compare this part ↗Advantages
- Reprogrammable and reusable
- Large learning ecosystem
- Complex behaviour remains changeable
Limitations
- GPIO voltage and current are limited
- Some pins affect boot or communication
- Loads normally need a driver
Handling
- Disconnect power before rewiring
- Avoid static discharge
- Never power motors, relays, or pumps directly from GPIO
Specifications to verify
- Use the exact model, value, package, and rating listed for ESP8266-01 - controller board / IC; similar-looking parts are not always interchangeable.
- Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
Connect one verified path at a time.
Explore the named components and standardized signal flow, then use Source Check to verify exact physical pins, values, and topology before applying power.
Trace this circuit.
Hack a PIR Motion Sensor with an ESP8266: interactive parts, standardized terminals, responsive anchored wires, student explanations, and the original circuit reference in one shared system.
Trace before wiring
Follow power, ground, inputs, processing, and outputs in that order. Never guess a pin from package shape alone.
Connect with power off
Make short, labelled connections and share a common ground only where the schematic requires it.
Inspect every joint
Check continuity, polarity, adjacent shorts, and loose connections before the first power-up.
Open all source diagrams and build views 5 visuals





Confirm the hardware-only control path.
This project does not include firmware in the source. The circuit itself provides the required behaviour.
How to connect
- Match every controller label to the circuit view and source pin map.
- Join grounds before signal wires when separate low-voltage supplies are used.
- Keep motors, relays, pumps, and other loads on a suitable driver and external supply.
Common mistakes
Reversed VCC/GND, board-label versus GPIO-number confusion, missing common ground, and charge-only USB cables.
Troubleshoot
Disconnect loads, continuity-test one path at a time, then test with a current limit.
Software preparation
No IDE, board package, library, or firmware upload is required for this project.
If you add a programmable controller as an extension, document its pin map separately.
How to upload code
The original design is implemented entirely in hardware, so proceed after verifying the circuit and supply.
Assemble, deploy, test, and troubleshoot.
Use the complete source notes in build order, then pass the final checks before calling the project finished.
Build in functional stages
- Power and regulation
- Controller or processing stage
- Inputs and sensors
- Outputs and loads
- Enclosure and strain relief
Power up safely
- Inspect unpowered continuity first
- Apply the lowest safe current limit
- Measure supply rails before signals
- Add one load at a time
- Record expected and actual results
Work from simple to complex
- Confirm power, ground, polarity, and orientation
- Compare each pin with the source
- Test inputs separately from outputs
- Replace only one variable at a time
- Power off before every correction
Follow the documented instructions.
These notes come from this project's source and remain in their original order.
Project overview
Project build noteWith an ESP8266, you can hack a PIR motion sensor. In this project, we'll connect an ESP8266 to a commercial (mains-powered) motion sensor and change it so that it logs data whenever it detects motion. MQTT, a type of communication protocol, will be used to send the data to Node-RED. The HLK-PM03 AC/DC converter will be used to power the ESP8266 through the motion sensor phase out. The HLK-PM03 AC/DC converter will be used to power the ESP8266 through the motion sensor phase out wire. Motion sensors, also called motion detectors, are electronic devices that can detect and measure movement. Most home and business security systems use motion sensors, but you can also find them in phones, paper towel dispensers, game consoles, and virtual reality systems.
What You Need
Project build notePIR 220V Motion Sensor (or 110V PIR Motion Sensor) ESP8266-01 – See Best ESP8266 Wi-Fi Development Boards ESP8266-01 Serial Adapter (to upload code to the ESP8266)
Hi-Link HLK-PM03 (to convert mains voltage to DC 3.3V) Slow Blow Small Protoboard Fuse (200mA) 47 uF electrolytic capacitor Pi Raspberry (to host Node-RED and MQTT broker)
There are three parts to this project
Project build notePutting the wires together Putting the ESP8266 code on paper and uploading it
Setting up the flow in Node-RED
Project build noteMotion Sensor The following picture shows a broad view of the project we will build. We'll hack a commercial motion sensor that has enough room for an ESP-01 and an HLK-PM03 AC/DC converter module. We got our motion sensor at a store near us for $5. When the PIR sensor sees movement, power flows through the red-hot wire and can be used to turn on a lamp or other device. Your motion sensor
should have a similar wiring diagram on the top or in the instructions. In our project, the motion sensor output load is the HLK-PM03 AC/DC converter module, which will power the ESP8266. The HLK-PM03 module AC/DC converter takes either 110VAC or 220VAC and turns it into 3.3V. This makes it perfect to use mains voltage to power the ESP8266. In short, power is sent to the ESP8266 when motion is detected. As long as the motion sensor is set off, the ESP8266 can run tasks. You might need to change how long the sensor stays on so that the ESP8266 has enough time to do its job. There should be a knob on the sensor to change the time (and another to adjust luminosity). In our example, when the ESP8266 is turned on, it runs a sketch that sends information to Node-RED via MQTT to record the date and time that motion was detected. You don't have to send information to Node-RED. You can do other things, like: Log information into a Google Spreadsheet, send an email when motion is detected, and get alerts on your phone. IFTTT makes it easy to do all of these things.
Schematic Diagram
Project build noteTake off the lid of your PIR sensor. Inside, it should have three wires: one for phase in, one for phase out, and one for neutral. Do these things: Wire the motion sensor with the phase-in (brown) and neutral (blue) wires. Wire the HLK-PM03 input with the neutral (blue) and phase out (red) wires. It is recommended to add a slow-blow fuse and a capacitor to the output right before the HKL-PM03 converter. Note: We recommend using this protection circuit if you are using an ESP8266 that is always on with the HLK-PM03. The 3.3V and GND come out of the HLK-PM03. These are hooked up to the VCC and GND pins of the ESP8266 to power it. To save space, we put the HLK-PM03 and ESP8266 circuit on a small protoboard. We've also added some header pins so the ESP8266-01 can be put in place. So, every time you need to upload new code, you can just plug and unplug the board.
Demonstration
Project build noteYou can now try out your project. When motion is sensed, the ESP8266 turns on and sends a message to Node-RED through MQTT. If you go to your Node-RED Dashboard, you can see all of the logs of when motion was detected. The following picture shows how your application should look. The dashboard shows the last time movement was picked up and all of the logs from before that. You can also choose to update the log or clear the log. Please remember that once you clear the log, you can't get it back. This project showed how to use an ESP8266 to make a commercial motion sensor
smarter. With the HLK-PM03, it's easy to use mains voltage to power the ESP8266 and make a small circuit that can fit in the motion sensor. When movement is detected, the ESP8266 is turned on and a task is done. In this case, it sends out a MQTT message to log the time motion was detected, but you can easily write code to do any other task.
You built Hack a PIR Motion Sensor with an ESP8266.
You followed the full workflow from understanding the mission to testing the finished project. That is a real engineering achievement - well done.
Browse all 500 projects