49713 Designing for the Internet of Things
· 25 members
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Is my cat inside or outside? This connected device will allow my family to feel confident that our indoor/outdoor cat is inside before they close the backyard door.
My hack will use a switch to turn on the device, a motion detector to detect the cats movement, and an LED to indicate that motion has been detected. My parents will be able to then access the information online to see either "The cat is inside now" or "The cat is outside now" This will let them know if they are able to lock the back door, or if they need to go outside and bring the cat in. This will solve the problem of needing to look inside and outside for the cat, which is time consuming and frustrating
The Initial Design incorporated the PIR Motion Sensor, the LED, and the resistor. The goal of the initial design was to notify the user that motion was detected by enabling the LED. I found that the user (my parents) did not want to constantly have the LED blinking on and off. The backdoor isn't always opened, so there needed to be a switch to turn off the device when not in use. I addressed this challenge by deciding to incorporate a sliding switch into my Final Design.
In order to prevent the motion sensor from perpetually taking readings, I incorporated an on/off sliding switch pictured below. This would allow the user to control when the device was recording motion and illuminating the LED. The switch would be in the "off" position at night, and when the back door was closed. When the door was opened up, and the cat was allowed to go outside, the switch would be turned to the "on" position and the motion sensor would start taking readings and pushing information to the cloud. This solution met the needs of my parents.
int inputPin = D4; // 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 switchPin = D2; // switch wired to D2
int calibrateTime = 10000; // calibrate
void setup()
{
pinMode( ledPin, OUTPUT );
pinMode( switchPin , INPUT_PULLUP ); // sets pin as input
pinMode(inputPin, INPUT_PULLDOWN ); // declare sensor as input
pinMode( ledPin , OUTPUT ); // sets pin as output
Serial.begin( 9600 ); // start the serial monitor
}
void loop()
{
int switchvalue = digitalRead(switchPin);
// if the sensor is calåbrated
if ( calibrated() )
{
// get the data from the sensor
readTheSensor();
}
if( calibrated() && switchvalue==HIGH ){
// report it out, if the state has changed
reportTheData();
}else {
digitalWrite ( ledPin, LOW);
}
Serial.print( "Switch Value is : " );
Serial.println( switchvalue );
Serial.print( "PIR value is : " );
Serial.println( val );
Serial.print( "PIR State is : " );
Serial.println( pirState );
delay( 100 );
}
void readTheSensor() {
val = digitalRead(inputPin);
}
bool calibrated() {
return (millis() > calibrateTime);
}
setLED( pirState );
}
void setLED( int state )
{
digitalWrite( ledPin, state );
}
Click to Expand
int inputPin = D4; // 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 switchPin = D2; // switch wired to D2
int calibrateTime = 10000; // calibrate
int cat_pos = 0;
void setup()
{
pinMode( ledPin, OUTPUT );
pinMode( switchPin , INPUT_PULLUP ); // sets pin as input
pinMode(inputPin, INPUT_PULLDOWN ); // declare sensor as input
pinMode( ledPin , OUTPUT ); // sets pin as output
Particle.publish("I sensed","Cat is inside first");
Serial.begin( 9600 ); // start the serial monitor
}
void loop()
{
// if the sensor is calåbrated
if ( calibrated() )
{
// get the data from the sensor
readTheSensor();
}
if( calibrated() ){
// report it out, if the state has changed
reportTheData();
}
Serial.print( "PIR value is : " );
Serial.println( val );
Serial.print( "PIR State is : " );
Serial.println( pirState );
Serial.println(millis());
if (val == HIGH){
cat_pos = cat_pos + 1;
}
if (cat_pos%2 == 1){
Particle.publish("I sensed","Cat is outside now");
delay(5000);
}
if (cat_pos%2 == 0){
Particle.publish("I sensed","Cat is inside now");
delay(5000);
}
delay( 500 );
}
void readTheSensor() {
val = digitalRead(inputPin);
}
bool calibrated() {
return (millis() > calibrateTime);
}
void reportTheData() {
Serial.println( "REPORT THE DATA" );
setLED( val );
}
void setLED( int state )
{
digitalWrite( ledPin, state );
}
Click to Expand
Developing the Cat Counter was a very informative process. I learned how to use a simple PIR motion sensor to accomplish a unique problem for my parents. This was very interesting to me because when I thought about the problem at first, I didn't realize that it would require so few components, yet be able to do something so powerful. I learned that their are so many unique applications for sensors, and that a simple motion sensor could solve so many problems and have such an interesting use case. If I were to do this again, I would think about different types of LEDs and utilizing color in a unique way, rather than just the white LED. I am happy about where I got with this project, because it solves a unique frustration my parents and is a unique idea that I have not seen elsewhere.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Is my cat inside or outside? This connected device will allow my family to feel confident that our indoor/outdoor cat is inside before they close the backyard door.
January 24th, 2018