My cousin, Johnny, is buying a NAS server for his home and wants to store it in his wardrobe. The space is very small and will heat up quickly, so he plans to run an exhaust fan to keep it cool. The problem is that he doesn’t want the fan running all the time and would prefer that it runs only when it gets to a certain temperature. There are various devices he could purchase to get this done, but I had the parts lying around and a few hours handy to get it built.
Eddy’s Temperature Sensor Relay Device thingy (TSRD) is a project I put together so quickly that I didn’t even have enough time to name it properly.
- Contains an ESP8266 on a NodeMCU board.
- Has a temperature sensor and relays to control power to the exhaust fan.
- Has an LCD screen and buttons for configuration of temperature threshold and fan run time.
- Is powered by a 5v DC power source (ie. mobile phone charger).
- Monitors the temperature and triggers the relays (ie. powers the fan) when a pre-configured threshold is reached for a pre-configured amount of time.
Disclaimer: This project involves dealing with mains house power. Mains power is VERY DANGEROUS and has the ability to KILL YOU. If you aren’t comfortable with messing around with mains power then DO NOT build this project. I am not responsible if you burn off your eyebrows, set your house on fire, zap your cat or kill yourself! You have been warned. Please be careful.
The logic is very simple. Best described using the below points:
- Upon boot the user uses an LCD screen and buttons to enter the threshold temperature in Celsius and run duration in minutes.
- If nothing is entered for a few minutes, the defaults settings are automatically used (these are set in the pre-compiled code)
- Once configured, the TSRD will monitor the temperature until the temperature threshold is met. Once met, it will trigger the relay to allow mains power through to the fan for a configured duration.
- Once the time elapses if the temperature is still above the threshold it will turn the fan on again for the same amount of time.
- This cycle will continue until the temperature drops back below the threshold.
- Once below the threshold, the fan won’t switch back on again until the temperature rises back above the threshold again.
The below video is a demonstration of the finished product
- NodeMCU (this contains the ESP8266). This runs Arduino code
- 10k Ohm thermistor
- 10k Ohm resistor
- 4.6k Ohm resistor
- 56 Ohm resistor
- 3x momentary push-buttons
- LCD screen (2×16 characters with back lit screen)
- Twin relay module
- Mains power extension lead
- Various wires, generic PCB, solder, pins, headers etc…
Step 1 – Breadboarding
The Fritzing diagram shows how the wires should be connected. The most complicated part of it is the LCD screen. There are great tutorials on the internet showing how to wire these parallel legacy devices up, or you can just use what I have done.
You can find the Arduino code for this project at my Github account.
There is a boolean variable in the Arduino code named testing. If you enable this it will cycle through enabling/disabling the relays and ignores temperature and duration settings. It will also count the number of times it has cycled the relays and display it on the LCD screen. Be sure to thoroughly test the device before using it with mains power, then test it again.
The relays say they can handle 10A of current at 250VAC, which means it should be able to run any normal household device. But I STRONGLY advice against using any device which draws too much current simply because the relays will be cycling a lot and with high current draw will be more prone to failure. So even though technically you can, don’t run your heater or hair dryer on it (or anything else which will draw more than a simple exhaust fan).
Step 2 – Soldering
Once you have confirmed all is working with your breadboard version of the project, then it is time to shift it all across to a PCB for a more permanent home.
Step 3 – Install parts in to the enclosure
This step is very important because you are playing with mains power so you want to make sure any wires are safely inside an enclosure and not exposed.
Remember: Mains power is VERY DANGEROUS and has the ability to KILL YOU. Do NOT mess around with mains power unless you know what you’re doing. I take no responsibility for you burning your house down or worse! Please be very careful or have a licensed electrician help you.
Remember to have the thermistor/temp sensor somewhere outside the enclosure.
In case it wasn’t clear above, below is a very badly drawn diagram showing how the wiring for the mains power to the relays should be done.
Step 4 – Testing
This is the most important step. Using the testing variable mentioned above, be sure to cycle the relays with the actual exhaust fan you plan to use. If you can avoid it, don’t leave the device alone while it is being tested. The LCD screen will show you the number of times the relay has either engaged or disengaged, so for every count of 2 the device has done a full on/off cycle. I suggest testing the device for 500 cycles at least before deploying in the field.