Author Topic: Inductive sensor with microcontroller  (Read 653 times)

0 Members and 1 Guest are viewing this topic.

Offline VekettiTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: fi
Inductive sensor with microcontroller
« on: January 22, 2023, 03:09:53 pm »
Hi,

I'm trying to connect PNP inductive sensor pepperl+fuchs NJ5-18GM50-E2-V1 to 5V microcontroller for reading its state. I made following connection to protect the input as the sensor will be supplied with +24VDC and micro 5VDC. However I'm seeing 2,5V in the UC input when sensor is not sensing and not 0,5V of the Vf of diode. If I connect the +24 directly to pin 4 removing the sensor it works as I was expecting. Eg. no supply, uC input 0,5V and 24V supply uC input 5V. I don't understand why it wont work with the sensor. Could someone explain what's wrong?

I could also use voltage divider for the input but I'd see this is safer.

Thank you in advance.
« Last Edit: January 22, 2023, 03:11:48 pm by Veketti »
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4430
  • Country: dk
Re: Inductive sensor with microcontroller
« Reply #1 on: January 22, 2023, 03:32:57 pm »
it is a PNP sensor it only pulls high, when it is off or the sensor disconnected you have a voltage divider between the 15k and the 12k

the 12k needs to be a lower value
 
The following users thanked this post: Veketti

Offline VekettiTopic starter

  • Regular Contributor
  • *
  • Posts: 178
  • Country: fi
Re: Inductive sensor with microcontroller
« Reply #2 on: January 22, 2023, 04:10:01 pm »
Ah, yes indeed. Stupid me. Thanks.

What would be the ideal/better way of reading the sensor? I wouldn't want to drop the 12k value too much as it would consume much power when sensor is active..
 

Offline BeBuLamar

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: us
Re: Inductive sensor with microcontroller
« Reply #3 on: January 22, 2023, 04:10:21 pm »
Check pin 4 of the sensor with the sensor powered up (pin 1 and 3 connected) and the sensor is off (not sensing) and measure the voltage between pin 4 and pin 3 and see if you have any voltage there. There may be some leakage current that cause a small voltage reading when the PNP transitor is off. But to be honest I use those type of sensors a lot and not notice the problem.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4430
  • Country: dk
Re: Inductive sensor with microcontroller
« Reply #4 on: January 22, 2023, 07:43:04 pm »
Ah, yes indeed. Stupid me. Thanks.

What would be the ideal/better way of reading the sensor? I wouldn't want to drop the 12k value too much as it would consume much power when sensor is active..

you can reduce the 12K and add another resistor in series with the input from the sensor to limit the current
 

Offline Kim Christensen

  • Super Contributor
  • ***
  • Posts: 1327
  • Country: ca
Re: Inductive sensor with microcontroller
« Reply #5 on: January 23, 2023, 04:27:41 am »
The uC could still get damaged from static electricity or if a negative voltage was applied on the input. A much safer method would be to use an optocoupler which would also give you the benefit of eliminating ground loop problems if the sensor was some distance away. Or, if you're not worried about ground loops, a simple voltage divider with a 5V zener in parallel with the lower resistor could work also.
 

Offline BeBuLamar

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: us
Re: Inductive sensor with microcontroller
« Reply #6 on: January 23, 2023, 02:03:59 pm »
I think a 5V zener between pin 4 and 3 is a good idea. The sensor is capable of 200mA so with some current going thru the zener isn't bad.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf