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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.