A smart fan that can react to changes in temperature to adjust the speed of a fan is useful in intelligent cooling scenarios that need to conserve power and keep a device (such as a CPU) cool. This project will demonstrate how to create a smart fan and how the Digi-Key IoT Studio can be used to do more than just read sensor values and then send them to a device app; this project shows program logic and control.
Controlling a Computer Fan
In this project, you will learn how to control a DC computer fan with the use of a PWM signal from Digi-Key’s Adafruit Huzzah32. Because the output current capability of the Huzzah32 is limited and cannot drive a fan directly, we need to use a simple MOSFET driver. The transistor that is used in this project, the IRF830, is an N-Type MOSFET that has a gate-source threshold of as much as 4V. This is the minimum voltage needed to get the transistor to start conducting current, which is a problem, as the Huzzah32 is a 3V device. So, we need to use an additional transistor -- a 2N3904 -- as a level converter, so that the 3V signal can switch a 12V signal, which can then be used to control the NMOS.
At this point, it may seem logical to use a single NPN transistor as the fan driver and do without the NMOS, but there is a catch: the output current capability of the Huzzah32! NPN transistors are current amplifying devices and not voltage amplifying devices, meaning they rely on an input current as their driving signal. Since the Huzzah32 maximum output current is 12mA (6mA to be safe), and large current transistors have very low hFE values (anywhere between 20 to 100), microcontrollers can only get these transistors to conduct currents less than an amp. The use of an additional driver stage converts a small current to a large voltage swing that will be used to control a powerful transistor, which can get our microcontroller to drive high current devices.
Programming the Project
The software in this project is broken down into two parts: the device firmware and the smartphone app. The device firmware demonstrates multiple concepts, including reading ADC pins, evaluation, and variables. An interval element is used to initiate the program sequence, which is set to trigger ten times a second. On each trigger, the ADC pin, A2, is read for its raw value. When this value is retrieved, it is sent over a Bluetooth element to the smartphone for displaying on the app.
You may be wondering why A2 is used instead of A0; the reason is that A0 is not usable when the Wi-Fi module is enabled, and since this is near impossible to turn off, it is better to just use an ADC pin that can be used. Therefore, A2 is the first feasible ADC pin on the Huzzah32!
The value of the ADC reading is sent to an evaluation element, which compares it to a predefined trigger point. The evaluation element produces two outputs: if the ADC value is greater than the target value and if the ADC value is lower than the target value. Each one of these triggers goes into a variable element that sets the duty cycle of the fan.
If the temperature is too cold, then the fan is set to 20% (slow), and if the temperature is too hot, it is set to 80% (fast). These values are used to demonstrate the operation of PWM as 100% (0% would simply be on and off). The value of the too hot and too cold variables is also passed to a Bluetooth element, allowing us to see them in real-time.
The app side of the software utilizes multiple GUI elements, including labels for text display and an analog meter for showing the fan speed. An interval is used for probing the BLE elements for new data, and data relating to the fan speed is sent to the analog meter, while data relating to the ADC read is sent to the ADC read label.
And, with that, you have a Bluetooth-enabled smart fan that runs through the Digi-Key IoT Studio! This is just scratching the surface of the kinds of projects you can build up with the IoT Studio, so stay tuned for more how-to’s and project write-ups in the future!