If it is safe to connect a 12V fan via usb to the Rpi3 then can you also tell is it feasable to code in python to control fan via USB that is to switch it on and off.

Please do help as soon as possible as am very close to the deadline to complete my college project.This is a part of my project

  • 3
    USB only provides 5V, it may not turn your fan, and may draw too much power causing your Pi to crash. You cannot switch USB ports on/off.
    – CoderMike
    May 9, 2020 at 16:19
  • Welcome to Raspberry Pi! Please take the tour and visit the helpcenter to see how things work here. Please note our Code of Conduct - in short the be nice policy. Even if you consider yourself to be wronged please do not respond in kind!
    – Ghanima
    May 10, 2020 at 11:59

1 Answer 1


You need to look at using uhubctl to control power on the Pi USB ports BUT be aware they are not individually controlled (cost reasons I assume).

You may also want to add


to /boot/config.txt (and reboot to make it active).

Pinout of standard USB ports and cables can be found here though normally red is +ve and black ground - I assume you are looking to power a relay with the 5v of the port (though there are a few GPIO ports available you know). The board does not tolerate 5v in the wrong location let alone 12 so double and triple check everything with a meter first...

There are many circuits and HATs / boards with simple relays on them for controlling 12v (some even with diode protection) and a google will show them up (other less intrusive search engines are available).

If the fan has to be powered by USB then I would jump onto eBay or Amazon for a USB fan with diode and BEFORE you jump in with both feet - read this on protection diodes DO NOT skip this - you can blow your Pi up messing with power...

Last bit of advice - get projects out of the way WELL before holidays end (in fact ASAP is best) - does wonders for your grades (and general health and mental wellbeing). It also lets you order things, check things and improve things


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.