Scott Phan
Published

Automatic Curtains

Automation of curtains that open and close depending on brightness outside.

BeginnerShowcase (no instructions)15 hours97
Automatic Curtains

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Limit Switch
×2
Relay Module (Generic)
×2
36W 40W 12-24V DC Permanent Magnet Motor
×1
PWM DC Motor Speed Controller 7-80V 30A
×1
3pin Optical Sensitive Resistance Light Detection Photosensitive Sensor Module
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Pulley Wheel
×1
Flange Shaft Coupling
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Circuit Schematic

Relay Module Schematic

LDR Module Schematic

Code

Software

Java
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
int leadR = 6; //pin that goes to the relay that goes to red lead on motor
int leadB = 5; //pin that goes to the relay that goes to black lead on motor
int lightSensor = A2;

int open;

int rLimit = A0; //right side limit switch
int lLimit = A1; //left side limit switch

int poten = A5;

void setup() {
    pinMode(leadR, OUTPUT);
    pinMode(leadB, OUTPUT);
    pinMode(lightSensor, INPUT);
    pinMode(rLimit, INPUT_PULLUP);
    pinMode(lLimit, INPUT_PULLUP);
    pinMode(poten, INPUT);
    
    open = isOpen();
}

void loop() {
    int potenVal = analogRead(poten);
    int brightness = analogRead(lightSensor);
    
    if(isOpen() == 1){
        if(brightness > potenVal){
            digitalWrite(leadR, LOW);
            digitalWrite(leadB, HIGH);
        }
        else{
            digitalWrite(leadR, HIGH);
            digitalWrite(leadB, LOW);
        }
    }
    
    if(isOpen() == 0){
        if(brightness < potenVal){
            digitalWrite(leadR, HIGH);
            digitalWrite(leadB, LOW);
        }
        else{
            digitalWrite(leadR, LOW);
            digitalWrite(leadB, HIGH);
        }
    }
}

int isOpen(){
    int valR = analogRead(rLimit);
    int valL = analogRead(lLimit);
    
    if(valL > 2000 && valR < 2000){
        return 1;
    }
    if(valL < 2000 && valR > 2000){
        return 0;
    }
    return 2;
}

Credits

Scott Phan
3 projects • 0 followers

Comments