![]() ![]() Raise RuntimeError('OFF_THRESHOLD must be less than ON_THRESHOLD') Raise RuntimeError('Could not parse temperature output.') RuntimeError: if response cannot be parsed.įloat: The core temperature in degrees Celsius. ![]() Run a shell script to get the core temp and parse the output. GPIO_PIN = 17 # Which GPIO pin you're using to control the fan. SLEEP_INTERVAL = 5 # (seconds) How often we check the core temperature. OFF_THRESHOLD = 55 # (degress Celsius) Fan shuts off at this temperature. ON_THRESHOLD = 65 # (degrees Celsius) Fan kicks on at this temperature. To create this file, run: nano fancontrol.pyĪdd the following to the file, save, and exit: #!/usr/bin/env python3 So we'll connect to the Pi via SSH and create a file called fancontrol.py. We're going to need code that continuously monitors the core temperature and turns on the fan when the temperature reaches a certain threshold. Skip this step if you used the install script above. ![]() So when pin 17 is switched to HIGH, it will send some voltage to the base of the transistor, which closes the circuit and turns on the fan. Lastly, the "emitter" of the transistor is connected to the ground. The positive lead on the fan is connected to the 5v pin, and the ground is connect to the "collector" pin in our transistor. So the "base" pin of the transistor is connected to the BCM 17 (a GPIO pin) with a 680Ω resistor in between. ![]() There are many types of resistors, but we're using an NPN transistor. The transistor is an interesting electrical component used to switch or amplify power. Therefore, we need a way to power the fan using the 5V pin, but switch it on and off using a GPIO pin. Likewise, the Pi's 5V pins are connected directly to the power supply and cannot be controlled via software. GPIO pins could power something small, like an LED, but they shouldn't be used for anything more. It's necessary because the fan requires 5V to operate but the Pi's GPIO pins are only capable of supplying 3.3V. The transistor is the most interesting piece of this circuit. We're only using a few components: the 5V fan (represented by the big DC motor in the image), a 680Ω resistor, and an NPN transistor (2N2222). In this step, I'll provide a breakdown of the circuit. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |