Jennifer AdamsTyler Dollberg
Published

Drink Alert!!! (Beverage Can Monitor)

Tired of going to grab a soda only to find they're all gone!? Well now you have an alert system to let you know when you need to refill.

BeginnerFull instructions provided4 hours1,403
Drink Alert!!! (Beverage Can Monitor)

Things used in this project

Story

Read more

Schematics

PIR Motion Sensor Schematic

Senses motion

BUZZER Schematic

Buzzer sounds until button is pushed

Code

PIR Motion Sensor Code

C/C++
int inputPin = D0;              // choose the input pin (for PIR sensor)
int ledPin = D1;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

int calibrateTime = 10000;      // wait for the calibration

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     // declare sensor as input
}

void loop()
{

  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();

    // report it out, if the state has changed
    reportTheData();
  }
}

void readTheSensor() {
  val = digitalRead(inputPin);
}

bool calibrated() {
  return millis() - calibrateTime > 0;
}

void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an event
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("designingiot/s17/jadam125");
      // Update the current state
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}

void setLED( int state )
{
  digitalWrite( ledPin, state );
}

Buzzer Code

C/C++
int refill = 0;
int buzz = D0;  //pin call out for the buzzer
int buzzer = D3; //pin call out for the pushbutton

 int  x, minX;
void setup() {
    pinMode(D7, OUTPUT);
    pinMode(buzzer, INPUT_PULLDOWN);
    pinMode(buzz, OUTPUT);
    digitalWrite(buzz, LOW);
    Particle.subscribe("designingiot/s17/jadam125", myHandler, "36003a000347353138383138" );  //id for the particle


}
void myHandler(const char *event, const char *data)
{
    
}


void loop() {

 digitalWrite(D7, HIGH);
    
    if (data)
         digitalWrite(buzz, HIGH);
        refill = refill+1;
        Particle.publish("refill",String(refill)); //publishes to IFTTT to send text message and graph data
   delay(2000); //2 second delay
   digitalWrite(D7, LOW);
   
 if(digitalRead(buzzer) == HIGH)
        digitalWrite(buzz, LOW);  
        
     delay(1000);   
 
}

Credits

Jennifer Adams

Jennifer Adams

1 project • 2 followers
Tyler Dollberg

Tyler Dollberg

1 project • 0 followers

Comments