Letice BussiereNicholas Brummitt
Published

Water Level Monitor for Pet Drinking Fountain

Let's face it. You're tired of losing pets to dehydration. You need to be alerted when your furry friend needs that sweet Earth nectar!

BeginnerFull instructions provided5 hours486

Things used in this project

Hardware components

Photon
Particle Photon
×2
Jumper wires (generic)
Jumper wires (generic)
4 jumper wires to connect the Ultrasonic Distance Senser to photon. 3 jumper wires to connect Gravity Non-Contact Liquid Level Sensor to photon.
×7
Breadboard (generic)
Breadboard (generic)
×2
Gravity Non-Contact Liquid Level Sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Maker service
IFTTT Maker service
Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Tape, Electrical
Tape, Electrical

Story

Read more

Schematics

HC-SR04 Ultrasonic Module Distance Measuring Transducer Sensor

Gravity Non-Contact Liquid Level Sensor

Code

Gravity Non-Contact Sensor

C/C++
Code by Nicholas Brummitt
/* Connections from Gravity Non-Contact Sensor to Photon
 *
 *                                     +-----+
 *                          +----------| USB |----------+
 *                          |          +-----+       *  |
 *                  Vin-----| [*] VIN           3V3 [ ] |
 *                  Gnd-----| [*] GND           RST [ ] |
 *                          | [ ] TX           VBAT [ ] |
 *                          | [ ] RX  [S]   [R] GND [ ] |
 *                          | [ ] WKP            D7 [ ] |       
 *                          | [ ] DAC +-------+  D6 [ ] |      
 *                          | [ ] A5  |   *   |  D5 [*] |-----Signal       
 *                          | [ ] A4  |Photon |  D4 [ ] |     
 *                          | [ ] A3  |       |  D3 [ ] |      
 *                          | [ ] A2  +-------+  D2 [ ] |      
 *                          | [ ] A1             D1 [ ] |       
 *                          | [ ] A0             D0 [ ] |
 *                          |                           |
 *                           \    []         [______]  /
 *                            \_______________________/
 *
 *
 */

//Define variable to be used in the code. One variable is measured, so one variable interger input required 
int waterLevel;

void setup() {
    /*setup inputs and outputs for the device. Sensor input is the only input.
    In this code, an output to blink the built in LED was added to ensure the 
    sensor was reading out and could communicate with the other photon.
    */
pinMode(waterLevel, INPUT);
pinMode(D2, OUTPUT);

// Subscribe to IFTTT
    Particle.subscribe("iftttTrigger", myWaterHandler, MY_DEVICES);
    
// Subscribe to Letice's photon
     Particle.subscribe("echo_boi", Water_Check);
}

void myWaterHandler(const char *event, const char *data) {
// Handles Integration
}


void loop() {
    if (waterLevel == 1) {
    
        Serial.println("trouble");
        Particle.publish("iftttTrigger", "waterLOW");//Publishes to IFTTT to email water needs to be refilled
        digitalWrite(D7,HIGH);
        delay(2000);
        digitalWrite(D7, LOW);
    }
}
    
 void Water_Check (const char *event, const char *data) {
     
/*Loop used to communicate with the particle Photon and the sensor. If water is detected, the LED light lights up
    If no liquid detected nothing happens. Will be modified further to communicate this with another photon. 0
    */
    waterLevel = digitalRead(D5);
    
    if (waterLevel == 0 ){
        
        Particle.publish("echo_boi", "allclear");
        
    }
    
    else if(waterLevel == 1){
    
        Particle.publish("echo_boi", "waterLOW");
    
    }
    
    delay(15000);/*Time between measurements change here. At this moment
    a measurement is taken ever ten seconds. Can change to monitor every
    minute, every hour or every half hour.
    */


}

Ultrasonic Distance Sensor

C/C++
Code by Letice Bussiere
// This code is for the Ultrasonic Distance Sensor
//      This will measure the distance between the sensor and the water using a signal
//      that will be sent and will bounce back. If the distance is larger than allowed,
//      the photon will check with the Non-Contact Digital Liquid Sensor to verify that
//      the water is too low. The photon will send the distance to an Excel sheet to graph
//      the water level throughout the day.

/* Connections from Ultrasonic Distance Sensor to Photon
 *
 *                                     +-----+
 *                          +----------| USB |----------+
 *                          |          +-----+       *  |
 *                  Vcc-----| [*] VIN           3V3 [ ] |
 *                  Gnd-----| [*] GND           RST [ ] |
 *                          | [ ] TX           VBAT [ ] |
 *                          | [ ] RX  [S]   [R] GND [ ] |
 *                          | [ ] WKP            D7 [ ] |       
 *                          | [ ] DAC +-------+  D6 [ ] |      
 *                          | [ ] A5  |   *   |  D5 [ ] |       
 *                          | [ ] A4  |Photon |  D4 [ ] |     
 *                          | [ ] A3  |       |  D3 [*] |-----Trig      
 *                          | [ ] A2  +-------+  D2 [*] |-----Echo       
 *                          | [ ] A1             D1 [ ] |       
 *                          | [ ] A0             D0 [ ] |
 *                          |                           |
 *                           \    []         [______]  /
 *                            \_______________________/
 *
 *
 */
 

// Identify Pins Used and Variables
    
    const int TriggerPin = D3;
    const int EchoPin = D2;
    int LED = D7;
    int WaterLevel;
    int Duration;
    
    
void setup() {
    
    Serial.begin(9600);
    
// Digital Pin Input/Output
    pinMode(TriggerPin, OUTPUT);
    pinMode(EchoPin, INPUT);
    pinMode(LED, OUTPUT);
    
// Subscribe to Gravity Sensor Code
    Particle.subscribe("myphoton", Water_Check);

// Subscribe to IFTTT Applet that will publish data to Google Sheets
    Particle.subscribe("Water_Level", myWaterHandler, MY_DEVICES);
}

void myWaterHandler(const char *event, const char *data) {
// Handles Integration
}

void loop() {

// Begin with Trigger Pin Off for 5 Microseconds
    digitalWrite(TriggerPin, LOW);
    delayMicroseconds(2);
    
// Send the Signal for 15 Microseconds and Then Turn Off
    digitalWrite(TriggerPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(TriggerPin, LOW);
    
// Convert Time (in MICROseconds)
    Duration = pulseIn(EchoPin, HIGH);
    int WaterLevel = Duration * (0.034/2); 
    String Distance = String(Duration*0.034/2);
    
// Trigger the integration
    Particle.publish("Water_Level", Distance);
    
// Wait 60 seconds
    delay(60000);
    digitalWrite(LED, LOW);    // Turn OFF the LED
    delay(30000); 
}

void Water_Check (const char *event, const char *data) {
// Check Water Level with Gravity Photon
    
    /* This is where photons communicate both ways.
       Echo_boi photon receives the Boolean response from myphoton saying whether the water
       is above or below the sensor. Echo_boi then checks to see if the water level it detected
       is also above or below designated limit. It will send a response agreeing that the
       either the pets need water or that the water level is good. */
    
    // If water is low (water line below gravity non-contact sensor)
    // and water level is below 6.5 (obtained through trial and error),
    // send message to Nick's photo agreeing water is needed. 
    if (strcmp(data, "waterLOW") == true && WaterLevel > 6.5) {
        char *message1 = "Need Water";
        Particle.publish("myphoton", message1, 20); // Publishing to Nick's photon
        Serial.println("Need Water");
        digitalWrite(LED, HIGH);
        delay(1500);
        digitalWrite(LED, LOW);
    }
       
    // If water  and water level is below 6.5 (obtained through trial and error),
    // send message to Nick's photo agreeing water is needed.
    else if (strcmp(data, "allclear") == true && WaterLevel < 6.5) {
        char *message2 = "I Good";
        Particle.publish("myphoton", message2, 20); // Publishing to Nick's photon
        Serial.println("I Good");
        digitalWrite(LED, HIGH);
        delay(1500);
        digitalWrite(LED, LOW);
        
    }
    
} 

Credits

Letice Bussiere

Letice Bussiere

1 project • 0 followers
Nicholas Brummitt

Nicholas Brummitt

1 project • 0 followers
Thanks to Team AquaNiner.

Comments

Add projectSign up / Login