Roberto Jacobo
Published © GPL3+

Lane Tech HS - PCL - IoT Smart Blinds

Adjust your blinds from the comfort of your seat without having to go through the effort of standing up.

BeginnerFull instructions provided2 hours3,431

Things used in this project

Hardware components

Photon
Particle Photon
×1
Photo resistor
Photo resistor
×1
RobotGeek Continuous Rotation Servo
RobotGeek Continuous Rotation Servo
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Blynk
Blynk

Story

Read more

Schematics

Schematics

Code

blinds.ino

C/C++
#define BLYNK_PRINT Serial

#include <blynk.h>

char auth[] = "YourAuthKey";

Servo motor;
int potPin = A0;
int potReading = 0;
int motorPin = 0;
int photoVal = 0;
int LEDPin = D3;
bool hasRun = false;
bool photoMode = false; //Control solely with photocell

void setup()
{
    motor.attach(D0);
    Serial.begin(9600);
    delay(5000);
    Blynk.begin(auth);
}

BLYNK_WRITE(V0) {
    if (param.asInt() == 1) { // CLOSE FULLY
        motor.write(0);
        delay(1200);
        motor.write(92);
    }
}
BLYNK_WRITE(V1) {
   if (param.asInt() == 1) { // OPEN FULLY
        motor.write(180);
        delay(1200);
        motor.write(92);
    }
}
BLYNK_WRITE(V2){ // CLOSE A LITTLE
    if(param.asInt() == 1){
        motor.write(0);
        delay(300);
        motor.write(92);
    }
}
BLYNK_WRITE(V3){ // OPEN A LITTLE
    if(param.asInt() ==1){
        motor.write(180);
        delay(300);
        motor.write(92);

    }
}
BLYNK_WRITE(V4){ // TOGGLE PHOTOCELL MODE
    if(param.asInt() ==1){
        photoMode = true;
    }
    else
        photoMode = false;
}
void loop() {
    Blynk.run();
    
    potReading = analogRead(potPin) - 1023;

    if(photoMode){
        if(potReading<0){
            if(hasRun==false){
                Particle.publish("**OPENING**");
                motor.write(180);
                delay(1200);
                motor.write(90);
                hasRun = true;
            } 
            else{
                if(checkChange(potPin)){ 
                    hasRun == false;
                    Particle.publish("**CHANGED; CLOSING**");            
                }
            }
            Particle.publish("**STAYING OPEN**"); 
        }
        else{
            if(hasRun==false){
                Particle.publish("**CLOSING**");
                motor.write(0);
                delay(1200);
                motor.write(90);
                hasRun = true;
            }
            else{
                if(checkChange(potPin)){
                    hasRun == false;
                    Particle.publish("**CHANGED; OPENING**");
                }
            }
            Particle.publish("**STAYING CLOSED**");
        }
    }
    Particle.publish("Photoresistor value",String(potReading));
}

boolean checkChange(int pin){ // Test to see if there's a notable difference
    int init = analogRead(potPin);
    delay(1000);
    int final = analogRead(potPin);
    
    int difference = abs(init-final);
    if(difference > 300){
        return true;
    }
    else{
        return  false;
  }
}

Credits

Roberto Jacobo

Roberto Jacobo

2 projects • 7 followers
Junior at Lane Tech

Comments

Add projectSign up / Login