Lights Off

Made by Dani Quan

Everyone forgets to turn off lights in their house sometimes. This device will turn off your lights when you forget to but will still let you use your light switch normally!

Created: January 25th, 2018

0

Problem Statement

My sister constantly complains about her electricity bills because she lives alone, and if she forgets to turn her lights off, then they are wasting energy all day while she is at work. I thought it would be interesting to come up with an IOT device for her because she doesn't have any IOT appliances already in her house. I thought coming up with a solution that isn’t obtrusive and doesn’t require other IOT infrastructure would be an interesting design problem.

0

Goal

This device will be able to attach onto existing light switches and turn off the lights if there is no motion is detected in a room after a set amount of time. I wanted the device to not hinder regular use of the light switch, so it only is able to flick the light switch off. 

0

Process

For this project I started by individually testing the servo motor and the PIR sensor by starting with code from the DIoT Labs and Guides. From there, I modified the code to work for the range of servo motion I needed, which was limited. For the PIR sensor, I set up the code to publish an event when motion is detected, but also to keep track of when there are long periods of no motion. Lastly I wired an LED to blink 3 times after the long no motion period as a warning. The servo then is activated and rotates to hit the light switch.

0

Outcome

While the finished project is a functional prototype, it is still incomplete. The appliance is missing all mounting hardware, which could easily be made by laser cutting or 3D printing a mount that uses existing screw holes from a light switch. The servo lacks the torque to directly flip the light switch, which might be solved by mounting the servo, but could alternately be solved by attaching a larger lever arm to the servo horn. Additionally, additional sensors such as a photoresistor could be added so that the PIR sensor doesn't have to look for motion when the lights are already off.

Parts

  • Photon
  • PIR Motion Sensor
  • LED
  • 1000 ohm resistor
  • Servo Motor
  • Jumper Wires
0
int servoPin = D3;
int motionPin = D6;
int ledPin = D0;

Servo servoSwitch;
int lowServo = 175;
int highServo = 5;


int checkTime = 200;
int blinkTime = 30;
int noMove = 1;
int lights = 1;
int count = 0;
int count2 = 0;

void setup() {
  servoSwitch.attach(servoPin);
  pinMode(motionPin,INPUT);
  pinMode(ledPin,OUTPUT);
  Particle.variable("count", count);
  Particle.variable("count2", count2);
  Particle.variable("noMove", noMove);
  servoSwitch.write(lowServo);
  blinkLED();
}

void loop() {
  noMove = 1;
  // If the lights are on, look for periods of no movement
  if (lights) {
    // Look for a long initial period of no movement
    count = 0;
    while (count <= checkTime){
      if (digitalRead(motionPin) == 1) {
        Particle.publish("motionDetect","HIGH");
        noMove = 0;
        break;
      }
      delay(100);
      count++;
    }

    // if long no movement period, blink the LED 3 times while checking
    // for movement
    if (noMove == 1){
      count2 = 0;
      while (count2 < 3) {
        noMove = blinkCheck();
        if (noMove == 0) {
          Particle.publish("motionDetect","HIGH");
          break;
        }
        count2++;
      }
    }
    // no movement has been detected, turn off lights
    if (noMove == 1) {
      servoControl();
      lights = 0;
    }

  } else {
    // The lights are on, if there is movement switch back to searching mode
    if (digitalRead(motionPin) == 1){
      Particle.publish("motionDetect","HIGH");
      blinkLED();
      lights = 1;
    }
  }
}

int blinkCheck() {
  int resultMove = 1;
  digitalWrite(ledPin,HIGH);
  int i = 0;
  while (i < blinkTime) {
    if (digitalRead(motionPin) == 1) {
      digitalWrite(ledPin,LOW);
      return 0;
    }
    delay(100);
    i++;
  }

  digitalWrite(ledPin,LOW);
  i = 0;
  while (i < blinkTime) {
    if (digitalRead(motionPin) == 1) {
      return 0;
    }
    delay(100);
    i++;
  }
  return 1;
}

void blinkLED() {
  digitalWrite(ledPin,HIGH);
  delay(200);
  digitalWrite(ledPin,LOW);
  delay(200);
}

void servoControl() {
  servoSwitch.write(highServo);
  delay(500);
  servoSwitch.write(lowServo);
}
Click to Expand
0
Light Switch Demo
AnomalyNerd - https://youtu.be/ymgeKI2Jsec
0

Reflection

This project helped familiarize myself with reading data and debugging code on the Particle. I had no prior experience with getting feedback for debugging, and I'm used to simply adding a bunch of print statements to my code. Through coding and testing my appliance, I got more experience publishing events and variables to monitor through the cloud. I also got to familiarize myself with electrical components like sensors and servos, which I have worked with before but not recently. I am a little disappointed that I ran out of time to properly mount the servo to see if it could switch the lights off.

x
Share this Project

Courses

49313 Designing for the Internet of Things (Undergrad)

· 22 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Everyone forgets to turn off lights in their house sometimes. This device will turn off your lights when you forget to but will still let you use your light switch normally!