USB triggered relay to switch on raspberry pi 3 B+

Thread Starter

j038lack

Joined Jun 1, 2019
4
HI everyone,
My old android Kodi box has just died and I have setup libreELEC on a new Pi 3 B+. As I worked through the may ways to power up and shutdown the unit. I found the Momentary switch on gpio 3 to be the easiest setup. but that got me thinking how hard would it be to attach a single channel 5v relay switch and connect to my usb on the tv. But wait the gpio 3 switch is a momentary switch.

So I ask you, is there such thing as 5v momentary relay module or is there something else I can use in place of one?

looking for a circuit that will take the 5v power from a USB port to trigger a momentary switch to momentarily short the pin 5 and 6 on a raspberry pi 3 B+ and also trigger it again when power is removed.

Any help would be great thanks.
J03
 

dendad

Joined Feb 20, 2016
4,641
You could try something like this..
PiUSBSwitch.jpg
When the power is applied, the transistor turns on with the capacitor charging current and operates the relay.
After the cap charges, the transistor will turn off.
The diode at the cap helps to discharge it when the TV is turned off.

The relay could be replaced with an opto isolator, and if you need a more refined circuit, a similar thing with CMOS logic Schmitt trigger IC or a comparator or even a Dreaded Arduino may be pressed into service. There are many ways to do it.
 

Thread Starter

j038lack

Joined Jun 1, 2019
4
A better way is to add a Pi UPS of some sort so the Pi shuts down safely.
Just dropping the power will eventually corrupt the SD card.
https://core-electronics.com.au/raspberry-pi-ups-hat.html may be ok. I have not used them myself. Also, make the file system read only.
Thanks dendad,
I'm not dropping the power, the Pi will be running on it own proper 5v 2.5 amp power supply. All I am doing is causing the shutdown process via code and putting the Pi to sleep and waking it back up when the 5v is present on the TV's USB port.

I am now thinking of using a 5v time delay relay module maybe 2 channel one on the restart pin gpio3 (pin 5,6) and another on a pin with the shutdown command assigned to it. The time delay module will give me the ability to mimic a momentary switch with a setting of .1sec delay. Just wish there was a way to use only the one gpio port as the new Pi 3 b+ has the startup/shutdown code already build into it. (less coding less errors).

What do you think?
Joe
 

dendad

Joined Feb 20, 2016
4,641
If you are having power on all the time, why shut it down?
have a loop running that looks at a port pin connected to the USB power, with appropriate resistive divider for protection, and put the Pi into sleep mode when the TV is off.
Or, use something like the circuit above to turn it on and then monitor the port to turn it off via the shutdown command.
 

Thread Starter

j038lack

Joined Jun 1, 2019
4
If you are having power on all the time, why shut it down?
have a loop running that looks at a port pin connected to the USB power, with appropriate resistive divider for protection, and put the Pi into sleep mode when the TV is off.
Or, use something like the circuit above to turn it on and then monitor the port to turn it off via the shutdown command.
Thanks dendad,

I looked into the resistive divider and found a few other ways here to trigger the gpio port. this does look like a possible solution but the only gpio port that stays active when sleeping is gpio 3 and I'm not sure how the port will react to being held low with one of these simple trigger circuit.

I did find a relay module that has a (Function #25 output on Trigger change) function that looks perfect. I thought I'd run it by you and see if you have seen one like this before or any other like it.
I figure i could supply the relay with 5V from raspberry 5v output port and connect the trigger to the usb + and connect the relay side to the gpio3 and gnd. setting the t1 and t2 to .5sec and turn on the gpio shutdown for gpio3.

here is a link to the pdf timing charts for the relay.

Thanks again for all the help
J03
 

Thread Starter

j038lack

Joined Jun 1, 2019
4
I was over thinking this problem all I needed was a on/off delay relay to wake the raspberry Pi 3. The shutdown was done from Kodi.

Final Solution..... for power on via USB port of TV
All you need is a 5V Infinite Cycle On Off Timer Delay Relay Loop Timing Module Board


I wired a old USB cable to the +/- 5v side of the module and jumper-ed the trigger so it would activated when the power was applied. I then wired the gpio 3 ( pin5 ) and gnd (pin6) on the Pi 3 to the load side ( no and com ). set the relay to once mode and set for 1/10 scale and adjusted the T1 (turn on) pot till the relay only activated for .5 sec.
On the Raspberry Pi 3 b+ the gpio3 is already setup to wake when forced low, so no change there. In Kodi I setup the power saving to 20 mins so it shutdown if no actions after that time expires and I may map a key for shutdown on my keyboard if I need it.

It works great.
Power on the Pi the first time manually, then shut it down via Kodi. now the next time you power on the tv it will wake the Pi and boot Kodi. shutdown from Kodi and it will sleep unable it is awakened via the 5v usb port on the TV. The great thing about setting it up to wake up only is if you turn the TV on and off multiple times it will only wake once until the power save feature in Kodi shuts it down.

Hope this help
J03
 
Top