I have a digital microscope connected to my pi (usb) that you can use in a browser with a java web app that I have written. The microscope is also powered through the usb. There is no on or off switch, whenever you power on the pi, the microscope is turned on as well. I don't like this and I would like a button on my webapp that can turn on/off the microscope. I thought about doing this by cutting off the power to the microscope by using a usb-relay of some sort that I can control with the pi. But I'm not sure how to do this. So normally I just plug in the usb in my pi and whenever you press button x the webapp shows what the microscope 'sees'. But as said the problem is that the microscope is powered on the whole time (which I don't like).

My device looks like this:


The setup would be something like: Pi connected to a 'usb-relay', then that relay connected to my digital microscope...or something. From my pi I would then send a command to the relay to allow the digital microscope to receive power (turn on) or not (turn off). The Pi still needs to receive images from the digital microscope. I found something online that would pretty much do the trick I guess: https://www.yepkit.com/products/ykush

But I'm wondering if this could be done with a relay? And if so what kind of relay would I need?

  • 1
    Is this a solution stackoverflow.com/questions/59772765/… It may depend what else you have plugged in where. I would try via SSH just in case you turn they keyboard off and it does not respond when plugged into another port :-)
    – user130616
    Commented Mar 13, 2021 at 15:28

1 Answer 1


Most well-behaved USB devices have a sleep mode which is activated when no active communication is taking place. If this is the case, simply unloading the driver will effectively power down the scope.

Otherwise, I would check out uhubctl mentioned by @Andrew. On a Pi4, you can control all 4 ports simultaneously, which will not do if you have other USB devices you need to remain powered. Connecting the microscope through a USB hub might help, but I suppose that depends on the hub.

You could, of course, use a relay to cut the power. I would avoid this solution if possible, as it will take time to implement and will not be strictly USB compliant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.