49713 Designing for the Internet of Things
· 25 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
A motion sensor for home security system. Don't let roommates enter to your room when they shouldn’t.
This project includes a motion sensor for home security system, and detects when someone is your home/room when they shouldn’t be. When a movement is detected, the alert is displayed through a LED flashing as an indicator of a threat. It also has an ON/OFF button which enables the user to turn the motion detector on when they want to activate it when leaving their room or vice versa. It is a personalized device because it enables notifications to be sent only to the user in alert cases.
The project is designed for my best friend who is having problems with her house mate due to privacy issues. I've chosen this problem because I can empathize with my best friend since I also live with house mates. I think everybody deserves personal space, so I would like to make a house mate detector for her.
The goal is to build a room security system and detect when someone is your room when they shouldn’t be. When a movement is detected, the alert is displayed through a LED flashing as an indicator of a threat and a notification is sent to the user. This way the process of realizing if someone has entered your room is streamlined and invading one's room without permission is prevented to some extent.
Steps:
1. I wired up an LED as an indicator for a motion detection. The LED is used to show that the motion sensor is working.
2. I wired up a PIR sensor to detect any motion.
3. I wired up a simple push button and used that as an ON/OFF button for the motion detector device. When the button is pushed, the device is OFF meaning that even though there is motion, it does not give any indication to the user. When it is not pushed, the device is ON, meaning that LED flashes and a notification is sent to the user when a motion is detected.
4. I enabled the product to publish an event to Particle Cloud every time a motion is detected. I needed to ensure that when the device is OFF (Push button is pressed), it shouldn't publish any event to the cloud. It should only publish when the device is ON. (Push button is not pressed.)
5. I downloaded IFTTT app to send notification to the user's phone every time motion is detected. I connected IFTTT with Particle Dev and built the IFTTT scenario.
The PIR sensor I used was too sensitive, therefore it was difficult for me to test accurately and see if my code and circuit were working as I planned. I tried to reduce its sensitivity and reduce the field; however it was hard since I did not how much to reduce.
It was also challenging for me to embed the code for the push button into my initial code. The Particle Dev gave me several errors until I found out how to write an if statement for the push button to operate correctly.
The device works successfully. After completing my fully-working device, I learned that IR sensor is better in terms of sensitivity than PIR sensor. I also learned thinking very basic and simple is better when writing a code. Drawing a flow chart of the tasks I want to accomplish with my code has helped me a lot to modify my code. Finally, I learned being patient and keeping myself motivated during coding! Public sources for codes has helped me a lot to build my code.
Next steps:
1) Try with a IR sensor.
2) Try alternative ways to make the sensor less reactive to external factors, such as running the sensor through a tube (cardboard or PVC) to reduce the sensor to a narrowor beam of detection.
3) Add buzzer to put the house mate invading your personal space in panic.
This was my first IOT project and I enjoyed it a lot! First, I thought it would be easier to create a connected device; however I think internet resources and collaboration makes it easier to build connected devices. Also, the project was very open-ended, so I could build it around a fun use case and make it personalized.
One of my goals was to learn the fundamentals of code writing. However, I still feel like I need to spend more time to understand the basic structures behind coding. I need to work more on my coding skills in order to build codes truly on my own. However, I feel I have progressed to a great extent.
Overall, I feel very happy about my project. I realized that with few wires and a small breadboard, many tasks and useful and fun scenarios can be accomplished.
I am planning to integrate IOT more into my life and make my day-to-day life easier through pulling data from cloud and exposing them to my routine in certain situations. I'll brainstorm on creative use cases!
int inputPin = D0; // choose the input pin (for PIR sensor)
int ledPin = D1; // LED Pin
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int buttonPin = D4; //added later on for push button
int calibrateTime = 10000; // wait for the thingy to calibrate
void setup()
{
pinMode( ledPin, OUTPUT );
pinMode(inputPin, INPUT); // declare sensor as input
pinMode( buttonPin , INPUT_PULLUP); // sets pin as input (added later on for push button)
}
void loop()
{
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// if the sensor is calibrated
} else //( calibrated() )
{
// get the data from the sensor
readTheSensor();
// report it out, if the state has changed
reportTheData();
}
}
void readTheSensor() {
val = digitalRead(inputPin);
}
bool calibrated() {
return millis() - calibrateTime > 0;
}
void reportTheData() {
// if the sensor reads high
// or there is now motion
if (val == HIGH) {
// the current state is no motion
// i.e. it's just changed
// announce this change by publishing an eent
if (pirState == LOW) {
// we have just turned on
Particle.publish("motionDetected");
// Update the current state
pirState = HIGH;
setLED( pirState );
}
} else {
if (pirState == HIGH) {
// we have just turned of
// Update the current state
pirState = LOW;
setLED( pirState );
}
}
}
void setLED( int state )
{
digitalWrite( ledPin, state );
}
Click to Expand
A hands-on introductory course exploring the Internet of Things and connected product experiences.
A motion sensor for home security system. Don't let roommates enter to your room when they shouldn’t.
January 25th, 2018