tristan zuberKaitlin McNeill
Published © GPL3+

The Light Saver

Tired of your bathroom light being left on? This IoT project turns your light on when motion is detected and back off when you are finished.

EasyFull instructions provided3 hours646
The Light Saver

Things used in this project

Hardware components

Photon
Particle Photon
×2
Servo (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Breadboard (generic)
Breadboard (generic)
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Servo Motor Circuit

Servo circuit febpxgst8u

PIR Motion Sensor Circuit

Pir circuit m4kednbcsi

Code

PIR Motion Sensor

C/C++
This code allows photon 1 to publish an event to the cloud when motion is detected.
int PIRSensor = D0;
int state=0;
void setup(){
pinMode(D7,OUTPUT);
pinMode(PIRSensor,INPUT);
}

void loop() {
    
  if (digitalRead(PIRSensor) == HIGH){
       digitalWrite(D7, (state) ? HIGH : LOW);
       Particle.publish("motion-detected","light");
       state = !state;
       delay(1000);
   }
   delay(10);
}

Servo Motor

C/C++
This code allows photon 2 to trigger the servo motor by subscribing to the event published by photon 1.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created


int pos = 75;    // variable to store the servo position
int led = D7;


void setup( ) {
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
  // attaches the servo on the D0 pin to the servo object
  myservo.attach(D0);

  // register the Spark function

  Particle.subscribe("motion-detected", monkey, "4b0050001451353432393433");
}

void monkey(const char *event, const char *data)
{
     digitalWrite(led,HIGH);
     if (strcmp(data, "light")==0)
     {
myservo.write(115);
delay(1800000);
myservo.write(75);
     }
}


void loop()
{
  
}

Credits

tristan zuber

tristan zuber

1 project • 2 followers
uncc
Contact
Kaitlin McNeill

Kaitlin McNeill

1 project • 2 followers
Contact

Comments

Add projectSign up / Login