Smart Mailbox

Made by Ethan Krokonko

Created: January 28th, 2015

0
GOAL

For busy individuals whose homes have mailboxes that aren’t visible from inside the house, it would be useful to know when mail is received so that he or she can optimize the process of stopping for it as well as be more aware of when outgoing mail is picked up. To achieve this, a platform consisting of a tilt sensor and force sensitive resistor (FSR) each connected to an LED indicator would be installed within a mailbox. As the mailbox door is opened, the tilt sensor located on the door’s interior would set off a red LED to indicate someone’s presence. The FSR would be located on the base of the interior and would be connected to a green LED with a minimum threshold to sense the presence of mail. The user would then know when he or she has received mail.


PROCESS

Components Used:

3 - 1K Resistor

1 - 10K Resistor

1 - LED, Red

1 - LED, Green

1 - Tilt Sensor

1 - Force Sensitive Resistor


CODE

0
// -----------------------------------
// Smart Mailbox
// -----------------------------------

// Name the pins
int boxLED = D0; // box indicator LED connected to D0
int inPin = D2; // tilt sensor connected to D2
int fsrPin = A0; // FSR connected to A0
int mailLED = D4; // mail indicator LED connected to D4
int TiltStatus = 0; // variable to store the tilt sensor status
char BoxStatus[128]; // char to describe box door status on cloud
int fsrReading = 0; // variable to store FSR reading
char fsrStatus[128]; // char to describe mail status on cloud
int mailLEDBrightness = 0; // variable to store mail LED brightness

void setup()
{
  // Configure the pins to be outputs
  pinMode(boxLED, OUTPUT); // sets D0 as output
  pinMode(inPin, INPUT); // sets D2 as input
  pinMode(mailLED, OUTPUT); // sets D4 as output

  strcpy(BoxStatus, "OFF"); // initialize char BoxStatus to "off"
  strcpy(fsrStatus, "OFF"); // initialize char fsrStatus to "off"

  // Create a cloud variable of type char
  // called 'BoxStatus' mapped to BoxStatus
 Spark.variable("BoxStatus", BoxStatus, STRING);

 // Create a cloud variable of type char
 // called 'MailStatus' mapped to fsrStatus
 Spark.variable("MailStatus", fsrStatus, STRING);
}

void loop()
{
  TiltStatus = digitalRead(inPin); // read the input pin D2
  // check to see if tilt sensor is tilted on
  // if it is, TiltStatus is HIGH
  if (TiltStatus == HIGH) {
    // turn boxLED on
    digitalWrite(boxLED, HIGH);
    // return "Open Sesame!" as cloud variable status
    strcpy(BoxStatus, "Open Sesame!");
  }
  else {
    // turn boxLED off
    digitalWrite(boxLED, LOW);
    // return "Sorry, We're Closed" as cloud variable status
    strcpy(BoxStatus, "Sorry, We're Closed");
  }
  // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  fsrReading = analogRead(fsrPin);
  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  mailLEDBrightness = map(fsrReading, 0, 4095, 0, 255);
  // create force threshold for presence of mail
  if (mailLEDBrightness >= 30) // 30 is arbitrary threshold # based on
                              // weight of mail
  {
    // turn mailLED on
    digitalWrite(mailLED, HIGH);
    // return "You've Got Mail" as cloud variable status
    strcpy(fsrStatus, "You've Got Mail");

  }
  else {
    // turn mailLED off
    digitalWrite(mailLED, LOW);
    // return "Nothing Here" as cloud variable status
    strcpy(fsrStatus, "Nothing here");
  }
  // wait 1/10th of a second and then loop
  delay(100);
}
Click to Expand
0
OUTCOME

The prototype as presented illustrates the proof-of-concept for a smart mailbox, with functional code and a breadboard-mounted circuit. To be tested in a real world scenario, some of the next steps to take would be to power the microcontroller with a battery and connect the Cloud information to smartphones so that the user could receive push notifications or SMS text message alerts notifying when they have received mail.


PHOTOS & VIDEO

0
http://youtu.be/t4JGNxyIaZU
0

REFLECTION

Without an extensive background in programming, there was an initial barrier to entry in understanding the syntax used for the Spark Core. Once I had a general understanding of the format for simple programs, it was easy to combine basic concepts into slightly more complex. Still, certain concepts that I thought would be easy, like outputting a string to the cloud variable rather than a numerical value, proved to be more difficult than initially anticipated, which exemplifies the underlying complexity of C++. Overall, I was satisfied with the successes I had with my project over the 1-week timeframe.

x