Eric AdkinsWill Slack
Published © GPL3+

Light Activated Blinds Opener/Closer

The device will cause blinds to open/close based on outside light levels, and graph when the blinds are opened/closed.

BeginnerFull instructions provided3 hours1,734
Light Activated Blinds Opener/Closer

Things used in this project

Hardware components

Photon
Particle Photon
×2
Zipties
×4
FITEC FS5103R Continuous Rotation Servo (with Circular Shaft Attachment)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Photo resistor
Photo resistor
×1
Male/Male Jumper Wires
×3
Anker Power Pack
×2
Velcro
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Sheetmetal Brackets (135 deg and 90 deg, see pics in story)
×2
Steel Paper Clip
×1

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Hand tools and fabrication machines

Wire Cutters

Story

Read more

Schematics

Sensor Photon

Servo Photon

Sensor Photon Schematic

Servo Photon Schematic

Code

Sensor Photon Code

C/C++
int power = A5; // This pin puts a voltage across the photoresistor so as the light intensity changes, the voltage across the photoresistor changes.

int photoresistor = A0; // Setting which pin reads the photoresistor

int threshold_condition = 100; // this is the threshold of the photoresistor reading that distinguishes bewtween dark and light. We accomplished this by using Tinker to analog read the A0 pin at different light levels.

int tempvalue = 0; // Setting an arbitrary initial value to compare to later in the code
 
int analogvalue=0; // Setting an arbitrary intial value to compare to later in the code

void setup() {

    
    pinMode(photoresistor,INPUT); // Setting the photoresistor pin (A0) as an          input
    
    pinMode(power,OUTPUT);// Setting the power pin (A5) as an output

    
    digitalWrite(power,HIGH);// Turning on the power (3.3V) of the A5 pin

   
    Particle.variable("analogvalue", &analogvalue, INT); // Sends every
    // photoresistor reading to the cloud to be stored. 
    
   Particle.subscribe("talkback", myHandler);// Subscribing to the "talkback" event sent by the Servo Photo, so that this Photon's D7 LED will light up everytime the servo runs. This allows for two-way communication between Photons.
   
}




void loop() {
    tempvalue = analogvalue; // Setting the inital condition for the toggling below
   
    analogvalue = analogRead(photoresistor); // Reading the output of the photoresistor pin

   if (analogRead(A0) >= threshold_condition & tempvalue < threshold_condition){
       Particle.publish("photoresistor", "light", 60, PUBLIC);
    // if the current photoresistor reading indicates that it is light, and the previous photoresistor reading indicated it was dark, then publish an event called "photoresistor" with the data "light" to tell the servo to open the blinds
    // The comparison between the current and previous photoresistor reading prevents this loop from publishing "light" at every iteration. Therefore, "light" will only be published when the ambient light intensity moves from dark to light.
    // We found it easiest to publish in this manner, it was more difficult to prevent the servo from running if this loop published "light" at every iteration.
   }
   
   if (analogRead(A0) < threshol_condition & tempvalue >= threshold_condition){
   Particle.publish("photoresistor", "dark", 60, PUBLIC);
    // if the current photoresistor reading indicates that it is dark, and the previous photoresistor reading indicated it was light, then publish an event called "photoresistor" with the data "dark" to tell the servo to close the blinds
    // The comparison between the current and previous photoresistor reading prevents this loop from publishing "dark" at every iteration. Therefore, "dark" will only be published when the ambient light intensity moves from light to dark.
    // We found it easiest to publish in this manner, it was more difficult to prevent the servo from running if this loop published "dark" at every iteration.
   
   
   }
  
    delay(5000); // Puts a 5 second delay between each loop to allow time for the servo to run completely


}




void myHandler(const char *event, const char *data){
 if (strcmp(data,"ON")==0) {
     digitalWrite(D7,HIGH);
     delay(5000);
     digitalWrite(D7,LOW);
     // This loop is subscribed to the servo photon's "talkback" string, which tells the D7 LED on this Photon to light up each time the servo is run. This allows for two-way communication between Photons.
     
 }
}

Servo Photon Code

C/C++
Servo myservo;

int pos = 0;
void setup() {
  
//This causes the servo photon to be subscribed to an event (photoresister) that the sensor photon published.
Particle.subscribe("photoresistor", myHandler);


}

//The code below actuates the servo in either the clockwise direction or the counter-clockwise direction to open/close the blinds.
void myHandler(const char *event, const char *data)
{

//If a "dark" data is recieved in the "photoresister" event, then this section of code will run.
 if (strcmp(data,"dark")==0) {
   
     //The pin that the motor is attached to is activated (in this case D0).
     myservo.attach(D0);
     
  //The write command sends a signal to the the pin that the motor is attached to(values beteen 90 and 180 result in clockwise rotation, with values closer to  180 being faster).
myservo.write(110);

// Here, the delay of 5000 milliseconds causses the motor to turn for 5 seconds.
delay(5000);

 //Then, the detach command causes power to stop being sent to the pin that the motor was previously attached to, casuing the motor to stop.
myservo.detach();

// Once this happens, an "ON" event is published to the cloud, and will be picked up by the sensor photon. This is to turn on the D7 LED of the sensor photon. This allows for two-way communication between Photons.
Particle.publish("talkback", "ON", 60, PUBLIC);
}



//If "light" data is recieved in the "photoresister" event, then this section of code will run.
else if (strcmp(data,"light")==0) {
  
  //The pin that the motor is attached to is activated (in this case D0).
myservo.attach(D0);

 //The write command sends a signal to the the pin that the motor is attached to(values beteen 0 and 90 result in counterclockwise rotation, with values closer to 0 being faster).
myservo.write(70);

// Here, the delay of 5000 milliseconds casuses the moter to turn for 5 seconds.
delay(5000);

 //Then, the detach command causes power to stop being sent to the pin that the motor was previously attached to, casuing the motor to stop.
myservo.detach();

// Once this happens, an "ON" event is published to the cloud, and will be picked  up by the sensor photon.  This is to turn on the D7 LED of the sensor photon. This allows for two-way communication between Photons.
Particle.publish("talkback", "ON", 60, PUBLIC);
}

//The only events being published by the sensor photon are "light" or "dark" so there aro no other possible cases.
else{}
}

Credits

Eric Adkins

Eric Adkins

1 project • 0 followers
Will Slack

Will Slack

1 project • 0 followers

Comments