# How can I turn on a Raspberry PI GPIO pin based on presence of ~22vdc?

**URL:** <https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751>\
**Category:** Factual Questions\
**Created:** [May 23, 2021, 6:21pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751 "2021-05-23T18:21:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [May 23, 2021, 6:21pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/1 "2021-05-23T18:21:40Z")

</div>

TL;DR version:  
I have a pair of wires with ~22vdc across them, and I want to use the presence or absence of this voltage to trigger a GPIO line on my Raspberry Pi in order to tell my program to do something. I know nothing about electronics. How can I do this?

Details:  
I am working on my [never-ending Seeburg 1000 project](https://photos.smugmug.com/photos/i-Gg4rhDL/0/b93cffab/X5/i-Gg4rhDL-X5.jpg), with the goal of putting a Raspberry Pi inside to give some cool modern upgrades to the device.

Inside the machine there is an electromechanical timer that is designed to trip on once every 30 minutes, and trip off an arbitrary number of minutes after that, controlled by a knob. This allows you to set an “on time” of ~5, 10, 15, 20, 25, or 30 minutes every half hour. In short, it sets the duty cycle of the machine.

In normal operation, this will control how many songs play every half hour, and it has a clever circuit that listens to the music and doesn’t actually shut off power until it hears a gap in the record.

I want to use this timer to control my Raspberry Pi, so that even though the Pi is playing music (and injecting it into the Seeburg’s amplifier), the electromechanical timer will still start and stop the music. I don’t want to modify anything–I am using the existing jacks of the device for everything.

There is a RCA jack on the back (labeled J103C on the schematic below) that is for externally controlling the timer switch in case you have an external audio feed you want to use and don’t want the record turning. If the jack is shorted with a jumper, the timer functions normally. If you unplug the jumper, the machine turns on, the timer turns, but the motor relay never closes and the record doesn’t turn–this is the normal “external audio” mode.

I would like to hack this jack. Though it is really intended as an input control, I believe I can detect the timer’s current on/off state from the jack. [It appears to have ~22 vdc present](https://photos.smugmug.com/photos/i-NW483Z7/0/7237336d/X5/i-NW483Z7-X5.jpg) when “on” and 0 vdc when “off”.

[Here is a highlighted schematic](https://photos.smugmug.com/photos/i-XFGMDrL/0/06b741fd/X5/i-XFGMDrL-X5.png) showing what I’m looking at. I have drawn lines showing where I think the voltage is coming from.

[Here’s the parts list](https://photos.smugmug.com/photos/i-fts2WFk/0/9ebd27bb/O/i-fts2WFk.png), if the resistor values are relevant.

I will leave the jumper off, since I don’t want the record to turn, but I want to detect the ~22v that appears when the timer is in the “on” cycle. I will use this to enable a GPIO pin that will be sensed by my code and start or stop the music, just as if I were actually playing records on the machine.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [May 23, 2021, 6:31pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/2 "2021-05-23T18:31:01Z")

</div>

Use an optoisolator, or a transistor with the correct base resistor.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [May 23, 2021, 6:39pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/3 "2021-05-23T18:39:20Z")

</div>

Remember, I know nothing about electronics.

Would an optoisolator be a drop-in part with no other components needed? What about the transistor, which kind and how do I determine the resistor, and which legs hook up to where?

A link to a photo of a rough pencil sketch of this on a napkin would be helpful.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [May 23, 2021, 7:06pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/4 "2021-05-23T19:06:05Z")

</div>

OK, hang on.

---

<div class="post-metadata">

**Author:** ![jnglmassiv](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@jnglmassiv](https://boards.straightdope.com/u/jnglmassiv)\
**Post date:** [May 23, 2021, 7:16pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/5 "2021-05-23T19:16:21Z")

</div>

What’s the allowable range of the high signal on the GPIO? I’d use a simple regulator that had at least a 22 volt input but outputs whatever the GPIO high is.

For example, if 5 VDC works, you could use this:

> **[Voltage Regulator - 5V - COM-00107 - SparkFun Electronics](https://www.sparkfun.com/products/107)**
>
> This is the basic L7805 voltage regulator, a three-terminal positive regulator with a 5V fixed output voltage. This fixed regulator provides a local regula

It will output 5 volts at inputs up to 35 volts.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [May 23, 2021, 7:19pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/6 "2021-05-23T19:19:43Z")

</div>

Do not do that, please.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [May 23, 2021, 7:20pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/7 "2021-05-23T19:20:52Z")

</div>

Here you go:  
 ![Shared with CloudApp](https://p9.f1.n0.cdn.getcloudapp.com/items/rRujpB7g/4ab79e07-a931-4939-bfff-398e61d0c86c.jpg?source=social&v=6f0de53d75bfa5093cf721734b2968e2)

The grounds can probably be connected, but since you are optically isolating, it might be nice to keep everything separate.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [May 23, 2021, 8:21pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/8 "2021-05-23T20:21:55Z")

</div>

The right way is **beowulff** ’s optoisolated circuit. The quick-and-dirty way, if you have connected grounds, is to just use a resistive voltage divider:  
22 V signal → 100k resistor → GPIO input → 10k resistor → gnd

That divides the 22 v down to 2 v, which is compatible with the RasPi input. But it does require the ground to be connected, which you may not want.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [May 23, 2021, 11:44pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/9 "2021-05-23T23:44:12Z")

</div>

Now _that_ is helping a friend out. Very cool.

With my meager electronics knowledge I had been thinking of either a simple voltage divider or some kind of regulator approach (with a little hand waving added), but just don’t know enough to understand the pros and cons.

I’ll use the optoisolator approach and keep the grounds disconnected for a couple of reasons: For starters, the voltage on the Seeburg is -22vdc with respect to ground, so as long as I don’t have to connect the grounds, I just call that “ground” and use the chassis ground as the +22vdc.  
The second reason is that the voltage appears to be directed to the coil of the motor relay–the jumper on the jack provides a path to ground for the current coming from the coil–so I just don’t want to worry about inadvertently letting enough current flow to trip the relay or having any weird stuff happening with the Pi because of that coil.

Thanks to everyone who answered, it’s awesome when folks with knowledge in the field give solid advice to a hobbyist like myself.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [May 23, 2021, 11:56pm UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/10 "2021-05-23T23:56:16Z")

</div>

It’s always good design practice to isolate delicate electronics from older, high-voltage ones. It only takes a few µS at 5-7v to destroy the port pin (and possibly the entire processor) of the Pi.  
Also, if you are dealing with audio, it’s nice to isolate the digital part to keep potential interference at bay.

---

<div class="post-metadata">

**Author:** ![DrDeth](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@DrDeth](https://boards.straightdope.com/u/DrDeth)\
**Post date:** [May 24, 2021, 12:00am UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/11 "2021-05-24T00:00:43Z")

</div>

I want to congratulate the OP on the most specific question I have ever read here, and on **beowulff** ’ and others very specific fast answer. My hat is off!

😲 🤠 👏 👍

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [May 25, 2021, 12:58am UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/12 "2021-05-25T00:58:31Z")

</div>

That stuff is cheap as chips. I just ordered a handful of resistors, optoisolators, and a few old-school terminal lug strips. Looking forward to getting this up and running!

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [May 25, 2021, 1:33am UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/13 "2021-05-25T01:33:49Z")

</div>

I can tell you MIDI connectors use opto-isolators. I have used them too as part of some DIY laboratory electronics.

---

<div class="post-metadata">

**Author:** ![3AxisCtrl](https://avatars.discourse-cdn.com/v4/letter/3/ecd19e/32.png) [@3AxisCtrl](https://boards.straightdope.com/u/3AxisCtrl)\
**Post date:** [May 25, 2021, 11:28am UTC](https://boards.straightdope.com/t/how-can-i-turn-on-a-raspberry-pi-gpio-pin-based-on-presence-of-22vdc/942751/14 "2021-05-25T11:28:08Z")

</div>

> [@minor7flat5](#):
>
> … cheap as chips.

Yes - the qty 1 price for the optoisolator is under $0.60.
