Cameron KinneyTanner Sponhouse
Published

Mailbox 2.0

Real time notifications for when your precious packages and letters arrive.

AdvancedWork in progress4 hours8,864

Things used in this project

Hardware components

Photon
Particle Photon
×2
Photo resistor
Photo resistor
×1
OLED Expansion
Onion Corporation OLED Expansion
The one used in this project is from the Particle Maker kit, but this one is similar.
×1
Adafruit FSR Force Sensitve Resistor
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 22.1k ohm
Resistor 22.1k ohm
×1

Software apps and online services

Maker service
IFTTT Maker service

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Sensor Particle Schematic

Slightly more complicated than the Receiving Photon pin-out, but very doable for any skill level.

OLED and Receiving Particle

Very simply pin-out. Just match the marked pins on the Photon with the labeled pins from the LCD screen.

Code

Sensor Particle Code

Arduino
This code handles the photo resistor and force sensitive resistors and the publication of their events.
/*
 *                                     +-----+
 *                          +----------| USB |----------+
 *                          |          +-----+       *  |
 *                          | [ ] VIN           3V3 [*] |-----------
 *   ---------From 22k------| [*] GND           RST [ ] |           \
 *  /                       | [ ] TX           VBAT [ ] |            \
 *  |                       | [ ] RX  [S]   [R] GND [ ] |             |
 *  |                       | [ ] WKP            D7 [ ] |            FSR
 * 220 ohm Resistor         | [ ] DAC +-------+  D6 [ ] |             |
 *  |    -------------------| [*] A5  |   *   |  D5 [ ] |             |
 *  |   /                   | [ ] A4  |Photon |  D4 [ ] |             |
 *  |   Photo Reistor       | [ ] A3  |       |  D3 [ ] |            / \
 *  |   |                   | [ ] A2  +-------+  D2 [ ] |           /   \
 *  \    \    From FSR------| [*] A1             D1 [ ] |          /     \
 *   -----------------------| [*] A0             D0 [ ] |       To A1    To
 22k ohm Resistor
 *                          |                           |
 *                           \    []         [______]  /
 *                            \_______________________/
 *
 *
 */
 
//declaring which pins everything is plugged into.
int boardLed = D7; // This is the LED that is already on your device.
int photoresistor = A0; // This is where your photoresistor is plugged in. The other side goes to the "power" pin (below).
int power = A5; // This is the other end of your photoresistor. The other side is plugged into the "photoresistor" pin (above).
int fsrpin = A1; 
int ledpin = D0;

// The following values get set up when your device boots up and calibrates:
int intactValue; // This is the average value that the photoresistor reads when the beam is intact.
int brokenValue; // This is the average value that the photoresistor reads when the beam is broken.
int beamThreshold; // This is a value halfway between ledOnValue and ledOffValue, above which we will assume the led is on and below which we will assume it is off.
bool beamBroken = false;
bool pressureon = false; // This flag will be used to mark if we have a new status or now. We will use it in the loop.
int fsrreading;

// We start with the setup function.
void setup() {
  pinMode(boardLed,OUTPUT); // Our on-board LED is output as well
  pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
  pinMode(fsrpin,INPUT);
  pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)
  pinMode(ledpin,OUTPUT);

  digitalWrite(power,HIGH);// Next, write the power of the photoresistor to be the maximum possible, which is 4095 in analog.

  //Calibrate the Photoresistor
  digitalWrite(boardLed,HIGH);// First, the D7 LED will go on to tell you to put your hand in front of the beam.
  delay(2000);
  
  digitalWrite(boardLed,LOW);// Then, the D7 LED will go off
  delay(500);

  //Taking readings
  int on_1 = analogRead(photoresistor);
  delay(200);
  int on_2 = analogRead(photoresistor);
  delay(300);

  // Now flash to let us know that you've taken the readings
  digitalWrite(boardLed,HIGH);
  delay(100);
  digitalWrite(boardLed,LOW);
  delay(100);
  digitalWrite(boardLed,HIGH);
  delay(100);
  digitalWrite(boardLed,LOW);
  delay(100);

  // Now the D7 LED will go then off on to tell you to remove your hand
  digitalWrite(boardLed,HIGH);
  delay(2000);
  digitalWrite(boardLed,LOW);

  //take two more readings.
  int off_1 = analogRead(photoresistor);
  delay(200);
  int off_2 = analogRead(photoresistor);
  delay(1000);

  // Now flash the D7 LED on and off three times to let us know that we're ready to go!
  digitalWrite(boardLed,HIGH);
  delay(100);
  digitalWrite(boardLed,LOW);
  delay(100);
  digitalWrite(boardLed,HIGH);
  delay(100);
  digitalWrite(boardLed,LOW);
  delay(100);
  digitalWrite(boardLed,HIGH);
  delay(100);
  digitalWrite(boardLed,LOW);

  // Now we average the "on" and "off" values to get an idea of what the resistance will be when the LED is on and off
  intactValue = (on_1+on_2)/2;
  brokenValue = (off_1+off_2)/2;

  // Let's also calculate the value between ledOn and ledOff, above which we will assume the led is on and below which we assume the led is off.
  beamThreshold = (intactValue+brokenValue)/2;

}
// Now for the loop.
void loop() {
  if (analogRead(photoresistor)>beamThreshold) {
    if (beamBroken==true) {
        Particle.publish("ckinneypubpr","open");
        digitalWrite(boardLed,HIGH);
        delay(5000);
        digitalWrite(boardLed,LOW);
        beamBroken=false; // Finally, set the flag to reflect the current status of the beam.
    }
    else {
        // Otherwise, this isn't a new status, and we don't have to do anything.
    }
  }
  else {
      // If you are below the threshold, the beam is probably broken.
      if (beamBroken==false) {
        Particle.publish("ckinneypubpr","closed"); // Send a publish...
        digitalWrite(boardLed,HIGH);
        delay(5000);
        digitalWrite(boardLed,LOW);
        beamBroken=true;
      }
      else {
          // Otherwise, this isn't a new status, and we don't have to do anything.
      }
  }
if (analogRead(fsrpin)<1000) { //3000 is an arbitrary numeber. When the resistor is perfeclty straight and has no wight it reads arond the max value of 4095. 
    if (pressureon==true) {
        Particle.publish("ckinneypubfsr","no mail");
        digitalWrite(boardLed,HIGH);
        delay(5000);
        digitalWrite(boardLed,LOW);
        pressureon=false; // Finally, set the flag to reflect the current status of the beam.
    }
    else {
        // Otherwise, this isn't a new status, and we don't have to do anything.
    }
  }
  else {
      // If you are below the threshold, the beam is probably broken.
      if (pressureon==false) {
        Particle.publish("ckinneypubfsr","mail"); // Send a publish...
        digitalWrite(boardLed,HIGH);
        delay(5000);
        digitalWrite(boardLed,LOW);
        pressureon=true;
      }
      else {
          // Otherwise, this isn't a new status, and we don't have to do anything.
      }
  }
}

OLED and Receiving Particle

Arduino
This code handles the reception of published events and the output of information onto an OLED screen.
/* Particle Pin out, attached to OLED Screen
 *
 *                                     +-----+
 *                          +----------| USB |----------+
 *                          |          +-----+       *  |
 *                          | [ ] VIN           3V3 [*] |-----VCC
 *                  Gnd-----| [*] GND           RST [ ] |
 *                          | [ ] TX           VBAT [ ] |
 *                          | [ ] RX  [S]   [R] GND [ ] |
 *                          | [ ] WKP            D7 [*] |-----RST       
 *                          | [ ] DAC +-------+  D6 [*] |-----DC       
 *                   D1-----| [*] A5  |   *   |  D5 [ ] |       
 *                          | [ ] A4  |Photon |  D4 [ ] |     
 *                   D0-----| [*] A3  |       |  D3 [ ] |       
 *                   Cs-----| [*] A2  +-------+  D2 [ ] |       
 *                          | [ ] A1             D1 [ ] |       
 *                          | [ ] A0             D0 [ ] |
 *                          |                           |
 *                           \    []         [______]  /
 *                            \_______________________/
 *
 *
 */
 
#include "SparkFunMicroOLED/SparkFunMicroOLED.h"  // Include MicroOLED library
 #include "math.h"
 
 MicroOLED oled;
 int countvalue = 0;
 const char *mail = "No Mail :(";

 void setup()
 {
   Particle.subscribe("ckinneypubpr", myHandler);
   Particle.subscribe("ckinneypubfsr", myHandler);
   Serial.begin(9600);
   oled.begin();    // Initialize the OLED
   oled.clear(ALL); // Clear the display's internal memory
   oled.display();  // Display what's in the buffer (splashscreen)
   delay(1000);     // Delay 1000 ms
 }

 void myHandler(const char *event, const char *data)
 {
     if (strcmp(data,"open")==0) {
     countvalue = countvalue + 1;
   }
   else {
   }
   
   if (strcmp(data,"no mail")==0) {
     mail = "NO...  :(";
   }
   else if (strcmp(data,"mail")==0) {
     mail = "Yessss!  :)";
   }
   else {
     // if the data is something else, don't do anything.
     // Really the data shouldn't be anything but those two listed above.
   }
   
 }

 void loop()
 {
   oled.setFontType(1);  // Set font to type 1
   oled.clear(PAGE);     // Clear the page
   oled.setCursor(0, 0); // Set cursor to top-left
   oled.print("Mail? ");
   oled.setCursor(0,16);
   oled.print(mail);
   oled.display();       // Refresh the display
   delay(3000);          // Delay a second and repeat
   oled.clear(PAGE);
   oled.setCursor(0, 0);
   oled.print("Times  Opened: ");
   oled.setCursor(0, 32);
   oled.print(countvalue);
   oled.display();
   delay(3000);
 }

Credits

Cameron Kinney

Cameron Kinney

1 project • 2 followers
UNCC18 BSME MEGR
Tanner Sponhouse

Tanner Sponhouse

1 project • 3 followers
20 years old Mechanical Engineering Student University of North Carolina at Charlotte

Comments