Humidity and Temperature sensing fan controller for a small boat, with battery protector. 

My boat can get quite hot, suffers from condensation, and a permanent fan kept on flattening the battery. 

I have built a small controller based on a Digispark ATTiny85 development board I have lying around and a spare DHT11 combined temperature and humidity sensor. It turns the ventilator fan on and off (and several speeds in between) depending on the temperature, humidity, user input and battery state (voltage).  

Hardware 

KiKad project files, Gerber files and the Case design files are all in this repository.


The circuit is very simple, there is a logic-level mosfet to drive the fan. I used a IRLZ14 for this but almost any logic-level mosfet will do, just make sure it can handle the startup current of your fan.
If your fan is powerful you may need to add a heatsink to the mosfet and make sure heat from it does not affect the sensor.

The Digispark incorporates a 5V voltage regulator (LM7805), which only powers the ATTiny and the DHT11 sensor, the absolute maximum voltage this can handle is 35V,  Digistump themselves recommend a maximum of 16V for the module. Please be careful when disconnecting batteries on boats with solar/fixed charging systems, you may be able to spike the supply voltage enough to damage the controller.
However; it is reasonably robust and may even work for a 24v systems, but no promises, and you will need to change the thresholds in the code ;-)


Here are some picture of my buildup; at this stage I had, ahem, forgotten to put a flyback diode in parallel to the fan. This could be a very bad idea if a high wind decides to spin the fan very fast. It is not visible in my pictures but I added a 1N4007 diode to the underside between the pins of the connector. The revised PCB now has this flyback diode onboard.

Software

See the `BoatFanControl.ino` sketch in the `Software` folder. There are a number of other sketches in there that I used during development, you may find the `*Calibrate` scripts useful to verify your sensors and voltage divider.

The DigiStump boards definitions are installed by adding `http://digistump.com/package_digistump_index.json` to the Boards URL list in the preferences dialog of the IDE. In the IDE.
Select `boards -> Digistump AVR boards -> Digispark (16MHz, no USB)` for programming. The 'No USB' refers to clock speed alignment and is advised to keep the clock stable when not plugged into a USB port.

Please read the notes at the top of the main sketch, by default the Digispark runs the fan at 500Hz, this is possibly audible and might affect fan lifespan (the jury is out, I've seen people arguing both sides quite convincingly). In any case I decided to pump the fan PWM frequency up as high as possible. But this requires modifying a file in the Digispark boards folder, proper details and URL's for reference are in the sketch header.

Operation

Testing is tricky due to lack of resources, serial debug is not practical due to memory and pin limitations. I found it best to test the sensors using the calibrate sketches. Then I ran on the testbench with much 'faster' timeouts (there is a option for this in the sketch), and my multimeters PWM (cycle and frequency) mode to check the output. I also used an identical sensor running on a Arduino Uno + a standard serial output DHT11 example to monitor the environment, and then spent time checking the results while breathing on sensors to trigger responses, and varying the voltage on my PSU.

Low Power

If the battery is good and the fan is running then the power use is dominated by the fan (the mosfet is good to 6A).

But once the voltage drops to powersave levels it is desirable to have the controller draw minimal power to avoid flooring the battery.