Natalie Jiang
Published

Lane Tech HS - PCL - Automatic Light

Turns on the light to wake you up at a certain time.

BeginnerFull instructions provided105
Lane Tech HS - PCL - Automatic Light

Things used in this project

Hardware components

Argon
Particle Argon
×1
Servo Module (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Google Home
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2

Software apps and online services

Maker service
IFTTT Maker service
Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Tape, Duct
Tape, Duct

Story

Read more

Schematics

Wiring

Code

Code

C/C++
Servo myServo; 

int on_button = 3;
int off_button = 4;

void setup()
{
    myServo.attach(2);
    myServo.write(100);
    Particle.subscribe("lights_on",light_on);
    Particle.subscribe("lights_off",light_off);
    Particle.subscribe("morning",morning);
    Particle.subscribe("night",night);
    pinMode(on_button, INPUT_PULLUP);
    pinMode(off_button, INPUT_PULLUP);
}

void loop(){
	
	int on_btnState = digitalRead(on_button);   // allows a eaiser way to turn on the light
	if ( on_btnState == LOW )
	{
	    myServo.write(130);              
        delay(500);
	}
	else
		myServo.write(100);
		
	int off_btnState = digitalRead(off_button); // allows a eaiser way to turn off the light
	if ( off_btnState == LOW )
	{
	    myServo.write(60);              
        delay(500);
	}
	else  
		myServo.write(100);
}

void morning(const char *event,const char *data)  //turns on at a certian time in the morning 
    
    {
        myServo.write(130);              
        delay(500);
        myServo.write(100); 
    }

void night(const char *event,const char *data)  //turns off at a certian time at night 
    
    {
        myServo.write(60);             
        delay(500);
        myServo.write(100);
    }

void light_on(const char *event,const char *data) // turns on the light with a voice command to google home

    {                                   
        myServo.write(130);              
        delay(500);
        myServo.write(100);
    }
    
void light_off(const char *event,const char *data)  // turns off the light with a voice command to google home
    
    {                                   
        myServo.write(60);             
        delay(500);
        myServo.write(100);
    }
    

Time

C/C++
If you would like the argon to turn on and off your light everyday at the same time, replace the ifttt time part from the original code with this.
Servo myServo; 

int D_Min = 00;
int D_Hour = 7;
int N_M = 30;
int N_H = 21;

void setup()
{
    myServo.attach(2);
    myServo.write(100);
    Time.zone(-6);
    Particle.syncTime();
    Particle.subscribe("lights_on",light_on);
    Particle.subscribe("lights_off",light_off);
  
}

void loop()
{
	
	if(Time.hour()== D_Hour && Time.minute()== D_Min)
	  {                                   
        myServo.write(130);              
        delay(500);
        myServo.write(100);
    }
    
	if(Time.hour()== N_H && Time.minute()== N_M)
	  {                                   
        myServo.write(130);              
        delay(500);
        myServo.write(100);
    }
}


void light_on(const char *event,const char *data) // turns on the light with a voice command to google home

    {                                   
        myServo.write(130);              
        delay(500);
        myServo.write(100);
    }
    
void light_off(const char *event,const char *data)  // turns off the light with a voice command to google home
    
    {                                   
        myServo.write(60);             
        delay(500);
        myServo.write(100);
    }
 

Credits

Natalie Jiang

Natalie Jiang

1 project • 0 followers

Comments

Add projectSign up / Login