Simple PIR (HC-SR501) x ESP8266 setup not working (SOLVED)

Hi everyone - stuck on something basic, i think.
Objective: turn on lights when motion is detected via PIR, turn off if no further motion and after the delay.

I can’t get any PIR to change states. LEDs work fine when PIR is connected, I can change to my preferred states “manually” (via app), but simply can’t get PIR to automatically cause the state change.

Troubleshooting I’ve done so far:

  • Swap out HC-SR501 units (nothing)
  • Dial down pots on HC-SR501 (nothing)
  • Change jumper position on HC-SR501 (nothing)
  • Button 1 as Switch (nothing)
  • Swapped physical wires (nothing)

I think this might be a settings issue in WLED, but I simply can’t pinpoint it. Without the PIR, LEDs work just fine (addressable, any preset, etc.).

All advice or troubleshooting would be super helpful!

Setup:
ESP8266 controller (12v)
GPIO2: WS2811 LEDs (12v)
GPIO1: HC-SR501 PIR
Button 1 is set to GPIO1 / PIR
(PIR power is wired to the +v/gnd surrounding GPIO1)

LED Preferences:
Max Current: 600mA
LED Voltage: 12V (30mA)
Hardware: WS281x RGB, Length: 14, GPIO2
Button 0 GPIO: unused, disabled
Button 1 GIPO: 1, PIR sensor
Touch Threshold: 32
IR GIPO: unused, remote disabled
Relay GPO: unused, Invert: Yes

Time & Macros / Button Actions
Button 0: 0,0,0
Button 1: 2,1,0

Presets
2 (“Sensor Works”) (turn red; for testing)
{"on":true,"bri":128,"transition":7,"mainseg":0,"seg":[{"id":0,"start":0,"stop":14,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"n":"","col":[[255,0,34],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0}]}

1 (“Solid WW”) (go to warm white)
{"on":true,"bri":128,"transition":7,"mainseg":1,"seg":[{"id":0,"start":3,"stop":14,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":11,"set":0,"n":"","col":[[255,253,212],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":50,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"id":1,"start":0,"stop":3,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":11,"set":0,"n":"","col":[[255,253,212],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0}]}

Try using GPIO3 or GPIO4 or GPIO5 for PIR.

It’s not clear what voltage you are using to power the HC-SR501.

The specs’s I’ve seen show 4.5-20V power supply required (might want to check your supplier to be sure).

If you’re grabbing power off the ESP board, it may only be 3.3V or limited current supply.
Try powering the HC-SR501 directly from 12V (keep ground common).

You also might try measuring the output of the HC-SR501 with a meter directly (not connected to the ESP) to see if you can see a voltage change when something comes near.

Then try to apply a 3.3V signal to the GPIO input (with @blazoncek’s suggestion) to prove WLED will do what you think it does independent of the HC-SR501.

Thanks @blazoncek - this unit (ESP8266) only has GPIO1 and GPIO2, unfortunately.

Every ESP8266 has GPIOs 0-16.
ESP01 is a development board of ESP8266 which has only GPIO0-GPIO3 exposed.

What kind of ESP8266 do you have?

Thanks @divsys! The HC-SR501 I have is 4.5-20V, yes.

I’m using the +V from the ESP8266 that’s next to the GPIO1 (see picture below). I assume this is running 12V like the LEDs. Is there a WLED setting to change voltage?

FWIW - I also tried PIR from the same +V and gnd connections as the LEDS (simply putting both the LED and PIR lead into +V and the same with gnd - the two surrounding GPIO2).

In the end, it looks like I need new batteries for my multimeter after all :expressionless:

Dumb fwp - how would I apply 3.3V to the GPIO? Simply connect a 3V watch battery to gnd and put the + to the terminal?

Thanks in advance!

These are only outputs!

Not sure what that V+ line gives you on that controller

That’s the easiest way to get +12V to the PIR (if your LEDs are actually on 12V).

By all means - get proper batteries for the multimeter :wink:
IMHO a proper meter is one of the most important tools you can have for working with LEDs.
If you don’t have a 3.3V regulator or source around, you can use a resistor divider to drop a different voltage down.

Safest to start with a 5V source (USB charger or some other small regulated device).
A 2.2K resistor in series with a 1.5K resistor will give you a 3.3V “reference” for testing.
(crude diagram follows)
+5V
|
< 2.2K
>
|
-----> +3.3V
|
< 1.5K
>
|
GND

Measure with a meter to make sure you’ve done it correctly (before connecting to your controller)

Manually trying the inputs without the PIR will at least tell you what WLED will do with a given state. Then you can see if you can get the PIR to give you that state, or measure with the meter to see what state it’s giving you instead…

What kind of ESP8266 do you have?

The ESP2866 I have is from Ericsity (https://www.amazon.com/gp/product/B0CHHZTGJR). Did they just put fancy plastic and cover up the rest of the GPIOs!?

@divsys thanks a bunch. May get to the bottom of this yet…

… and added a few components such as level shifter.
And this is where your problem is, GPIOs used for outputs are level shifted and they are no longer inputs.

Oooops, that will do it - unless you’re willing to open up that box and find a viable input, you’re hooped (IMHO).

And looking closer at your pic - that’s a GLEDOPTO controller, not known to be particularly well designed or built.

You could beat that thing for quite a while chasing issues.
Might be easier to just get a proper ESP8266 or (better yet) an ESP32.

just my $.02 :thinking:

:expressionless: That’s what I get for getting the prepackaged version.

I’m more than happy to open and solder it. Here’re some shots of the board (below) - I’ll have to chase down a diagram to determine pins for this one.

I’m probably better suited to a plug and play option–are there ESP8266s that have easy access to all of the GPIOs and capabilities?

Really appreciate the help.

1 Like

Up and running! I definitely soldered to the wrong pin, but trial and error (assigning each GPIO to the Button 2 in turn) led me to lucky GPIO13.

Thanks a bunch for the help! I have true ESP8266es headed my way now, so I may switch over to that for ease of use or changing things in the future.

I marked as resolved - thanks @blazoncek and @divsys!