Smart Bed Underglow

Made by Xitong Deng

Found in DIoT 2018 1- Home Hack

Make night trips to the bathroom easier

0

Intention

My grandma is one of those who have to frequent the bathroom by night. It can be dangerous for her to grope for the room light switch in the darkness, with a certain distance from the bed. Moreover, pet owners need to watch out for their cats and dogs when they step out of bed at night, and people don't want to wake their partners up. Therefore, I would like to make a smart bed light installed under the bed frame. It is motion activated at night to provide visibility. To save energy, people can turn off the switch when the room is bright enough.

0

Part

- Particle Photon x 1
- PIR motion sensor x 1
- 10 kOhm resistor x 3
- LED GRB strip x 1
- LED x 1 (for testing)
- Breadboard x 1
- Jumper Wires
- Slide switch x 1

0

Process

1. Test the motion sensor with LED light

Firstly, I built the test circuit connecting the LED light and the PIR motion sensor. As soon as I approached the motion sensor, the LED lit up. And then when I walked away, the LED light went out after about 15 seconds. Therefore, I knew that the motion sensor was working well. I consider a time delay of 15 seconds acceptable because the sensor might need some time to figure out whether there are still motion changes taking place.
0
the circuit work from GitHub
01
0
The LED light showed that the motion sensor was working
001
0
/*
 * Project homehack
 * Title: Smart Bed Underglow
 * Author:Xitong Deng
 * Date: 01/28/2018
 */

int inputPin = A0;          //choose the input pin (for PIR sensor) [analog pin]
int ledPin = D1;            //LED Pin
int pirState = LOW;         //assume no motion detected when we start
int val = 0;                //variable for reading the pin status.

void setup() {
  Serial.begin(9600);
  Serial.print("On");
  pinMode(ledPin, OUTPUT);  //declare LED light as output
  pinMode(inputPin, INPUT); //declare sensor as input
}

void loop() {
    //make sure the loop is working
    Serial.print("Calibrated");
    //get the data from the sensor
    readTheSensor();
    //report it out, if the state has changed
    reportTheData();

}

void readTheSensor(){
  val = analogRead(inputPin);
  Serial.println(val);
  delay(500); //I can try to delete it!
}

void reportTheData(){
    //--> when the sensor tells that motion is there
    if (val > 1000){
      if (pirState == LOW){
        Particle.publish("motion-detected"); //announce this change by publishing an event
        pirState = HIGH;
        setLED(pirState);
      }
    }
    else{
    //--> when the sensor tells that motion is no longer there
    //--> we need to turn the state into LOW and turn off the light
      if (pirState == HIGH){
        pirState = LOW;
        setLED(pirState);
      }
    }
}

void setLED (int state){ //turn on/off the led light according to state
  digitalWrite(ledPin, state);
}
Click to Expand
0

2. Replace the white LED with a RGB LED

I replaced the white LED light with a RGB LED because it looks nicer with the vivid color. 

0
Codes for the RGB LED
int redPin = D2;
int greenPin = D0;
int bluePin = D1;
 
void setup() {

  //declare LED RRB as output
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

}

void setLED (int state){ //turn on/off the led light according to state

  digitalWrite(redPin, state);
  delay(3000);  // wait for 500 milliseconds

  digitalWrite(greenPin, state);
  delay(3000);  // wait for 500 milliseconds

  digitalWrite(bluePin, state);
  delay(3000);  // wait for 500 milliseconds

}
Click to Expand
0

3. Add the slide switch

Finally, I added a slide switch to the circuit so that people can turn off this motion activated light when the room is bright enough. 

The slide switch is designed to control inputs of the motion sensor. If the switch slides to the left, the photon can receive the input from the motion sensor so the RBG LED will light up when motion is detected. If the switch slides to the right, the motion sensor is disconnected to the photon, and therefore the RBG LED won't be activated by motion in this case.

0

Reflection

If I have more time to improve my design, I would like to add a photo resistor to provide extra inputs. If enough light is detected (which means the room is bright), the photon will automatically disconnect the motion sensor, and therefore manual control of the  switch will be no longer needed. Moreover, another improvement can be connecting the breadboard with a 12V, 60W power supply, so that this under-bed light can be installed without a computer to provide power right next to it.

0
Final sketch
/*
 * Project homehack
 * Title: Smart Bed Underglow
 * Author:Xitong Deng
 * Date: 01/28/2018
 */

int inputPin = A0;          //choose the input pin (for PIR sensor) [analog pin]

int redPin = D2;
int greenPin = D0;
int bluePin = D1;

int pirState = LOW;         //assume no motion detected when we start
int val = 0;                //variable for reading the pin status.

void setup() {
  Serial.begin(9600); //open serial connection for debugging
  Serial.println("On");

  //declare LED RRB as output
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  //declare sensor as input
  pinMode(inputPin, INPUT);
}

void loop() {
    //make sure the loop is working
    Serial.print("Calibrated");
    //get the data from the sensor
    readTheSensor();
    //report it out, if the state has changed
    reportTheData();
}

void readTheSensor(){
  val = analogRead(inputPin);
  Serial.println(val);
  delay(1000);
}

void reportTheData(){
    //--> when the sensor tells that motion is there
    if (val > 2000){
      if (pirState == LOW){
        Particle.publish("motion-detected"); //announce this change by publishing an event
        pirState = HIGH;
        setLED(pirState);
      }
    }
    else{
    //--> when the sensor tells that motion is no longer there
    //--> we need to turn the state into LOW and turn off the light
      if (pirState == HIGH){
        pirState = LOW;
        setLED(pirState);
      }
    }
}

void setLED (int state){ //turn on/off the led light according to state
  // digitalWrite(ledPin, state);

  digitalWrite(redPin, state);
  delay(3000);  // wait for 500 milliseconds

  digitalWrite(greenPin, state);
  delay(3000);  // wait for 500 milliseconds

  digitalWrite(bluePin, state);
  delay(3000);  // wait for 500 milliseconds

}
Click to Expand
x
Share this Project

Courses

49713 Designing for the Internet of Things

· 25 members

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


About

Make night trips to the bathroom easier

Created

January 25th, 2018