Best way to integrate several magnetic door switches

Sorry for the slow reply.

Correct, connect one side of every reed switch the the negative on the 12V power supply. Connect the other wire from each reed switch to a separate negative input on the 12v side of the opto. You need to “daisy chain” the positive from the power supply to each positive input on the 12v side of the opto

Hi Brad,

How have you got on with wiring directly to the GPIO pins? Have you had much trouble with interference or false positives?

I’m in a similar situation to you and trying to plan my wiring

I ended up using an octocoupler between the door sensors and the ESP32. It’s been working great.

More info

Thanks Brad, thats a fantastic write-up

I’m very new to this and trying to get my head around it. At the moment I have my ESP32-WROOM plugged in via USB, I have one end of my reed to the GPIO pin and the other to GND. In the code
pull-up = true. This works fine in HA, and I can add a second reed switch to another pin with them both going to GND.

Is this how you wired it without the optocoupler? I have seen some tutorials using the 3.3v pin on the ESP too but unsure why

Yep, that’s how to wire it without the optocoupler.

I don’t quite understand why you have a x3 terminal block distribution module then?

You have two cables coming from each terminal to the ESP (presumably GPIO and GND) and a third cable jumping from one terminal to the next.

Would you mind explaining the wiring for me?

A proper schematic (where have you heard this before) would answer a LOT of questions. A pretty Fritzing picture or a photograph is almost always absolutely worthless.

I’m not sure which x3 terminal block you are referring to. Was there a picture of a x3 terminal block in my smart home build thread?

Sorry should have been more specific. This one here:

IMG_7424
IMG_7423

I ended up ditching that setup. That’s what I would have used if not using the optocoupler. The optocoupler replaced that terminal board.

I had that terminal board set up with each of those looped wires connected to GND on the ESP32. Each long wire went to a GPIO. That way each 3x terminal could connect two sensors. I just doubled up the ground wire into the middle terminal.

1 Like

Ah gotcha, that makes sense now. Thanks Brad I appreciate your time and explanation

Hey there Brad

I’ve been reading this topic for almost two months now.
I’m on the exact same spot as you, need a solution for an in house alarm system witch would integrate with home assistant. I’m also building at the moment and I’m on the feeding lines stage.

I’m not very keen on electronics, but a close friend will help me.

Do you have more in depth pics and info of your current setup with the octocoupler?

Thanks in advance, and thanks for sharing

Yep, I ended up doing a write up on my smart home build here

This post goes over the wiring of the optocouplers for the magnetic switches.

2 Likes

Thank you very much!!

That the reading shall continue!! :smiley: