Help with Prox Switch

Hello all,

I thought I had this working until I removed the USB cable from the Arduino (Nano v3).

This is a 12v prox switch that I’d like to read into the Arduino. The odd thing is that it is working as long as I leave USB connected, touch the usb ground to the outside of the USB connector on Arduino, or wire the ground to 120v ground (green). I’ve tried everything but I’m at a loss and not real knowledgable about electronic design. In the end, this won’t have a USB connection so it has to work without it, not to mention, there’s obviously something wrong anyway.

I took the 12v sensing portion of the circuit from an Arduino (optoisolator design):

Prox switch from Ebay:
http://www.ebay.com/itm/321226619540?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

See attached image for wiring.

Any suggestions are appreciated.

Thanks - Brian

Drawing.png

You need to wire the input of the opto-coupler between brown and black, with a resistor suitable for 12V operation, DO NOT COMMON the grounds.

These sensors are usually open-collector, so you have to wire the load as a load to the output transistor (the diagram shows its an NPN open-collector, so load between output and V+).

The point of the opto coupler is to isolate, here its essential as the voltage offset and magnitude are both incompatible with 5V logic.

I think I probably should have mentioned that I'm powering the Arduino Nano from the 12v power supply that is also running the prox switch.

Just a couple of things that I like to clarify for my edification. The switch states that it's PNP and the diagram shows the load between black & blue.

Backing up a moment, it's my understanding that I should be able to supply 12v+ to Brown and 12v- to Blue and the light on the switch should indicate correctly (it's doing this now). As soon as I put 12v+ to Arduino pin 30 (Vin) and 12v- to pin 29 (GND) the prox switch shows detection all the time.

Turns out to have been a faulty power supply. Tried another and it works just fine.