Things used in this project

Hardware components:
Photon new
Particle Photon
×2
Adafruit industries ada161 image 75px
Photo resistor
×1
45 2719133f d90e 4f08 9a52 b5c9ba10eb77 large
Onion 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
Mfr 25fbf52 221r sml
Resistor 221 ohm
×1
11026 02
Jumper wires (generic)
×1
Mfr 25fbf52 22k1 sml
Resistor 22.1k ohm
×1
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
Hy gluegun
Hot glue gun (generic)

Schematics

Sensor Particle Schematic
Slightly more complicated than the Receiving Photon pin-out, but very doable for any skill level.
Mxlknqkgbnuy6pz0z1o6
OLED and Receiving Particle
Very simply pin-out. Just match the marked pins on the Photon with the labeled pins from the LCD screen.
9fnzt1vpaephcqlggeyb

Code

Sensor Particle CodeArduino
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 ParticleArduino
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

Image
Cameron Kinney

UNCC18 BSME MEGR

Contact
21ff2cf8abac5c7d994e126b782e21e4
Tanner Sponhouse

20 years old Mechanical Engineering Student University of North Carolina at Charlotte

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Networked RGB Wi-Fi Decorative Touch Lights
Advanced
  • 10,449
  • 133

Full instructions

Easy to use Wi-Fi enabled touch lights that network to give you a beautiful and unobtrusive way to stay connected with the people you love.

Use the Force... Or your Brainwaves?
Advanced
  • 17,248
  • 72

Full instructions

Thought controlled system with personal webserver and 3 working functions: robot controller, home automation and PC mouse controller.

The Minimalist Thermostat
Advanced
  • 5,402
  • 34

Full instructions

A thermostat you won't see

Car or Motorbike Tracker
Advanced
  • 3,057
  • 35

Work in progress

A GPS tracker for your car, motorcycle, bike and flying saucer, with data storage and map visualization. Not too hard, but no easy either...

Email Notifications Using Amazon Web Services
Advanced
  • 3,984
  • 20

Protip

When the Particle Cloud meets the Amazon Cloud

Star Wars Droid Translator Helmets
Advanced
  • 8,598
  • 62

Wear helmets & speak Droid to each other! Everyone hears droid "language" but wearers of the helmets hear each others' actual voice instead!

Add projectSign up / Login