NPN Proxy Sensor reducing 12v Analog to 3.3v for ESP32

Hello all,

I am trying to get a 12v NPN Inductive sensor (PNK6-AN-3A) to work with an ESP32-S3. The project is trying to get it to detect the gears on my tractor so I may calculate how many times my tires spin.

I can get the inductor to work without any issue. For the NPN sensor setup, I have blue going to GND, Brown to 12v+, and have my Red lead on my multi-meter plugged into the black output of the NPN with the Black lead going into the positive on my power supply. This works and when the system detects metal I get 12v- and when no metal is detected I get 0v.

I was planning on using a voltage divider on the analog signal but have been having issues getting it to work as an entire unit. I haven't put the ESP32 in the system but have just been trying to get it to work with a voltmeter.

I can get the divider to work on its own with an output of 2.98v:

  • Vin as 12v+
  • R1 as 1k
  • R2 as 330

But when I try any combination of wiring the sensor, I cannot get anything but 12v out of the divider. Right now I have this configuration: IMG-1051 hosted at ImgBB — ImgBB

Any help would be appreciated.

Here are some sources I have already read:

The NPN output goes directly to an input pin, together with a pullup resistor to 3.3V Vcc.

2 Likes

Maybe you should read on 'open collector'.

1 Like

I think that it works like an open collector, the output will be either connected to ground or floating, so connected to nothing.
Then you have to add a 10K resistor from the signal pin to 12V, to tie it there when it's floating, and to GND when active:
image

Edit note: check the other comments. If you pull it to 3.3V then the voltage divider is not needed.

1 Like

No. If it is open collector, simlpy pull it up to the microprocessor Vcc and lose the voltage divider as @DrDiettrich has stated.

a7

Ah, yes, that's simpler. The voltage divider is not needed.

@dapsoneanimal

Connect like this

2 Likes

I was able to get this all wired up, I didn't want to fry my ESP32 so I did an Arduino first and it did not catch anything on fire!

My question remains in measuring for verification purposes, should I be measuring with my multimeter against Vcc or Gnd when checking for voltage on the output (aka black wire)?

Connect the multimeter positive lead to the BLACK wire and the negative lead to the BLUE wire (GND)

1 Like

I am pulling .77v when the sensor picks up metal and 3.35v when no metal is detected.

Does that matter or will the code work fine with it? I am starting to program now and wanted to ask before I got too deep into it.

What code?

It should work. But I find 0.77V a bit too high, is not normal. When the sensor is active it should be close to zero. Make sure that all GND's are connected. And that you have zero volts in the GND point where you connect the blue wire. And that the sensor is fully activated.

Anyway it should work, but with a not so big margin. The voltage levels to trigger HIGH or LOW are:


(ESP32-S3 datasheet)

If VDD is 3.3V then high will start at 0.75x3.3 = 2.475V
And low will be from -0.3 to 0.25x3.3 = 0.825V

Would be better to have more margin in the low side. Anyway test if it works or miss some hits.

I haven't gone back to correct the voltage item but I am reading the inductor into the ESP32 without any issue at that voltage.

1 Like

Your microprocessor senses the change in voltage, NOT the low level. In some cases if the low level is not low enough, there may be problems, but you do not have that problem. See the documentation on the microcontroller for the lower limit for that particular device.

Yes - you wont get a zero because the npn transistor is conducting - and in conduction you still get a voltage across it.
When the transisitor is OFF (ie no metal) the voltage is Vcc. (around 3.3V in your case).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.