Temperature Activated Fan! – The Learning Circuit
20K views on YouTube
DaftMike built a thermometer using an Arduino and a thermistor. He expands on this to show you how to build a temperature controlled fan for your desk. It monitors the room temperature to see if it gets too hot. When it’s too hot, an Arduino turns on a fan that cools you off! Visit The Learning Circuit: http://bit.ly/2zNsMiC
Visit sudo Sergeant: http://bit.ly/2LrmXIY
Visit The Ben Heck Show: http://bit.ly/2Lkir2e
Visit Project14: http://bit.ly/2uPuRoD
DaftMike goes over the code from last time. It reads a thermistor and prints the temperature to the serial monitor. He moves all the equations he wrote earlier into four separate functions. A function is like its own little program. In Arduino code there is always a setup and a loop function. The setup is at the start and only runs once. The loop comes after that and repeats continuously. Taking the equations from last time, he re-writes them so that they each have their own separate function. The main loop uses these functions to execute the code. Structuring your program this way makes it easier for you to reuse parts of your code. For example, if you wanted to add another temperature sensor then all you would need to do is call these functions again and pass them a different value. It saves you time as well as some program memory. For it to work, he’ll need to add a couple more functions. One for turning the fan on and one for turning the fan off. He’ll also need to set up the built-in LED as an output to stand in for the fan during testing. When that is done, he tests the code.
After testing the code, he notice that when the temperature gets close to the trigger point it flashes. This is not what he wants. The way to fix this is to add what’s called hysteresis. Hysteresis is the dependence of the state of a system on its history. It’s when the output of your system, in this case the fan or the LED for now, lags behind the state of your input, which in this case is the room temperature. Returning to the code, instead of a single trigger point, he’s set some thresholds to check. There’s a high threshold and a low threshold. As long as one number is lower than the other you can use code to check if the temperature is higher than the high threshold and switch the fan on for true. You can then use a conditional statement to perform a check to see if the temperature is lower than the low threshold to turn the fan off. He proceeds to test the new code. Once the code is fixed, you can replace your test LED with a real fan. Arduino pins can only supply a small amount of current, around 20 milliamps. This is good for LED but you’re going to need additional circuitry for something more powerful like a fan. You could use a relay. A relay is a type of switch that’s controlled by a magnetic coil. In this case, DaftMike wants to use an existing fan that plugs into the mains so he uses a remote controlled outlet, originally designed for Raspberry Pi.