Tim Tiernan
Published © GPL3+

Vertical Vinetian Blind Controller

Hoping to create a controller for the vertical blinds in my living room... and then the world!

IntermediateWork in progress52
Vertical Vinetian Blind Controller

Things used in this project

Hardware components

Photon
Particle Photon
×1
Mini Reed Switch KY-021
×2
9g Continuous Rotation Micro Servo
×2

Story

Read more

Code

Code to control blinds

C#
// ** NOTES
    // ** posStatus1 -> Reed switch for openServo -> HIGH=DISENGAGED, LOW=ENGAGED
    // ** posStatus2 -> Reed switch for twistServo -> HIGH=DISENGAGED, LOW=ENGAGED
    // ** openServo -> Operates string that moves blinds apart -> HIGH=CLOSED
    // ** twistServo -> Operates beaded cord that turns blinds -> HIGH=FLUSH
    // ** 
    // ** 
    
    #define OPEN_TIME 175
    #define TWIST_TIME 200
    
    int servoPin1 = D0; // ToggleOpen servo
    Servo openServo;
    
    
    int servoPin2 = D1; // ToggleTwist servo
    Servo twistServo;
    
    
    int posDetector1 = D2; // ToggleOpen switch input
    int posDetector2 = D3; // ToggleTwist switch input
    
    
    int servoPos = 0; // Reset servo position
    int posStatus1 = 0; // Position status variable ToggleOpen
    int posStatus2 = 0; // Position status variable ToggleTwist
    
    volatile bool doToggle = false;
    volatile bool doTwist = false;
    
    void setup() {
    
        openServo.write(90);
        twistServo.write(90);
     
        openServo.attach( servoPin1 ); // Attach Toggle servo to D0
        Particle.function("toggleOpen", toggleOpen);
    
    
        twistServo.attach( servoPin2 ); // Attach Twist servo to D1
        Particle.function("toggleTwist", toggleTwist);
    
    
        pinMode(posDetector1, INPUT_PULLDOWN); // Check status of ToggleOpen switch
        pinMode(posDetector2, INPUT_PULLDOWN); // Check status of ToggleTwist switch
    
    
        Particle.variable("posStatus1", &posStatus1, INT); // Declare status variable to check ToggleOpen position status
        Particle.variable("posStatus2", &posStatus2, INT); // Declare status variable to check ToggleTwist position status
    
    
    }
     
    
    
    //  ToggleOpen blinds open/closed
    
void loop () {
        
        
        if (doToggle == true) {
        
            posStatus1 = digitalRead(posDetector1); // Status of ToggleOpen switch
            posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
    
     
                    if (posStatus1 == LOW && posStatus2 == LOW) { // A If OPEN and NOT FLUSH to window then this closes and aligns them
                        openServo.write( 80 ); // B
                        delay(OPEN_TIME);  // C
                        openServo.write( 90 );// D Pulls curtains together
                        delay( 500 ); // E Half second pause
                        twistServo.write( 80 ); // F 
                        delay(TWIST_TIME); // G
                        twistServo.write( 90 ); // H Twists to close flush to window
                    }
            
                    else if (posStatus1 == LOW && posStatus2 == HIGH) {// J I If OPEN and FLUSH to window then this closes them
                        openServo.write( 80 ); // K
                        delay(OPEN_TIME); // L
                        openServo.write( 90 ); // M Pulls curtains together
                    }
            
            
                    else if  (posStatus1 == HIGH && posStatus2 == LOW) {// N If CLOSED and NOT FLUSH to the window, this opens them
                        openServo.write( 100 ); // O
                        delay(OPEN_TIME); // P
                        openServo.write( 90 ); // Q Pulls curtains apart
                    }
    
    
                    else if  (posStatus1 == HIGH && posStatus2 == HIGH) {// R If CLOSED and FLUSH to the window, this opens and aligns them
                        twistServo.write( 100 ); // S
                        delay(TWIST_TIME); // T
                        twistServo.write( 90 ); // U Twists to close flush to window
                        delay( 500 ); // V Half second pause
                        openServo.write( 100 ); //W
                        delay(OPEN_TIME); // X
                        openServo.write( 90 );// Y Pulls curtains together
                    }
				
				doToggle = false;
				
                    }
    
    
        

    
        if (doTwist == true) {
        
        
            posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
     
     
					if (posStatus2 == LOW) {// If FLUSH TO WINDOW
						twistServo.write( 100 ); 
						delay(TWIST_TIME); 
						twistServo.write( 90 );
					}
     
            
					else {
						twistServo.write( 80 );
						delay(TWIST_TIME);
						twistServo.write( 90 );
					}   
			
			doTwist = false;
        
		}  
    
}
    
int toggleOpen(String command) {
    doToggle = true;
}
    
    
int toggleTwist(String command) {
    doTwist = true;
}

Credits

Tim Tiernan

Tim Tiernan

2 projects • 3 followers

Comments