It’s been a long time since my last post, but I have a legitimate excuse! I bought a house and have been moving in and getting the place comfortable. Then the Christmas holiday came, and I had to move more stuff from my parents’ house, then I bought a car so I’ll have something to drive while I tear my truck apart. Maybe I’ll have pictures of the house and the car in a later post. For now, I must document my first house-related project.

What I wanted was a way to have the bathroom fans run for a set amount of time after I was done taking a shower in order to suck the humidity out and prevent mold from growing in the bathroom (a serious concern in South Florida, which is already a substantially humid area). My options were either turn the fan off when leaving the bathroom and risk high humidity levels, or leave the fan on and waste energy. I figure there was a solution for me out there.

I decided I could program an ATtiny45 to do this job. My goal originally was for the microcontroller to measure how long I had the lights on, and turn the fan on and leave it on for an appreciable amount of time after I turned the light out. It took me a while to hammer out the program, but I learned all about Interrupt Service Routines and some of the registers while I was doing the coding.

I used an old cell phone charger to get 5V DC from the 120 AC in the gang box. Luckily the electricians who wired my house ran the neutral to the gang box as well, otherwise this project would have been shot. Without the neutral wire, this would have tripped the house-wide GFCI every time the light or the fan in the bathroom was switched on. That would have been inconvenient. Additionally, using the cell phone charger is great for power efficiency; when neither the light nor the fan is on, I do not have the tools sensitive enough to measure how much power it uses (meaning less than 5 mW are consumed when it is idling). When both are on, the whole thing uses only about 3.5 watts (but presumably saves me a lot of money over simply leaving the fan on).

I used timer interrupts to crudely measure how long the light had been on, and a rising edge interrupt on  one of the pins to toggle the fan (in case it was on, turn it off if you wanted, or vice versa). I decided on 90 seconds for the light to be on before the fan gets turned on (to allow for bathroom activities that are NOT showers) and an hour and a half of fan run time after the light turns off.

Trying to squeeze everything into the gang box without making too many modifications. I had to trim two of the wires down that lead to the fan, which hopefully won’t be that hard to fix if I ever decide to sell the house and take this monstrosity with me.

Hooking up the switch for the light, which now no longer switches 120V AC. It now is only a logic switch for the microcontroller to tell the program to turn the relay on that is connected to the light. I wanted to use some of the original hardware though.

(Almost) finished. Those two wires will be attached to the toggle button for the fan. For now it works just fine without. I’m planning on using some bondo to modify another face plate to accept the new switch. The best part about this project is that now that I am done, I allowed myself to buy the parts from Digikey that I need to build something I’ve wanted to build for a long time. I had to finish this one first before starting on it though, and everyone knows how much I disapprove of programming. So I had to give myself some incentive. But hey!

Join the Conversation


  1. That’s quite a nifty project you have. While some fans come pre-installed with this function, most of them don’t and rely on intricate wiring from the homeowner or electrician’s part to pull off. The easiest setup I’ve seen is having a lightbulb plug extension and hooking the exhaust fan from there, but that seems a bit crude despite being effective.

    Staci Severns

Leave a comment

Leave a Reply to Ceiling Fancity Cancel reply

Your email address will not be published. Required fields are marked *