|
| 1 | +# Example module Microsoft.PowerShell.IoT.Fan |
| 2 | + |
| 3 | +This PowerShell module is for turning on/off a fan on Raspberry Pi 4 case enclosure. |
| 4 | +This showcases GPIO functionality of [the Microsoft.PowerShell.IoT module](../../README.md). |
| 5 | + |
| 6 | +## Hardware setup |
| 7 | + |
| 8 | +[This Raspberry Pi 4 case enclosure](https://www.amazon.com/gp/product/B07XTRK8D4) comes with a 5V fan that can be connected to Raspberry Pi 5V and GND pins. |
| 9 | +This fan is nice but a little noisy so we can use this example module to turn it off when the CPU temperature is relatively low. |
| 10 | +An [IRLB8721 transistor](https://www.adafruit.com/product/355) can be used to switch power to the fan based on GPIO line of Raspberry Pi. |
| 11 | + |
| 12 | +## Wiring |
| 13 | + |
| 14 | +Insert IRLB8721 transistor into the break of the negative wire of the fan. |
| 15 | +Connect transistor gate to GPIO 17 (BCM schema) on Raspberry Pi. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +## Software setup |
| 21 | + |
| 22 | +### Install PowerShell Core on Raspberry Pi |
| 23 | + |
| 24 | +Installation instructions can be found [here](https://github.com/PowerShell/PowerShell/tree/master/docs/installation/linux.md#raspbian). |
| 25 | + |
| 26 | +### Start Powershell and install modules |
| 27 | + |
| 28 | +```powershell |
| 29 | +pwsh |
| 30 | +
|
| 31 | +Install-Module -Name Microsoft.PowerShell.IoT |
| 32 | +
|
| 33 | +git clone https://github.com/PowerShell/PowerShell-IoT.git |
| 34 | +``` |
| 35 | + |
| 36 | +### Usage |
| 37 | + |
| 38 | +```powershell |
| 39 | +# Start monitoring CPU temperature and turn on the fan when it reaches 71 degrees; turn fan off when CPU temperature drops below 55 degrees |
| 40 | +pwsh ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.Fan/SmartFan.ps1 -Pin 17 -OnTemperature 71 -OffTemperature 55 -TemperatureScale Celsius |
| 41 | +VERBOSE: 1:36:05 PM: CPU temperature = 71.575 C | 160.835 F |
| 42 | +VERBOSE: Starting fan... |
| 43 | +VERBOSE: 1:36:10 PM: CPU temperature = 70.601 C | 159.0818 F |
| 44 | +VERBOSE: 1:36:16 PM: CPU temperature = 70.114 C | 158.2052 F |
| 45 | +VERBOSE: 1:36:21 PM: CPU temperature = 68.653 C | 155.5754 F |
| 46 | +#... |
| 47 | +VERBOSE: 1:39:01 PM: CPU temperature = 55.504 C | 131.9072 F |
| 48 | +VERBOSE: 1:39:06 PM: CPU temperature = 55.504 C | 131.9072 F |
| 49 | +VERBOSE: 1:39:11 PM: CPU temperature = 54.043 C | 129.2774 F |
| 50 | +VERBOSE: Stopping fan... |
| 51 | +VERBOSE: 1:39:17 PM: CPU temperature = 55.991 C | 132.7838 F |
| 52 | +#... |
| 53 | +``` |
| 54 | + |
| 55 | +This produces following CPU temperature graph: |
| 56 | + |
0 commit comments