STEP 1 / 6ESP + IOT

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…

Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035
PROJECT#429
TRACKIoT
PARTS07
STAGES06
STEP 1 / 6 · Overview

Know the mission before touching a wire.

Understand what you are making, prepare the right tools, and make the workbench safe.

01

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
02

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.

03

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.
Ready to continue?
STEP 2 / 6 · Parts library

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.

NAMED PROJECT INVENTORY7 PART LINES
PARTTYPEQTYREADY
BPutting the wires togetherBUILD1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035BUILD LEARNING VIEW

Putting the wires together

A named project component whose exact role is defined by the source circuit and build guide.

What it does here

It 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.
MPutting the ESP8266 code on paper and uploading itMODULE1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035MODULE LEARNING VIEW

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 here

It 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.
MESP8266MODULE1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035MODULE LEARNING VIEW

ESP8266

A programmable controller that reads inputs, makes decisions, and drives the project's outputs.

What it does here

It 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.
MPIR sensorMODULE1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035MODULE LEARNING VIEW

PIR sensor

A sensor converts a physical condition into an electrical signal the circuit can measure.

What it does here

It 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.
PNEARPART1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035PART LEARNING VIEW

NEAR

A named project component whose exact role is defined by the source circuit and build guide.

What it does here

It 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.
PNEUTRALPART1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035PART LEARNING VIEW

NEUTRAL

A named project component whose exact role is defined by the source circuit and build guide.

What it does here

It 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.
MESP8266-01 - controller board / ICMODULE1
What's this?Image, role, pros, cons, handling & specifications
Hack a PIR Motion Sensor with an ESP8266 - source illustration from page 1035MODULE LEARNING VIEW

ESP8266-01 - controller board / IC

A programmable controller that reads inputs, makes decisions, and drives the project's outputs.

What it does here

It 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.
Ready to continue?
STEP 4 / 6 · Source code

Confirm the hardware-only control path.

This project does not include firmware in the source. The circuit itself provides the required behaviour.

01

How to connect

  1. Match every controller label to the circuit view and source pin map.
  2. Join grounds before signal wires when separate low-voltage supplies are used.
  3. 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.

02

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.

03

How to upload code

The original design is implemented entirely in hardware, so proceed after verifying the circuit and supply.

Ready to continue?
STEP 5 / 6 · Build

Assemble, deploy, test, and troubleshoot.

Use the complete source notes in build order, then pass the final checks before calling the project finished.

ASSEMBLY

Build in functional stages

  • Power and regulation
  • Controller or processing stage
  • Inputs and sensors
  • Outputs and loads
  • Enclosure and strain relief
TEST

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
TROUBLESHOOT

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
PROJECT-SPECIFIC BUILD NOTES

Follow the documented instructions.

These notes come from this project's source and remain in their original order.

01

Project overview

Project build note

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 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.

02

What You Need

Project build note

PIR 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)

03

There are three parts to this project

Project build note

Putting the wires together Putting the ESP8266 code on paper and uploading it

04

Setting up the flow in Node-RED

Project build note

Motion 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.

05

Schematic Diagram

Project build note

Take 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.

06

Demonstration

Project build note

You 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.

Ready to continue?
PROJECT ACHIEVED

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.

Power ESP8266 with Mains Voltage using Hi-Link HLK-PM03 Converter project thumbnail featuring ESP8266, ESP32, Relay module
NEXT IOT ADVENTURE

Power ESP8266 with Mains Voltage using Hi-Link HLK-PM03 Converter

Ready to reuse what you learned in another project from the same track?

Start this project
Browse all 500 projects