Having a mold problem in your home is terrible, especially if you have an allergy to it. It can be toxic, aggravate asthma, and damage your possessions. But let’s be honest, before you even get to those listed issues, having mold where you live feels disgusting.
You can clean it with the regular use of unpleasant chemicals like bleach, although only with limited effectiveness. So I was not particularly happy to discover mold growing on the kitchen wall, and decided to do science at it. Happily, I managed to fix my mold problems with a little bit of hacker ingenuity.
What Level of Humidity Leads to Mold?
I did some research into the underlying causes of the issue. We know mold loves moisture, but the specific root of the problem seems to be a high relative humidity in the surrounding air.
There is a limit to how much water vapor the air can contain at a given temperature. Relative humidity is the percentage of that water vapor limit at the current air temperature. High relative humidity also makes condensation worse, another source of moisture for mold growth. The thing to know is that moisture is our enemy here and the unit of measure that gives us the most reliable information about that is relative humidity.
A study done in Tokyo (PDF warning) seemed to show that the magic number is a bit below 70% relative humidity. Below that, the types of mold being studied grew much less. A previous study (PDF warning) described that the relative humidity required for mold growth was highly dependent on the surface in question; staying below 76% relative humidity prevented mold growth on most surfaces they studied. However, the Japanese study specifically dealt with walls in homes. The United States Environmental Protection Agency recommends below 60%.
Measuring My Home’s (Really High) Relative Humidity
Here in Southeast Asia, humidity below 60% is not really a thing for most of the year. Ever see packaging that says ‘store in a cool, dry place’? Better not to bring those things here.
Anyway, I had taken some quick measurements with a DHT11 combined temperature/humidity sensor while investigating IoT data logging platforms. They showed a range of 52% to 70% outdoors (we’re at the end of rainy season presently), drier in the mornings and more humid at night. In any case, with proper ventilation alone, it looks like 70% relative humidity or lower is achievable.
I repeated the measurement in the problem area of the house, and recorded a consistent 86% relative humidity! That was clearly problematic so I considered solutions. Running an air conditioner all the time was not practical. We’ve seen a couple of projects out there addressing mold problem with dehumidifiers, and those are sold here at around USD $150 for a small one, but it’s yet another appliance in the house. One effect of population density is that houses here are small.
Building a Smart Fan
My solution is a simple one: up the ventilation. The numbers so far suggest moving the humid air out would be sufficient. I was short a fan in the house anyway, and fans are cheap so there was little penalty if I was wrong.
I didn’t really want to leave a fan on all the time though. It may only use 40 watts, but it’s irritating to hear it, and I had a bunch of parts left over from learning to use gracefully silent solid-state relays. So why not add a humidistat to the fan? Humidistats are like thermostats, but they switch based on humidity rather than temperature.
You know those days when everything just comes together? This was one of those days. The fan had no electronics inside, only switches that connected mains power directly to ‘something’ further in the fan.
As much as possible, I avoid using solder for anything that uses mains power. In this case though, the wiring was just soldered to brass conductors already, and moreover, there were perforations in it that exactly fit the wire I had. As a result, all I had to do was put the solid-state relay across the switch for the fastest fan speed, and I had an OK test system:
I used a DHT11 combined temperature/humidity sensor to track humidity, interfaced with a Wemos Mini D1 board running NodeMCU to control the relay. A small mains to 5 volt module powered the control system. I wrote up a quick Lua program to control when the fan should be on:
gpio.mode(2, gpio.OUTPUT) gpio.mode(1, gpio.OUTPUT) gpio.write(2, gpio.LOW) gpio.write(1, gpio.LOW) pin = 4 x = 'off' function currentlyon(level) status, temp, humi, temp_dec, humi_dec = dht.read(pin) print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03drn", math.floor(temp), temp_dec, math.floor(humi), humi_dec )) print('Currently ON. Temp:'..temp..' ,Humidity:'..humi) if humi < 66 then gpio.write(2, gpio.LOW) x = 'off' end end function currentlyoff(level) status, temp, humi, temp_dec, humi_dec = dht.read(pin) print('Currently OFF. Temp:'..temp..' ,Humidity:'..humi) if humi > 68 then gpio.write(2, gpio.HIGH) x = 'on' end end function statuscheck() print('Checking Status') if x == 'on' then currentlyon() elseif x == 'off' then currentlyoff() else print('Invalid state') end end tmr.alarm(1, 20000, tmr.ALARM_AUTO, function() statuscheck() end)
A Simple Hysteresis Example and the Hunting Problem
The humidity required to change the state of the fan depends on whether the fan has last switched from on to off, or from off to on. This is called hysteresis: the state of the system depends on it’s history, and it’s an inelegant but easy way to avoid a common control issue called ‘the hunting problem’.
Hunting problems can be an issue in closed-loop control systems, where the behavior of the controller depends on feedback from a sensor coupled to the process you are measuring. In our situation, if we simply set the target humidity to 70%, then the fan will get to that value and turn on or off frequently due to small fluctuations in humidity. The fan can only be completely on or off, and neither of those states result in the target humidity being reached for long.
As in our case an acceptable humidity is a rather wide range, we set the fan to turn on at anything over 68% humidity, and once on, turn off under 66% humidity. The sensor resolution is 1%, so that’s a 4% range which seemed reasonable to start.
Some quick tests were run by blowing into the sensor, and it all worked as expected. The humidity problem tentatively solved, I put on protective gear and bleached the mold as best I could. Since then, it hasn’t returned.
It Works! Now Make It Better
Some improvements were added afterwards. Initially, the control system just toggles the fan in response to humidity by taking control of the actual switch. This means it doesn’t work well as a normal fan – it can ignore your speed selection depending on humidity! It would be better to interrupt the main power line with the solid-state relay, and have the control system default to the fan being on. Only when a dehumidifier function is selected (a switch), the control system will then connect or disconnect power to the fan as needed.
In the end that was an easy update. I removed the relay from the fan switch, added it as above, and added a toggle switch that connects GPIO D5 on the Wemos Mini D1 to either +3.3 volts or ground. Then I updated the code as below, assembled everything into the fan case, and it just worked:
gpio.mode(2, gpio.OUTPUT) gpio.mode(1, gpio.OUTPUT) gpio.write(2, gpio.LOW) gpio.write(1, gpio.LOW) gpio.mode(5, gpio.INPUT) pin = 4 x = 'off' function currentlyon(level) status, temp, humi, temp_dec, humi_dec = dht.read(pin) print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03drn", math.floor(temp), temp_dec, math.floor(humi), humi_dec )) gpio.write(2, gpio.HIGH) print('Currently ON. Temp:'..temp..' ,Humidity:'..humi) if humi < 66 then x = 'off' end end function currentlyoff(level) status, temp, humi, temp_dec, humi_dec = dht.read(pin) gpio.write(2, gpio.LOW) print('Currently OFF. Temp:'..temp..' ,Humidity:'..humi) if humi > 68 then x = 'on' end end function statuscheck() fanmode = gpio.read(5) print (fanmode) print('Checking Status') if x == 'on' and fanmode == 1 then currentlyon() elseif x == 'off' and fanmode == 1 then currentlyoff() else print('Humidity mode inactive. Fan always on.') gpio.write(2, gpio.HIGH) end end tmr.alarm(1, 5000, tmr.ALARM_AUTO, function() statuscheck() end)
As a final note, solid-state relays of this type should normally have heat sinks attached, but I’m using it at a very small fraction of the rated current. It does not heat up perceptibly even after running for a long time. This large relay is overkill, as there are many smaller and cheaper options more suitable for the low currents used by the fan, but I had it on hand… so in it went.
There are many ways I could have tackled my mold problem. The most eloquent turned out to the a little bit of head scratching, and a lot of fun.