# Converting a 5V output to a 3.3V input for the Raspberry pi GPIO

Hi everyone, I’m stumped by this. Basically, I want to programmatically determine whether my TV is switched on. Luckily, my TV has a USB port (I assume, for firmware updates) which is only powered when the TV is on. I’m thinking of using a USB breakout cable (USB Type A Plug Breakout Cable with Premium Female Jumpers - 30cm long | Adafruit ADA4448 | Core Electronics Australia), and wiring the +5V and GND to a GPIO and GND pin on my Raspberry Pi.

Of course, I’m going to need to convert the +5V output down to 3.3V so I don’t fry my Pi.

I was looking at logic level converters, but I’m not sure if I need one of these as I don’t need to convert a signal - all the Raspberry Pi needs to do is determine whether there’s voltage on the GPIO pin.

I also looked at this MPM3610 3.3V Buck Converter Breakout - 21V In 3.3V Out at 1.2A | Adafruit ADA4683 | Core Electronics Australia, but I’m just as clueless as to whether this would work.

Or am I overthinking this? Would it be safe to just use a pair of resistors like I googled here (How to Level Shift 5V to 3.3V | Random Nerd Tutorials)?

I’m very wary of damaging my Raspberry Pi.

1 Like

That arrangement would be quite safe. You can google ‘voltage divider’ to get a full explanation. As a logic high is any voltage between 1.8V and 3.3V, you can be conservative and do the calculation for the voltage divider for an output of something like 2.0 to 2.5V.

3 Likes

Brilliant, thank you!

2 Likes

Hi Steven

You might find that this an input for video on a flash drive. Looking at your TVs input sources will give you a clue, could be under the heading “Media”.

I think any updates come via an internet connection on a “smart” TV.

You don’t. If they are of the bi-directional type with a Mosfet they provide the voltage shift via a 10k resistor and are not capable of providing current, Voltage only into a very high impedance load. BUT I think your RPi GPIO pin is such a high impedance (someone with RPi experience might like to jump in and confirm or correct this) so would probably work.
Having said that there is no need to overcomplicate things and as suggested a simple voltage divider will do the trick. Resistor values??? 1k8 and 3k3 in series across the 5V will provide about 3.3V across the 3k3 resistor. Or any multiples of these values will do up to about 18k and 33k. The GPIO input impedance should be high enough so you can ignore any modification due to load resistance.

One question. What is wrong with the indicator LED on the TV for visual indication.
Cheers Bob

3 Likes

Hi Steven,

As Jeff and Bob have already covered a voltage divider circuit should suit your project.
Spakfun have a particularly good guide that covers them if you wanted to read into the why as well as the how.
https://learn.sparkfun.com/tutorials/voltage-dividers

1 Like

Thanks everyone. I think I’ve got it. Assuming I want to halve 5 to 2.5, I’d simply need two resistors of the same resistance. Does it matter what resistance they are?

It’s been a long time since high school physics. Assuming it’s USB 2.0, the current would be 500 mA.

`R=V/I = 5/0.5 = 10Ω`
`P=VI = 5*0.5 = 2.5W`

So I’d need resistors rated for at least 2.5 watts, with a resistance of around 10 ohms.

Is the method of my calculations correct? (I can always get a multimeter to find the exact output from the TV to be safe).

This is my plan:

Thanks again for all the help.

1 Like

Your method is correct but you don’t need anything like 0.5A. You are supplying a voltage level for a very high impedance load, not a current source to power something. So a total resistance of anything between about 2,000 ohms and 10,000 ohms would work. The higher the total resistance the lower the load on the supply. In this case the TV would likely be able to supply 0.5A, but that means you need very high wattage resistors and there would be a lot of heat. Keep the current very low and use small 1/4W or 1/8W resistors.

3 Likes

Thanks @Jeff105671 that’s starting to make sense now.

Hi Steven
The TV USB is CAPABLE of supplying 500mA. That does not mean you have to USE 500mA. The numbers I gave you previously would use 1mA which would be accommodated easily. I would not go any lower that these as you would only be using power for nothing.

Otherwise your basic assumptions are correct. If you wanted half voltages 2 equal value resistors would give you this assuming a high resistance load.

Assuming R1 is the upper resistor and R2 is the lower resistor the output voltage calculation would be.
Vout = (Vin / (R1+R2))*R2. R1 and R2 values must be the same multiplier ie; both Ω or both kΩ etc but not mixed.
Cheers Bob

3 Likes

A safe way of doing this is using an optocoupler. This completely isolates the TV and Pi. Core have one - PS2501-1. Here is a generic circuit I found.

Loop 1 is the USB side, Vdd is the 5V and R1 is fine at 500 ohm. Loop 2 Vcc is 3.3V supplied from the Pi side, 3K ohm should also be fine. Vout is high if the TV is off, goes low when turned on. Just about any optocoupler would work for the purpose, the PS2501-1 is probably overkill.

Note that the two earths are not connected. Loop 1 earth goes back to the TV, Loop 2 goes back to the Pi.

You can have up to 1000V between the two system (not that it is likely) without a problem. For less than \$2, this is cheap insurance.

2 Likes

Hi Alan

If you are crawling around your lounge room carpet (or any other carpet for that matter) you could have a lot more that that
Cheers Bob

1 Like

Thats really helpful Alan, I’ve never heard of such a component before. Isolating the two circuits sounds like a good idea to me.

1 Like

@Alan73922 tested out your solution and it worked like a charm.

For @Robert93820 and anyone who’s interested, this is so I can automatically turn on my stereo at the same time as my TV. Not only do I need a way to programmatically turn on/off the stereo (I’m going to use an off the shelf WiFi IR blaster for this), but also a way to determine whether the TV and stereo are switched on at any given time.

The stereo is plugged into the TV via an analog input, but can also act as a USB audio device. So it was trivial to connect the stereo’s USB to one of the Raspberry Pi’s USB ports and code a script to poll the ports to see if it’s connected.

The TV isn’t a smart one, so I need the method of detecting voltage from the TV’s USB input on a GPIO pin (otherwise I’d just ping the TV’s IP address).

I also plan to integrate the thin client I use for retro gaming into this setup (for that I can simply ping the computer to see if it’s on).

Sounds like a lot of work just to avoid pressing a few more buttons on the remote(s), but hey, where’s the fun in that.

Just need a few more parts before everything is complete.

Thanks everyone for all your help!

2 Likes