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
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:
Edit note: check the other comments. If you pull it to 3.3V then the voltage divider is not needed.
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)?
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:
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).