Andrea LiebermanDavid Rosenfield
Published

Whiskey Business

Never find yourself out of Whiskey with this setup that will notify you at the perfect time to hit the ABC store.

IntermediateFull instructions provided15 hours290
Whiskey Business

Things used in this project

Hardware components

Photon
Particle Photon
×2
LED (generic)
LED (generic)
×2
Resistor 221 ohm
Resistor 221 ohm
×4
4xAA battery holder
4xAA battery holder
×1
Photo resistor
Photo resistor
×2

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Webhook chart

Shows that the webhook is sending and receiving information from the particle cloud to IFTTT

Circuit Schematic

The particle is the key component in connecting a signal from the photoresistor to a cloud in the internet. This will be the setup for both particles

Code

Whiskey Level

C/C++
This code will collect a signal from the photo resistor of the status of the whiskey. If the whiskey bottle is not replaced after a set time, a command will be published through the particle cloud, to your phone to remind you to buy more whiskey.
int led = D0; // This is where your LED is plugged in. The other side goes to a resistor connected to GND.
int boardLed = D7;
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).
// The reason we have plugged one side into an analog pin instead of to "power" is because we want a very steady voltage to be sent to the photoresistor.
// That way, when we read the value from the other side of the photoresistor, we can accurately calculate a voltage drop.

int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
int present;
int critical_value = 30;
int dooropencutoff = 90;
int door;

bool dooropen = false;
bool whiskeypresent = true;

String data;  //string global variable for publishing

// Next we go into the setup function.

void setup() {

    // First, declare all of our pins. This lets our device know which ones will be used for outputting voltage, and which ones will read incoming voltage.
    pinMode(led,OUTPUT); // Our LED pin is output (lighting up the LED)
    pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
    pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)
    pinMode(boardLed,OUTPUT);
    // Next, write the power of the photoresistor to be the maximum possible, so that we can use this for power.
    digitalWrite(power,HIGH);

    // We are going to declare a Paritcle.variable() here so that we can access the value of the photoresistor from the cloud.
    Particle.variable("analogvalue", &analogvalue, INT);
    // This is saying that when we ask the cloud for "analogvalue", this will reference the variable analogvalue in this app, which is an integer variable.
    Particle.variable("door", &door, INT);
    // We are also going to declare a Particle.function so that we can turn the LED on and off from the cloud.
   Particle.subscribe("doorStatus",myHandler);
}

 
void myHandler(const char event,const char *data)
{  if (dooropen==true) {
    if (strcmp(data,"Closed")==0) {
    // if your buddy's beam is intact, then turn your board LED off
    door=0;
   dooropen=false;
   delay(12000);
   digitalWrite(boardLed,HIGH);
   delay(1000);
    digitalWrite(led,HIGH);
    delay(3000);
   analogvalue = analogRead(photoresistor);
   if (whiskeypresent==true){
   if  (analogvalue<critical_value) {
    Particle.publish("Whiskey Out");                                                                    
    whiskeypresent=false;
    present=0;
    updateThingspeak();
    }}
    else{
    if (analogvalue>dooropencutoff){
    }
    else if(analogvalue>critical_value) {Particle.publish("whiskey");                                   
    whiskeypresent=true;                                                                
    present=1;
    updateThingspeak();
    }
    else{}
    }
    digitalWrite(boardLed,LOW);
    digitalWrite(led,LOW);
    }
  else {
  Particle.publish("Door","Open");
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }}
  else {
        if (strcmp(data,"Open")==0){
      door=1;
      dooropen=true;
    }
        else{
    }
  }
}

bool updateThingspeak() 
{
Particle.subscribe("hook-response/ThingSpeak", myHandler, MY_DEVICES);
bool success = Particle.publish("thingSpeakWrite_A0", "{ \"1\": \"" + String(abnalogvalue) + "\", \"k\": \"XXXXXXXXXXXXXXXX\" }", 60, PRIVATE);
    lastPublish = now;
}

return success; //if sent, then turn of the send flag, otherwise let it try again.
    
}

Fridge Sensor

C/C++
This code reads to see if the fridge is open with a photoresistor and if it is open prompts the second particle to check for the whiskey. For the code to work properly, the values returned for lighting will need to be calibrated based on your fridge
/ This app will read the brightness reading off of the photoresistor. Then, if the read exceeds the threshold level, it will publish the variable stating that the frigde is open

int led = D0; // This is where your LED is plugged in. The other side goes to a resistor connected to GND.
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;

int lightlevel;
int Fridge;
// The following values are the read values of the photoresistor 
int Closedvalue=300; // This is the average value that the photoresistor reads while in the fridge.
int Openvalue=1900; // This is the average value that the photoresistor reads when exposed to average lighting.
int Cutoff=((Closedvalue+Openvalue)/2);

bool Dooropen = false;







void setup() {
 pinMode(led,OUTPUT); // Our LED pin is output (lighting up the LED)
  pinMode(boardLed,OUTPUT); // Our on-board LED is output as well
  pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
  pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)

digitalWrite(power,HIGH);



 Particle.variable("analogvalue", &lightlevel, INT);



}



void loop() {
/* In this loop function, it checks to see if the light level means the door is open
  When the status of the door changes, we'll send a Particle.publish() 


 It will also turn the LEDs on when the Photoresistor detects a light
  */

lightlevel=analogRead(photoresistor);
  
 // Get some data
  String data = String(10);
  // Trigger the integration
  //Particle.publish("Fridge", data, PRIVATE);
  // Wait 60 seconds
  //updateThingspeak();
  delay(2000);
  
 


  if (analogRead(photoresistor)<Cutoff){
      
      
    if (Dooropen==true) {
        // If the door was already open, then we assume you have closed it
        // We will send a publish to the cloud and blink LED on.

        // Send a publish to your devices...
        Particle.publish("doorStatus","Closed",60);
        // And flash the on-board LED on and off.
        digitalWrite(boardLed,HIGH);
        digitalWrite(led,HIGH);
        delay(3000);
        digitalWrite(boardLed,LOW);
        digitalWrite(led,LOW);
        // And change the status of the door
        Dooropen=false;
    }
    else {
        // Otherwise, this isn't a new status, and we don't have to do anything.
        // This way, the device will not continue to send door open and door closed notifications if it is held open
    }
    }
  
  else 
      // If you are above the threshold, assume the door is open
      if (Dooropen==false) {  // If the door is already closed, we must have opened it

        // Send a publish...
        Particle.publish("doorStatus","Open",60);
        // And flash the  LED on and off.
        digitalWrite(boardLed,HIGH);
        digitalWrite(led,HIGH);
        delay(3000);
        digitalWrite(boardLed,LOW);
        digitalWrite(led,LOW);

        // and change the status of the door
        Dooropen=true;
      }
      else {
          // Otherwise, this isn't a new status, and we don't have to do anything.
      }
   
    
}

bool updateThingspeak() {
      
      bool success = Particle.publish("Fridge",+  "{ \"1\": \"" + String(lightlevel) + "\"}",60,PRIVATE);
      return success;
  }

Credits

Andrea Lieberman

Andrea Lieberman

1 project • 0 followers
Student at UNCC School of Engineering
David Rosenfield

David Rosenfield

1 project • 0 followers
I am a mechanical engineering student from UNC-Charlotte from Raleigh, NC my interests include aerodynamics and robotics!
Thanks to John McAlpine.

Comments