Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4474

Beginners • Induction sensor PNP with Raspberry pi

$
0
0
I'm having struggles with what I suspect is a very basic task. I can't figure out what else to try, so perhaps you all might be able to point me in the same direction.

I'm using a Raspberry Pi 4 model B, and this https://www.mcmaster.com/7674K95/ sensor. I hooked up Brown wire to Pin4 (5V), Black to Pin6 (Ground), and Blue to Pin11 (GPIO17). I'm reading 5V across brown and black, and about 3.0V from blue to black when the sensor is not anywhere near metal. Since this a PNP sensor, I was expecting 0V. Furthermore, when I bring it into contact with a metal surface, no change in the state is reported. The code below just spews out a constant flow of "1", with no changes when I bring the sensor near ferrous materials. help?

from time import sleep
import RPi.GPIO as gpio

prox_switch = 17

gpio.setmode(gpio.BCM)
gpio.setup(prox_switch, gpio.IN, pull_up_down = gpio.PUD_UP)

try:
while True:
state = gpio.input(prox_switch)
print (state)
sleep(0.1)

except KeyboardInterrupt:
gpio.cleanup()
exit()

Statistics: Posted by sonarsquad99 — Fri Jul 05, 2024 10:42 pm — Replies 0 — Views 26



Viewing all articles
Browse latest Browse all 4474

Trending Articles