Trenton TeagueAllison FileConnor Frederes
Published © GPL3+

Drink Monitor

The drink monitor is designed to watch your drink for tampering when you step away with a variety of sensors.

IntermediateFull instructions provided20 hours305
Drink Monitor

Things used in this project

Hardware components

Argon
Particle Argon
×3
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Elegoo Water Level Senstor
×1
Breadboard (generic)
Breadboard (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×20
LED (generic)
LED (generic)
×3
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Maker service
IFTTT Maker service
Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets

Story

Read more

Schematics

Flow Chart

Chart of the Drink Monitor process and communication between three Particle Argons. This includes the sensors, alerts, and live data read by this system. There is two-way communication between each of the sensor circuits.

Water Level Sensor

This is the most basic of the circuit diagrams. Power and ground come directly from the Argon 3V3 and GND respectively. Sensor Data runs back through A0.

Temperature and Humidity Sensor

Power and Ground come from D8 and Li+ on the Argon respectively. The Power is then restricted by the 220 Ohms resistor going into the positive on the Sensor. Negative is also connected to ground accordingly. Sensor data is reported back to D2.

Motion Sensor with LED Warning Light

Power and Ground come from 3V3 and GND. They then connect to positive and negative on the sensor. Sensor data is then run back to A0. The warning light is threaded into power with a 220 Ohms resistor and lights up when D0 is triggered. This is triggered when Water Level is low or Temperature is changing.

Code

Motion Sensor Codes

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

int calibrateTime = 100;      // wait for the thingy to calibrate

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(ledPin2, OUTPUT);
  Particle.subscribe("Temperature_Lyons", myHandler, MY_DEVICES);
  Particle.subscribe("No_H20_Lyons", myHandler, MY_DEVICES);
}
void myHandler(const char *event, const char *data){
    digitalWrite(ledPin2,HIGH);
    delay(5000);
    digitalWrite(ledPin2,LOW);
    }
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 eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("motion","Motion Detected");
      // 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 );
}

Water Level Sensor

C/C++
int waterSens = A0; //define water sensor
int led = D7;//define led to pin 9
int waterVal; //define the water sensor value



void setup() {
pinMode(led, OUTPUT); //set led as an output
pinMode(waterSens, INPUT);//set water sensor as an input
pinMode(LED_PIN, OUTPUT);
     Particle.subscribe("motion", myHandler, MY_DEVICES);
     Particle.subscribe("Temperature_Lyons", myHandler, MY_DEVICES);
}  

void myHandler(const char *event, const char *data){
    digitalWrite(LED_PIN,HIGH);
    delay(2000);
    digitalWrite(LED_PIN,LOW);
}

void loop() {


  waterVal = analogRead(waterSens); //read the water sensor
  delay(1000);

String level = String(waterVal);
  Particle.publish("Water_level_value", level, PRIVATE);
  delay(1000);

if (waterVal>0 && waterVal<=300){
    Particle.publish("Water_Level_iot1", "LOW   ",PRIVATE);
   
}
else if (waterVal>300 && waterVal<=600){
    Particle.publish("Water_Level_iot1","MEDIUM",PRIVATE);

}
else if (waterVal>600){
    Particle.publish("Water_Level_iot1", "HIGH  ",PRIVATE );

}

}

Temperature and Humidity Sensor Code

C/C++
/ This #include statement was automatically added by the Particle IDE.

#include <LiquidCrystal.h>

 

// This #include statement was automatically added by the Particle IDE.

#include <ThingSpeak.h>

 

// This #include statement was automatically added by the Particle IDE.

#include <Adafruit_DHT.h>

 

// This #include statement was automatically added by the Particle IDE.

#include <Adafruit_DHT.h>

 

// This #include statement was automatically added by the Particle IDE.

#include <ThingSpeak.h>

 

 

 

// This example assumes the sensor to be plugged into CONN2

#define DHTPIN 2     // what pin we're connected to

 

// Here we define the type of sensor used

#define DHTTYPE DHT11        // DHT 11

 

DHT dht(DHTPIN, DHTTYPE);

 

bool humid = false;

 

TCPClient client;

 

 

unsigned long myChannelNumber = 919272;

const char * myWriteAPIKey = "X2KU2U3BSYN4214V";

 

 

void setup() {

   

    ThingSpeak.begin(client);

   

 pinMode(D2, OUTPUT);

Serial.begin(9600);

 dhtbegin();
 Particle.subscribe("motion", myHandler, MY_DEVICES);
     Particle.subscribe("no_H2O_Lyons", myHandler, MY_DEVICES);
}  

void myHandler(const char *event, const char *data){
    digitalWrite(LED_PIN,HIGH);
    delay(2000);
    digitalWrite(LED_PIN,LOW);

 

 

}

 

void loop() {

    // Wait a few seconds between measurements.

    delay(2000);

 

    // Sensor readings may also be up to 2 seconds

    // Read temperature as Celsius

    float t = dht.getTempCelcius();

    // Read temperature as Farenheit

    float f = dht.getTempFarenheit();

 

 

    Particle.publish("Allison_File_IOTtemperature", String (f), ALL_DEVICES);

   

    ThingSpeak.setField(1,f);

    Serial.print(dht.getTempFarenheit());

    Serial.println("f");

    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 

    delay(60000); // ThingSpeak will only accept updates every 15 seconds.

 

}

 

    void l(const char *event, const char *data) {

       

            digitalWrite(D2, HIGH);

            delay(2000);

            digitalWrite(D2, LOW);

            delay(1000);

      

    }

Credits

Trenton Teague
2 projects • 0 followers
Allison File
0 projects • 1 follower
Connor Frederes
0 projects • 0 followers

Comments