Proximity Switch For Your Mains Devices

[Ivan’s] friend built a proximity sensor to switch his LED bench lighting off every time he walked away. The idea is pretty neat, so [Ivan] decided to implement it for mains devices by making this proximity switched outlet box.

A Sharp GP2D12 infrared distance sensor is the key to the system. It has an emitter and receiver that combine to give distance feedback base on how much of the light is reflected back to the detector. This is presented as a voltage curve which is monitored by an ATtiny85 (running the Arduino bootloader). It is small enough to fit inside the outlet box along with a tiny transformer and linear regulator to power to logic circuitry. The mains are switched with a relay using an NPN transistor to protect the chip’s I/O pins.

Check out the video after the break to see this in action. It should be a snap to add a count-down timer that gives you a bit more freedom to move around the workshop. With that in place this is a fantastic alternative to some other auto-shutoff techniques for your bench outlets.

17 thoughts on “Proximity Switch For Your Mains Devices

      1. The NPN transistor to protect the chip’s I/O pins isn’t optically isolated. The 12V junk transformer is dubious. What happens if 120v encounters any of the low voltage items? Transformers can and do fail, shorts can happen.

        I’ve seen far worse though.

    1. I’m not sure what isolation you are talking about but two potential improvements I saw would be:

      1. Add a diode across the coil of the relay to prevent inductive kickback from potentially damaging the transistor over time.

      2. Add some hysteresis in the firmware to prevent the relay stuttering for an object that sits just at the edge of one of the detection limits. Maybe add a small 0.1-1.0 uF filter cap on the input of the ADC.

      Obviously neither of these issues is affecting the device operation too much.

    2. it already has 100% isolation… its activated by a magnetic feild! no wires there!

      the sensor wire does not touch or contact any other project.

      if you think the sensor wire needs isolation then you should not ever ever ever touch a lamp cord with bare hands… that was sarcasm, except during a lightning storm… that you should just not work with wires perioud. mmkay

      this project already has redundant isolation.

      are you talking about an auto off box for a tesla coil?
      if you are you have bigger issuses then the on/off box… try a fricking faraday shield SUIT and then the box is moot (for personal safety)

      1. and ive seen worse. MUCH worse…

        actually, speaking of isolation safety

        i think the UL/CSA/CE/TUV can bite my a__ for trying to kill me.

        but you’d have to void the warranty to see for yourself ;)

        ive seen VERY scary (edit: dangerous) circuitry for sale on the shelf!
        supposedly safety tested by those organizations.

    3. Are we looking at the same schematic. The NPN transistor appears to be there to drive the relay not protect the IC. Relays are generally considered high enough isolation. Using optos to isolate the relay from the Attiny85 seems like over kill. As far as what happens if mains comes in contact with low voltage. I imagine the regulator blows apart as well as the $1.28 Attiny85 and hopefully a fuse or something blows open before any real property damage can happen. Now if one was really worried about mains shorting to the low voltage because of the transformer then fusing the 12volt supply and adding a MOV to the 12 volt power supply would address the transformer failure. However if that is a split bobbin transformer the winding are separated.

      From my perspective the only thing that is missing is a diode across the relay coil. In the event of a catastrophic failure the parts cost is minimal as long as everything is fused properly.

      1. just want to confirm I did put protection diode to protect the relay, but just isn’t in the schematic drawing, I will update the drawing soon,
        And this power plug isn’t connected directly through internal house wiring , I plug it in through fuse protected extension cord. I realize it isn’t save without fuse. I will improve it later. Thanks for every feedback.


  1. Not being adverse to the Arduino myself, I still think this design could have been completed without the use of a micro controller with some basic filtering on the analog side. Add a toggling circuit on the relay side and you’ve got basically the same thing.

    1. Everyone bitches about this too much. Is time worth nothing? I mean damn, the attiny is a $1.50 part, you’re not gonna save much money by going all analog. And if you know how you can do this with the attiny, but not in analog, then it’s probably going to be more efficient to just use the attiny. At minimum wage in the US, the attiny costs 15 minutes. I don’t think someone is likely to be able to figure out the analog stuff in that amount of time.

      So everyone needs to stop bitching that it can be done without a micro. Unless it is a mass produced product, the micro is probably a more efficient use of resources.

      1. your right…
        ***_IF_*** the parts for the project were solely PURCHASED!

        opamp and capacitor are in everything and thus FREE on the curb (garbage), i guanentee you own one inside something broken somewhere. not one single person reading this site should be out of opamps or capacitors.

        then again, if you HAVE attiny by the bucketload, why not? after all they ARE tiny.

        RasPI or ATMega 128 would be super-overkill i agree!
        but attiny?
        cmon guys its not even 8kb and it has how many GPIO?
        its the same footprint as a 555 too.

        PS: (future) features are much easier to make when its computer controlled too :)

        PPS: screw the 555, its very uncommon in consumer devices. i have yet to find one used. theres a seperate part for pretty much everything you can do with a 555.

  2. I’m not saying this setup is dangerous or safe, but that’s an Australian power socket and being a permanent fixture, you’re actually breaking the law and your house insurance is most likely null and void. Take it off the wall, and it becomes legal (as long as it’s not directly connected to the house wiring). That’s my layman’s understanding of the law, anyway.

    1. it isn’t permanent fixture in the wall socket. I plug this to another fused extension wire. I just find this wall socket case fit all the guts, that’s the reason i use it. In the picture you can see AC input wire which is connected to another extension.
      thx for your feedback

  3. This is cool and as the author already stated he has added the diode and a fused extension cord and will probably add a fuse internally. Good on him for a good project and adding suggestions.
    What I want to know is has anyone seen of any type of cheap power line networking hack? something like X10 but bidirectional and can do a few bps? Maybe some kind of AM power line transmitter sendin DTMF?
    Just wondering I could see some real uses for it for things like this.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.