Tonight I’m making a little Arduino mains relay timer. It’s for the box fan in my room. The timer built into the fan broke years ago but even before it did, the ticking noise was distracting when trying to go to sleep! But leaving it on all night means I wake up extra dehydrated. Hence, an electronic 2-hour timer for my fan.
Here's the code. (not yet tested tho!)
It compiles to 1222 entire bytes and uses a whole 10 bytes of RAM! I love embedded processors
revisions to code: replace the hardcoded LOW/HIGH with constants, as it turns out the relay module is active-low; replace clockCounting with clockStart and == with >= in the comparison, whoops.
Here’s the finished box plugged in and working. Not very exciting looking, but does the job and hopefully will continue to do so for years!
@kirby unplug it, haha. I can use the off switch on the fan itself if I need to turn it off manually.
@kirby you know what, I think tomorrow I’ll change it so pressing it while it’s on does turn it off. Doesn’t hurt to have that option.
@stibbons yeah, it's one of those things that's definitely good practise, but in this case all I need is to distinguish 0-499 ms press from 500+ ms press! The delay(500) does a good enough job of it -- since I don't have any concurrent timers/tasks, I might as well just hang waiting to sample again. If this was high-reliability I would probably debounce & check a minimum bound on the press duration too.
@s0 Neat! I use a pi with an IR board to control the fan in study. It grabs the inside temperature from my weather station and has a series of rules to turn the fan on/off based on time and temperature.
Not quite as techy as your solution but it does what I need. (if only I could get the a/c to respond to commands).
@dadegroot bet that uses more than 10 bytes of RAM tho 😝 (of which 15 bits aren’t used anyway, more like 8 bytes + 1 bit...)