I just bought a case with fa , as pi 4 is not working great without it. Now temperature is low, but as I have it in my room, I would like to turn it off while sleeping.
When I shutdown the pi, fan is still active, so I have to physically unplug power, which is not so great.
Is there a way to shutdown fan at the same time than pi ?
How to turn off Rpi4B case’s cooling fan without pulling the power plug?
There are many ways, including the following:
(1) Get a case with a manual power switch (Reference 2).
(2) DIY a manual cable power switch (Appendices A to C).
(3) Using Rpi GPIO to control a software switch to turn on/off the power supply for the cooling fan (Ref 6, Appendix C)
(4) Use a WiFi power plug, such a Sonoff (Ref 8 ~ 23).
(5) Use extreme passive cooling (Ref 24), using effective heatsink which is even better than a cooling fan.
(6) @Dmitry Grigoryev points out one thing I never thought of – When Rpi is shut down, 3v3 is also shutdown, even 5V power to Rpi is still on. So there are two get arounds, (a) Use Rpi 3V3 to drive the cooling fan, (b) Use a step up regulator to convert Rpi 3V3 to 5V, or even to 12V to drive a cooling fan.
(7) Ref 24’s extreme passive cooling WITHOUT a fan performs better than a regular cooling fan. So this the quietest or perfect solution. Another similar method is to use the ICE Cooling Tower Fan 2.0 (Ref 27), which, if not using fan, should be as good (I guess) as the OP’s cooling fan. (I once used a similar water circulation tubing heat sink PC graphics card, WITHOUT a fan, therefore very quiet, and PC chassis also uses fans with double bearing, or magnet bearing，so very quiet for my recording studio, …)
Discussion Notes #1 – 2019oct04 hkt1635
The OP commented that my answer does not meet his requirement, which is summarized below:
Lying in bed, after watching a movie, shut down the Rpi as a PC, without leaving the bed. Therefore a local switch near the Rpi but too far from bed won’t do.
Now let me consider some cases and see if I can produce a real solution.
Case 1 – The OP sits in front of Rpi on a desk, starts the VLC Media Player, selects a movie, then walks to his bed, lies on bed and starts watching the movie. He does not want to leave the bed anymore, and wishes NOT to get up and walk to the wall socket to switch off the wall wart.
Now either he changes his present Rpi case without a manual power switch to a new one with manual power switch, or DIY his own switch, IF the switch is “local” to Rpi but remote from bed, then he has to get up to reach the switch.
In other words, if the switch either comes with the Rpi case, or DIY inserted, does NOT solve the problem.
Case 2 – I have thought about a couple of more possible solutions, including the following:
(2.1) Use a mobile phone to switch Rpi, and then case power,
(2.2) Use a remote controller (similar to TV remote) to switch off Rpi and then case power, or just cooling fan power, which is easier.
(2.3) Lengthen the power cord at either or both ends of the manual power switch (Appendix A, Tamiya socket labelled “B”). This way, the OP needs to carry the switch with a dangling long power cord to bed. But this method is easy. One problem is that Rpi won’t be properly shutdown.
(2.4) use a WiFi power socket, …
(2.5) Extract the two wires connecting to the fan, extend the wires and added manual switch. This is easy but messy.
I need to ask the OP to confirm if I indeed understand his situation, and more details of his user requirements, before I suggest more solutions.
Discussion Notes #2 – 2019oct05 0938
(3.1) Use a USB powered cooling fan, extend the USB cable to bedside, and without leaving the bed, just pull the USB plug to turn off the fan (Ref 7). This 40mm cooling fan is brushless, double bearing, and might be much more quiet than your Rpi case’s built in fan. You can also find “magnetic” bearing which is even more quiet.
(3.2) And you can add temperature sensed PWM fan speed control, so if the Rpi is not playing video, Rpi becomes cool, the fan will automatically run at very low speed, or even stops. Now you can have a nice sleep, …
Case 4 – Updated 2019oct06hkt1204
In Case 2.4 above, I suggest using a WiFi power switch such as Sonoff, but I am not sure if the OP is confident to to the wiring of 200VAC wires. I also googled IoT Stack Exchange and found 50+ posts on uggest using a WiFi power switch, but I am not sure if the OP is confident to to the wiring of 200VAC wires. I also googled IoT Stack Exchange and found 50+ posts on Sonoff, including how to use Sonoff’s GPIO pins to do other things (Perhaps turning on/off the OP’s case’s cooling fan, as well as the Rpi power.
Again, this is a bit risky and not recommended to newbies. So in case if the OP is interested in the approach,
I would suggest the OP to move this question to IoT Stack Exchange, …
For those those are interested to learn about Sonoff, IoT MQTT, ESP8266 etc, and dare not to touch the dangerous 200VAC mains, you can consider doing the following experiments.
(1) Open the Sonoff cover (it is hacker friendly, takes your less than 3 seconds)
(2) Study the schematic, find where the AC200V to 3V3 transformer output, remove the AC circuit, supply your own 3V3 power. Update (Ref 22 Youtube has a very good description of how NOT removing AC to DC converter circuit and can just supply your own 3V power from Win10 USB to UART TTL.)
(3) Find the ESP8266 chip’s TxD, RxD, GPIO pins and use Rpi ESP8266 IDE to program the ESP8266.
There is a tutorial (Ref 20) on how to use LUA to program the ESP8266/ Sonoff smart switch. This tutorial is simple because it does not make use of any cloud, third party server, MQTT broker, you just use your smart phone to WiFi talk to ESP8266 whose pins can do the following: (1) switch on/off Rpi (logic or power circuit), (2) switch on/off cooling fan, with the help of ddriver 2N2222.
WARNING: I myself have not tried it. So there is no guarantee that something won’t explode!
/ to continue, …
(10) Sonoff User Guide
(21) Sonoff Schematic
Appendix A – Power Switch DIY Notes 1 – Cutting power cord to insert switch
Appendix B – Power Switch DIY Notes 2 – Switch inserted
Appendix C – Rpi4B + PSU – Power Switch Testing OK
Appendix E – Sonoff Smart Remote Control Wifi Switch
Supports 2.4G WIFI router and 2/3/4G mobile network (5G router not supported)
Power Input – 90 ~250VAC
Maximum load current – 10A
Only use “eWeLink” free app.
Security Mechanism: WEP/WPA-PSK/WPA2-PSK
Remote ON/OFF: Turn electrical devices on/off from anywhere
App Support: Free IOS and Android mobile App eWelink
Sync Status: Real time device status provided to App
Timing: Set scheduled/countdown timers to turn on/off at specified time
Scene: Turn on/off a gang of devices one tap
Smart Scene: Trigger on/off by temperature, humidity or other environmental conditions
Sonoff Basic Switch works with Amazon Echo,Echo Dot,Amazon Tap and Google Home to manage your devices through Voice control
Sonoff Switch transmits data to a cloud platform through the Wi-Fi Router, which enables you to remotely control the connected appliances, via free eWeLink App.You can download the iOS version in App Store and the Android version in Google Play.The App eWeLink enables you to control your devices easily
Set timing schedules for the appliances, which can include countdown, scheduled on/off
- Switch off electricity source
- Open the covers at both ends
- Connect the two electricity source cables (Live and Neutral) to the ports with “IN” mark, one cable for one port, and there’s no limitation for which port to connect
- Connect the two appliances cables(Live and Neutral) to the two ports with “OUT” mark, one cable for one port, and there’s no limitation for which port to connect make the cover install firmly
End of Answer
If the fan is connected to the 5V and GND pins then they are not controlled by software. Those two pins are directly connected to your power supply, so as long as the power supply is connected and turned on at the wall socket your fan will continue to run.
Use gpio-fan. See this for reference: https://hackernoon.com/how-to-control-a-fan-to-cool-the-cpu-of-your-raspberrypi-3313b6e7f92c and https://github.com/spritrl/rpi-fan
Do not use an NPN transistor, it may or may not switch on perfectly with 8mA. Use a MOSFET, something like a BS170 (TO-92) or IRLZ24N (TO-220, big) and switch it neatly with 3V3. But really, the circuit specifics are “use what you have”.
You will need to adjust your temperature threshold to an appropriate value. Generally, you want to keep the CPU temperature lower than 70°, or more ideally 60°, for longevity, and to mitigate thermal stress on components. Using an init.d script or rc.local is a matter of taste. It hardly seems worth it to make a service file.
The easiest solution is to get a really quiet fan which you can leave running overnight. Personally I got a GPU cooler with a 12V fan: it still rotates reliably when powered with 5V, but at a much slower speed which makes it totally silent unless I put the case to my ear.
If you already bought a fan and it’s 5V, I would try to plug it into 3.3V to see if it becomes silent enough, while still providing sufficient airflow. AFAIK 3.3V is also switched off when the RPi is shut down.
Also, if your fan doesn’t include a heatsink and the cooling is sufficient, you could try the opposite: get rid of the fan and attach a passive heatsink to the chip.