PNP Sensor Hookup

I am a bit of an electronics novice and would like some guidance hooking up a PNP Sensor to my Arduino 2560.

I have two Arduino 2560's, one where I test things out on and another which integrates with another PLC.

I hooked up the sensor with my test Arduino and read the value of A0 which toggled from 1.6v to 1.2v when going between high and low. So it seemed to work

But was not able to read any values on my production system. The only difference is the GND reference isn't directly from the PSU, but is from a relay board from the other PLC which has the same GND PSU

Thoughts and is this how I should be hooking up this sensor?

I just hooked up the above in my production Arduino but bypassing the really long cable runs to the actual sensor.

I observe at the voltage divider (a device I bought on Ebay) the voltage change from 1.2v to 1.6v but I read nothing in on the Arduino.

I am using the GND near the Analog pins and an analog pin, should I be using a digital pin?

A voltage divider normally consists of 2 resistors. You want to reduce 12 volts to 5 volts. I'd probably use this:

gnd ---  4.3K --- pin A0 --- 6.2K ---  +12V(PNP collector)

with the gnd common to both circuits.


This voltage range from your potential divider (what ever it is) is unsuitable for a digital pin:

1.6v to 1.2v

Hello 6v6GT.

Not 100% following, you may need to elaborate for myself.

The voltage divider which consists of 2 resistors appears to work and I can see a voltage change at its output pins.

Are you saying the GND I am feeding the Arduino should be direct from my 12V PSU which is the same PSU powering the sensor?

I think thats what is missing but was unsure if I pushed in a 12v GND it would break things.

OK. If you are using the same power supply for the Arduino and the sensor, then the grounds will already be interconnected so that problem is solved.

Can you provide a link to the voltage divider you are using. I'd have expected a voltage range of 0 to 5 volts if the divider is correctly balanced for inter connecting a 12 volt and 5 volt circuit.
If you get a large voltage swing, say 0 to 5 volts but also a bit less, you can use a digital pin. If it stays in the range you have quoted (1.2 - 1.6 volt) that will not cause a transition between a digital 0 and a digital 1 on the Arduino pin.

Thanks for the reply.
Here is what I purchased.

The line in my main loop currently has


and the serial monitor shows values between 280 and 290.

If I measure with a multi meter at the GND and SIG output on the voltage divider, as mentioned I see a voltage change but on the Arduino all I see is 280 to 290 with the signal in analog pin irrespective of the value of the sensor.

If I unplug A1 from Arduino the integer values will hover around 250

Any help is appreciated.

Getting close to midnight here, so this may be my last reply of the night.

OK. It is a 25 volt voltage divider so you should see a range of 0 to about 490 on the analog pin.

The voltage divider you have purchased does indeed consist of 2 resistors but has 5 (!) connections and no diagram, anyway I found this which might be the same :


You connect the output of the PNP photo cell to VCC and the "S" (I guess "Sig" on your device) connection to the arduino analog pin. The grounds are common.

Try it this way, first:

And if that doesn't give you enough range, then try it this way:

The first circuit is more efficient, but has more limited range. The second one uses more current, but has a larger potential range (i.e. more "sensitive").

The resistor values are quesses (I downloaded one of the product photos from the eBay link you provided and then "blew up" the image and examined the markings on the chip resistors).

The 2k resistor was chosen based on my "Voltage Sensor" resistor value guesses -- the logic being, to select a resistance value low enough to minimize the effect of current flowing into the Voltage Sensor, yet, not over tax the photo sensor. That 2k resistor value may be too low. You'll probably have to experiment.

Connect "SIG" to an Analog Input, in Setup, do an pinMode(analogInput, INPUT), and then, to read the level, do an analogRead(analogInput). analogInput is, of course, defined as the pin number you connected SIG to [e.g. #define analogInput A1]

And this is actually a way to get, pretty much, the most sensitivity/responsiveness/range out of this thing.

This is, of course, in exclusion of (or instead of) the Voltage Sensor module.

Also, it doesn't seem to be established if you're looking for an on/off effect, or if you want to measure levels.

If on/off, depending on whether there is enough light, in your application, to turn that phototransistor on enough to drive the voltage high enough for a defined HIGH condition, you may need to adjust the zener voltage (by using a different part) -- BUT, be sure the "Out" voltage never goes above the MAX Arduino Input Voltage. Probably best to test the open circuit voltages before connecting this to the Arduino.

Also, if on/off, then, of course, use a Digital Input :wink:

If analog levels is the goal, you may need to use more like a 1k resistor (instead of 2k2), to push the response into the more linear region of the Zener curve. If I was designing/making this, I would use a precision active zener, but the only one's I could find, are SMD and quite small and hard to work with.

I typically use the BZX84 line or lately, the ridiculously smaller BZT585BnnT series ['nn' being the zener voltage]. With these, the zener current can be MUCH lower -- even in the microamp range. And, the response is far more flat.

...and finally, here are a couple of examples with input protection. One for Analog Input, and one for Digital Input (good over temperature range 0°C to 65°C):

Thanks for the replies ReverseEMF and for the schematics. I currently have this wired up as per your diagram

And am not having any luck.

I dont own any resistors so I will buy some 2K ones today. All I am after is a Boolean on and off, I dont need values.

How I am reading the pin is exactly as you stated.

Connect "SIG" to an Analog Input, in Setup, do an pinMode(analogInput, INPUT), and then, to read the level, do an analogRead(analogInput). analogInput is, of course, defined as the pin number you connected SIG to [e.g. #define analogInput A1]

Without waiting for these 2k resistors to arrive. Is there any other way I could get this working?

Should I also purchase a Zenner Diode (BZX84) ?

Just looking through some resistors I have. I think I have 2.2K resistors.

(red - red - black - brown brown)

I am going to try and hook this up as stated above

Thats a 5:1 divider, 12V in should get you 2.4V out, not high enough for a digital input, you could connect to an analog input and test for greater than 2V.

Thanks outsider for the reply.

I hooked things up as per

and used the following code snippet to rule out my code as being an issue.


  Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:

I see values in the serial monitor of 1.6 irrespective if the PNP laser sensor receiver goes from high to low when a laser is shone at it yet if I use a multi meter and measure DC volts between GND and SIG on the volateg divider there is a clear change which is what I dont get, why doesnt the Arduino see this.

When I unplug A0 from the Arduino this drops instantly to 1.2.

Still pretty stuck here.

Is it possible to bypass the voltage divider and use the 2.2k ohm resistor.

Apologies, still an electronics novice and appreciate everyones help here.

Do you have the sensor ground (blue wire?) connected to Arduino GND?. Try this:

sensorState = analogRead(A0) > 410;

I believe its GND. I can try another one and did with no change

On the multimeter when I read the SIG and GND on the voltage divider this goes between .6V and 1.1 when the laser is aligned and not aligned with the PNP receiver

The values are never going over 300 so unsure how this code will work, upon execution (and I believe mean SensorValue) this yields zero as the condition is not true.

So in essence, whilst I can see the voltage change when testing the voltage dividers signal and gnd pins, i can't seem to reflect this on the Arduino

What is the VCC voltage on the sensor? Should be near 12V.

Correct it is 12v coming back from the sensor.

Should I just bypass the voltage divider and use multiple 2.2K resistors.

A single resistor has the voltage toggle between 2v and 6v, if I add another shouldnt it reduce even fruther below the 5v. In reading FIXED (Thanks): Arduino nano.. voltage divider not working. - Project Guidance - Arduino Forum this guy had an issue with his volatge divider.

I just dont understand why a multimeter is able to show the voltage change but I can't see this on my Arduino

No, that won’t reduce the 12V, you should have something like this:
If there’s 12V on divider VCC, there should be 2.4V on SIG and ADC value should be 491.

That is basically how I had hooked things up to start with. I now have a 2.2k resistor between VCC and GND.

The values in the serial monitor don't reflect what my meter is saying.

I really am a bit baffled here.