Josh Parsio
Published

Lane Tech HS - PCL - Automatic "Sun” Lights

Lights that turn on automatically and gradually to simulate the sun rising so that waking up on early mornings is easier.

BeginnerFull instructions provided83
Lane Tech HS - PCL - Automatic "Sun” Lights

Things used in this project

Hardware components

Argon
Particle Argon
×2
Darlington High Power Transistor
Darlington High Power Transistor
×3
Through Hole Resistor, 680 ohm
Through Hole Resistor, 680 ohm
×3
Hall Effect Sensor
Hall Effect Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
magnet
×1
5.5mm x 2.1mm Female Male DC Power Plug Adapter
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Wiring for one transistor

Duplicate 3 times for all 3 colors

Wiring for transistor with power

Connect green and orange wires as well as the other wires you get when you duplicate the previous wiring, with the LED strip

Code

Led Argon

C/C++
This code is what is running on the argon that controls the lights
int red = A2;
int green = A3;
int blue = A1;
int color[3] = {255, 255, 255};

int thirtySeconds = 0;
int i = 0;
bool start = false;
bool active = false;
int hour = 5;
int minute = 45;

int hallSensor = D7;

int chooseColor(String cmd);
int chooseTime(String cmd);
int on(String cmd);
int off(String cmd);
int doorOpen(String cmd);

void setup() {
    pinMode(red, OUTPUT);
    pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
    
    Particle.function("chooseColor", chooseColor);
    Particle.function("chooseTime", chooseTime);
    Particle.function("on", on);
    Particle.function("off", off);
    Particle.function("doorOpen", doorOpen);
    
    Time.zone(-6);
}

void loop() {
    int now = Time.now();
    
    if (Time.hour() == hour && Time.minute() == minute && !start){
        start = true;
        thirtySeconds = now + 30;
    }
    if (start){
        if (now == thirtySeconds){
            i++;
            thirtySeconds += 30;
            analogWrite(red, i/30 * color[0]);
            analogWrite(green, i/30 * color[1]);
            analogWrite(blue, i/30 * color[2]);
            if (i == 30){
                active = true;
            }
        }
        if (Time.minute() == 30){
            start = false;
        }
    }
}

int chooseColor(String cmd){
    if (!(sscanf(cmd, "%d,%d,%d", &color[0], &color[1], &color[2]) == 3)){
        color[0] = 255;
        color[1] = 255;
        color[2] = 255;
        return 0;
    }
    if (active){
        on("");
    }
    return 1;
}

int chooseTime(String cmd){
    if (!sscanf(cmd, "%d:%d", &hour, &minute) == 2){
        hour = 5;
        minute = 45;
        return -1;
    }
    return 0;
}

int on(String cmd){
    start = false; 
    
    if (!(cmd == "")){
        sscanf(cmd, "%d,%d,%d", &color[0], &color[1], &color[2]);
    }
    
    analogWrite(red, color[0]);
    analogWrite(green, color[1]);
    analogWrite(blue, color[2]);
    active = true;
    return 1;
}

int off(String cmd){
    analogWrite(red, 0);
    analogWrite(green, 0);
    analogWrite(blue, 0);
    active = false;
    return 1;
}

int doorOpen(String cmd){
    if(!active){
        analogWrite(red, color[0]);
        analogWrite(green, color[1]);
        analogWrite(blue, color[2]);
    }
    if(active){
        delay(2000);
        
        analogWrite(red, 0);
        analogWrite(green, 0);
        analogWrite(blue, 0);
    }
    active = !active;
    return 1;
}

Hall Sensor Argon

C/C++
This is the code running on the argon by the door
int hall = 7;
int led = 6;

bool state = false;
int pastState = LOW;


void setup() {
    pinMode(hall, INPUT);
    pinMode(led, OUTPUT);
}

void loop() {
    int hallS = digitalRead(hall);

    //magnet close to sensor
    if (hallS == HIGH && pastState != HIGH){
        Particle.publish("doorClose");
    }
    
    //magnet pulled away
    if (hallS == LOW && pastState != LOW){
        Particle.publish("doorOpen");
    }
    
    pastState = digitalRead(hall);
    delay(100);

}

Credits

Josh Parsio
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.