ESP32 binary sensor and a photoelectric beam sensor

Glad you got it sorted.

It depends on how they are rectifying the AC to DC. If they use a full bridge rectifier then it should not matter. A half bridge rectifier would have issues with reversed polarity DC.

1 Like

Hi Gaz, I note that the voltage for this sensor is 6-36V DC. how does this work with the ESP32 or do you interface it into home assistant another way. Im looking to set up a sensor that will detect letters being put into a mailbox slot.

Is your esp going to be in mailbox?

i can, but I thought I would leave it under the house out of the weather. Im not sure which is the best way yet?

So how long is the distance from box to house?

The cable run would be about 10 to 12 metres

Quite a lot. What about small wireless door sensor(reed switch) on the slot?

I would if I could find a mail box front with a door that looks ok. I have purchased one but it has a open slot. The plan was to use the photoelectric sensor on the front slot and reed switch on the back door

Ok, back to the original.
You can use any NPN sensor if it’s open collector without any problems. I means that signal is either low or floating. So there is no conflict with voltage.

Another option is to use PNP and simple voltage divider(two resistors) between sensor output and Esp.
Third option is to use some cheap 3.3V sensor module like this:
image

Just be sure to use some shielded alarm or ethernet cable, 10+ meter cable is a long antenna for interferences.

thanks Karosm. I might need to make it a little water proof in case rain blows in. I could probably 3D print a case and just have the sensors stick through. So basically put the ESP32 and sensor in the mailbox and run 5v accross the 10-12m?. Ill need to check my wifi signal there. It may be sheilded by the metal enclosure of the mailbox case. Or leave the esp32 in the house and just run 5v, ground and signal the 10-12m? I would imagine that would not be much voltage drop over this distance based on the current draw of this sensor?

What about these type? Infrared Diffuse Reflection Type Photoelectric Switch Sensor Switch’s E3Z-D61 E3Z-D62 E3Z-D81 E3Z-D82 DC12-24V with Bracket - AliExpress 13

There are two options, either both in mailbox or just sensor in mailbox.
Putting just sensor there has more advantages, the downside is interferences. But since I expect you don’t need some microsecond speed for your mail detection :grinning:, you can just filter them out in your code.

You can waterproof them as you want, even dipping in epoxy… Just leave the tips of the leds uncovered.

If you go with ready made sensor switches, choose NPN NO type. If it’s open collector (without internal pullup) you can wire it straight to Esp. If it has internal pullup, you need to add one diode between sensor output and Esp pin. You really don’t know before you receive it(except if you find some good datasheets).

Just make sure it’s adjustable.
There are also sensors that work with 5V and up, might be more convenient for powering it…
https://nl.aliexpress.com/item/1005006558697041.html?spm=a2g0o.detail.pcDetailBottomMoreOtherSeller.6.21dbxRLPxRLP4O&gps-id=pcDetailBottomMoreOtherSeller&scm=1007.40196.368083.0&scm_id=1007.40196.368083.0&scm-url=1007.40196.368083.0&pvid=d0ae22e8-baf8-4a72-87bf-6b3c3e3db5c4&_t=gps-id:pcDetailBottomMoreOtherSeller,scm-url:1007.40196.368083.0,pvid:d0ae22e8-baf8-4a72-87bf-6b3c3e3db5c4,tpp_buckets:668%232846%238111%231996&pdp_npi=4%40dis!EUR!2.02!2.02!!!2.20!2.20!%402103850917247483308696456e0199!12000037665158890!rec!IT!103797544!XZ&utparam-url=scene%3ApcDetailBottomMoreOtherSeller|query_from%3A

Thanks again Karosm. This is great info. Im wondering if the same 5V power supply would work for both ESP32 (leaving ESP 32 in House) and the sensor over this distance for the Aliexpress one listed. I was looking to run shielded 17AWG or 1mm2 cable (probably 6 core to run both the proximity switch and reed switch) Would get a little volt drop but not sure if it would work. perhaps the one above might be better and put it in a box. (it will operate down to 3.3v)

As long as your 5V psu has current rating high enough. Normal 5V2A phone charger is sufficient. Voltage drop depends on current, if you have low power sensor, voltage drop is minimal even if wire resistance is high.

There are so many tiny battery operated BLE and Zigbee reed switch sensors around, that it’s almost shame to use wired one.

You’ve got me curious and my brain’s thinking! How did that break beam sensor end up working for you?

How do you distinguish between the vehicle and perhaps youve got an irresponsible kid like me and they park their bicycle right in front of your break beam and drive you nuts?

Do you use it for anything else like detecting intruders if the house is empty? Obviously nothing ahould break the beam if no one’s home.

Thanks Karosm, Im a little way off getting it all set up, but will test with some of the components.