0

how do I hook a PNP sensor to a raspberry pi 3? I know I need an A/D converter, and I've already got a MCP3008. But apart from that, what else do I need? The sensor output switches 24v or 0v, I also know I have to bring it down to 3,3V. Thanks a lot guys!

2 Answers2

2

The sensor output switches 24 V or 0 V.

That means it's a digital sensor and should be connected to a digital input. You use analog inputs for varying signals which are "analogous" to the physical property you are measuring - e.g., temperature, pressure, etc.

schematic

simulate this circuit – Schematic created using CircuitLab

I also know I have to bring it down to 3,3V.

So we need to divide the voltage by 3.3 / 24 = 7.3. 68k and 10k as shown in Figure 1 should do the job.

The resistor values are high to keep currents low. If you have a two-wire sensor it may need a certain current in the 'off' condition to power the electronics. In that case we may need to scale the resistors down by a factor of 10 or so. Let us know and post a link to the sensor datasheet.

Transistor
  • 175,532
  • 13
  • 190
  • 404
  • http://www.leuze.com/en/deutschland/produkte/schaltende_sensoren/optische_sensoren/lichtschranken_lichttaster_zylindrisch/baureihe_318_kunststoff/lichttaster/rt_hrt_3/selector.php?supplier_aid=50122564&grp_id=1332237561758&lang=eng#{"tab":"2"} – Roberto Mack May 09 '16 at 02:50
  • just click on downloads and find the datasheet in your preferred language...

    thanks a lot dude! btw I'll still need the a/d for the analog sensors

    – Roberto Mack May 09 '16 at 02:51
  • OK. There's no mention of analog in your question. Industrial analog sensors will be 0 - 10 V or 4 - 20 mA. – Transistor May 09 '16 at 07:27
0

You can use a voltage divider as so:

schematic

simulate this circuit – Schematic created using CircuitLab

It will work with R1 and R4 as a single 30K resistor, with C1 missing, and with R3 shorted, D1, D2 missing, but the suggested parts add more immunity to

Spehro Pefhany
  • 397,265
  • 22
  • 337
  • 893