Drop me a line
Made by K P ·
Made by K P ·
Use this IoT to remove the guesswork and anticipation for when your mail arrives by getting pushed notifications sent to your smartphone.
Created: January 29th, 2016
A common and frequent homeowner problem is anticipating when mail will arrive. Taking inspiration from complaints about having to check mail unnecessarily, I realized there was an opportunity to create a solution that removes the guesswork if and when mail has been delivered. Mailmen arrive at different times everyday, creating confusion and additional effort for recipients to check for their mail. This solution provides a way for mail recipients to save the time spent checking their mailbox repetitively or unnecessarily before the mailman arrives.
//Want to set a variable for photoCell and set it to map to A0
int photoCellPin = A0;
//Create a varibale to store readings from the photoCell
int photoCellReading = 0;
//Set a varible for LED that maps to D0
int ledPin = D0;
//threshold of being covered
int threshold = 3000;
//Create a varible that will track and store brightness of the LED
int ledBrightness = 0;
//Define LED on pin D1
int ledPIR = D1;
//Define the PIR sensor on D7;
int PIR = D7;
//store PIR readings
int PIRReading = 0;
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int calibrateTime = 1000; // wait for calibration
//track publishing process
bool published;
long publishTimeout = 60000;
long lastPublishTime = -60000;
void setup ()
{
//Configure D0 pin as output
pinMode (ledPin, OUTPUT);
//create a cloud variable interger called light that is mapped to the photoCellReading
Particle.variable("light", &photoCellReading, INT);
Serial.begin(9600);
// set ledPIR pin to output
pinMode(ledPIR, OUTPUT);
//set ledPIR pin to input
pinMode(PIR, INPUT);
//ledPIR is on
digitalWrite(ledPIR, HIGH);
//ledPir is off
digitalWrite(ledPIR, LOW);
// set the timezone to EST!!!
Time.zone( -5 );
Serial.begin( 9600) ;
}
void loop ()
{
//Use the analogRead to provide photoCellReading
photoCellReading = analogRead(photoCellPin);
if(photoCellReading < threshold){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
Serial.print("Analog reading = ");
Serial.println(photoCellReading);
//Make LED brighter, the darker the sensor is
photoCellReading = 4095 - photoCellReading;
//ledBrightness = map( photoCellReading, 0, 4095, 0 , 255 );
//fade LED to desired brightness
//analogWrite(ledPin, ledBrightness);
//wait for x seconds and then loop
//delay(100);
//motion detection, then turn LED on as an indicator
// if the sensor is calibrated
if ( calibrated() )
{
Serial.println( "calibrated and reading" ) ;
// get the data from the sensor
readTheSensor();
// report it out, if the state has changed
reportTheData();
}
//wait for 5 seconds delay before reading again
delay(500);
}
void readTheSensor() {
val = digitalRead(PIR);
}
bool calibrated() {
return millis() - calibrateTime > 0;
}
void reportTheData() {
// if the sensor reads high
// or there is now motion
if (val == HIGH) {
Serial.println( "there's motion" ) ;
// the current state is no motion
// i.e. it's just changed
// announce this change by publishing an eent
if (pirState == LOW) {
Serial.println( "changed" ) ;
// we have just turned on
// Update the current state
pirState = HIGH;
if (Time.hour()>=6 && Time.hour()<=18 && (lastPublishTime + publishTimeout) < millis() ){
Serial.println( "announcing" ) ;
Particle.publish("kpanchma/s16/motion", "You've Got Mail");
lastPublishTime = millis();
}
}
} else {
if (pirState == HIGH) {
Serial.println( "used to be high" ) ;
// we have just turned of
// Update the current state
pirState = LOW;
}
}
digitalWrite( ledPIR , pirState );
}
Click to Expand
References to help build this IoT Device:
1. http://daraghbyrne.github.io/diotlabs/3-working-with-sensors/photoresistors/
3. https://learn.adafruit.com/photocells/using-a-photocell
4. https://docs.particle.io/reference/firmware/photon/#zone-
5. http://daraghbyrne.github.io/diotlabs/7-communicating-events/pir/
This project is only accessible by signed in users. Be considerate and think twice before sharing.
This course charts the emergence of the now "connected world" to explore the possibilities for future products and connected spaces.
Use this IoT to remove the guesswork and anticipation for when your mail arrives by getting pushed notifications sent to your smartphone.