Writing the Sketch

The sketch for this project borrows from ideas we encoded in two other projects. The sensor readings come from the Tweeting Bird Feeder, and the state machine for the open or closed status was copied from the Water Level Notifier. As such, here is the complete sketch.

CurtainAutomation/CurtainAutomation.pde
​ 
#include <AFMotor.h>
​ 
#define LIGHT_PIN 0
 
#define LIGHT_THRESHOLD 800
 
#define TEMP_PIN 5
 
#define TEMP_THRESHOLD 72
 
#define TEMP_VOLTAGE 5.0
 
#define ONBOARD_LED 13
 
​ 
int​ curtain_state = 1;
 
int​ light_status = 0;
 
double​ temp_status = 0;
 
 
boolean daylight = true;
 
boolean warm = false;
 
 
AF_Stepper motor(100, 2);
 
​ 
void​ setup() {
 
Serial.begin(9600);
 
Serial.println(​"Setting up ...

Get Programming Your Home now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.