gxmark
Posts: 16
Joined: Mon May 20, 2019 3:04 pm

Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 2:56 pm

Hi Guys,
I am testing an 12 V Induction Sensor( PNP) with a Raspberry pi 3. The sensor is powered with a 12 v battery. On metal detection the signal wire puts out high.
test.png
test.png (6.35 KiB) Viewed 342 times
With the above breadboard set using the 10K and 3.3K resistor my voltage readings are as follows....
V [in] - 12.27
V [out] - 2.865

My test application snippet:
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
is_found = GPIO.input(5)


Question 1: Will the application only work if the V [out] is 3.3 V?
Question 2: Does the code look right?

pcmanbob
Posts: 6209
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 3:55 pm

I normally like to go with 2v minimum for a high, so your 2.85V will be just fine.

I don't think you will need the pull down in your code because when there is no 12v output R2 (3.3k ) will pull your gpio down to ground for you.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

gxmark
Posts: 16
Joined: Mon May 20, 2019 3:04 pm

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 4:17 pm

I modified my code.

GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN)
while True:
if GPIO.input(5):
print("open")
else:
print("Closed")

It seems to be switching between open and closed randomly as soon as a jumper cable is hooked to the pin 5 and nothing else.
When it is connected to the analog signal on the induction sensor the behavior does not change either.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 4:30 pm

Please place you code like this, this will make it a lot more readable :)

Code: Select all

GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.IN)
while True:
    if GPIO.input(5):
        print("open")
    else:
        print("Closed")
To you question, that is indeed the "correct" behaviour of a high impedance (high resistance) input. Then the wire will act as an antenne and this could result in that the input is digital 0 or a digital 1. And the pull-down resistor will ensure that this can never happen. That resistor is in your case the 3.3k. So you can not disconnect that part.

gxmark
Posts: 16
Joined: Mon May 20, 2019 3:04 pm

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 5:11 pm

Thanks for the pointers.

A little confused. :?
How do I get it to report open when the analog pin is high and vice versa.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 5:32 pm

Okay, I assume that you have connected the two resistors and the sensor to the Rpi?

When the induction sensor doesn't see metal, the output of that sensor will be noting. Because it has a PNP output, (but you can read is at 0V). In this case R2 will ensure that the voltage at the Rpi is 0V and you read a digital "0".
When the sensor sees something, the PNP transistor goes into condition, and the input voltage of the sensor is present at the output. The 12V that you measured before, the two resistors will riduse the voltage to a save input level for the Rpi. And it will read that as an digital "1" .

I hope this makes some sense to you :)
And to make a little bit more confusing, the Rpi doesn't have an analog input. Every signal <=0.9V will be seen as a digital "0" and everything above 1.6V is a digital "1". Between 0.9V and 1.6V could be anything and you don't want to operate here ever.

gxmark
Posts: 16
Joined: Mon May 20, 2019 3:04 pm

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 7:51 pm

inductive_sensor_.png
inductive_sensor_.png (234.17 KiB) Viewed 245 times
So here is my setup.
When an metal object is detected... Is the voltage pulsing very quickly between 0 and 2.835 volts on the analog pin?

what changes should i make to get door open or closed status. ?

d_older
Posts: 117
Joined: Mon Jun 25, 2012 5:04 pm
Location: East Yorkshire, UK

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 8:05 pm

Hi gxmark,

It doesn't look like the ground of the battery powered circuit is connected to the Pi's ground. Without this, the pi's input is just floating / acting as an antenna.

Hope this helps

Dave

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 8:11 pm

gxmark wrote:
Wed May 22, 2019 7:51 pm
inductive_sensor_.png
So here is my setup.
When an metal object is detected... Is the voltage pulsing very quickly between 0 and 2.835 volts on the analog pin?

what changes should i make to get door open or closed status. ?
Note, the Rpi does not have a analog pin only digital ones.

You also need to connect the ground of the sensor to Rpi. Otherwise it doesn't have a full circle, so to speak.

So, the bottom of R2 need to be connected to the ground of the Rpi. But remember if you connect the 12v in some of way directly to the Rpi. It is game over for your Rpi.

gxmark
Posts: 16
Joined: Mon May 20, 2019 3:04 pm

Re: Raspberry Pi 3 to 12V Induction sensor

Wed May 22, 2019 8:19 pm

That's it.

Thanks Brandon and Dave

Return to “General discussion”