I have trouble waking up in the morning. The bed is so darn comfy, and it's nice and dark in the morning with my blackout curtains. I strove to take away one of those comforts with an automated curtain system! When my alarm sounds, the curtain opens, letting in the sun and kickstarting my day!
Code and Communication:
My alarm clock app, Sleep as Android, has the ability to interface with IFTTT. This is an awesome system that takes care of API calls for you and talks to hundreds of different services.
Sleep as Android >>> Adafruit IO
When the alarm goes off, Sleep as Android sends "alarm_alert_start" to a Maker channel feed. Using the Sleep as Android documentation, I created an IFTTT recipe that looks for this message, and writes a "1" to an Adafruit IO feed. When the alarm is disabled, "alarm_alert_dismiss" is sent, and a "0" is written to the data feed.
Adafruit IO >>> ESP8266
On the hardware side, I have an ESP8266 checking the Adafruit IO feed. I followed the basics of the Adafruit guide to get set up. When the feed returns a "1" the alarm is sounding, and the ESP8266 then lets the Arduino know it's time to open the curtain.
ESP8266 >>> Arduino
The connection between the ESP8266 and Arduino is very basic, just an on/off digital signal. When it's time to open the curtain, the ESP8266 writes a HIGH value on the digital line connecting the two microcontrollers.
When the digital input is HIGH, the Arduino operates the servo to open the curtain, pauses, and then retracts the cord so that the curtain can be closed in the evening. The Arduino also has two buttons attached to it that allow the servo to be manually moved in either direction. These buttons also interrupt the automated open/close operation in case anything unexpected occurs.
The Arduino code also has a timeout (2 hours for now) during which no other alarm events will trigger the curtain opening. This avoids snoozing triggering the curtain multiple times in one morning.
The ESP8266 and Arduino code can be found on the repository.
Thanks to ydonnelly for the ESP8266 Fritzing part!
(The Fritzing design file for this breadboard layout can be found on the repository)
The servo is mounted on the curtain rod, and has an old plastic wheel as a spool. As the servo turns, the spool reels in the string. The string is attached to the end of the curtain, so as it is pulled onto the spool, the curtain is dragged open.
The string has a bunch of washers along it such that there is tension when it unspools. The software will automatically unspool the string a few seconds after the curtain is dragged in so that the curtain can be later closed.
- Motorize the second curtain
- Solder up a PCB once all the bugs are worked out
- Mount the buttons on the wall for easy control
- Make the alarm on/off data transmission more robust
- Add feedback to servo rotation for more precise movement
Automated Curtains Jeremy Wilson is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.