Nicholas BraunsteinerConnor TrautweinMichael DiRusso
Published © GPL3+

MEGR 3171 Automated Sink Sensing

Take control of washing your hands with this faucet sensing system!

BeginnerFull instructions provided8 hours270
MEGR 3171 Automated Sink Sensing

Things used in this project

Hardware components

Argon
Particle Argon
×3
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Elegoo KY-028 Digital Temperature Sensor
×1
FL-408 Water Flow Sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Plier, Waterpump
Plier, Waterpump

Story

Read more

Schematics

Ultrasonic Sensor Circuit

Digital Temperature Sensor Circuit

Water Flow Sensor Circuit

Code

Ultrasonic Sensor Code

C/C++
#define HCSR04_PIN_TRIG D4
#define HCSR04_PIN_ECHO D5


int sound = 0;
long timeTaken;
long distance;
int onboardLed = 7;

void setup() {
    
    Serial.begin(9600);
    pinMode(onboardLed, OUTPUT);
    pinMode(HCSR04_PIN_TRIG, OUTPUT);
    pinMode(HCSR04_PIN_ECHO, INPUT);
    Particle.subscribe("temp", temp, MY_DEVICES);       //Subscribe to temperature sensor
}



void loop() {
    
    digitalWrite(HCSR04_PIN_TRIG, LOW);
    delayMicroseconds(2);
    digitalWrite(HCSR04_PIN_TRIG,HIGH);
    delayMicroseconds(10);
    digitalWrite(HCSR04_PIN_TRIG,LOW);
    timeTaken = pulseIn(HCSR04_PIN_ECHO,HIGH);
    distance = (timeTaken/2)/29.1;




if (distance <= 20) {                                   
    
    Particle.publish("Water Flow", "On", PUBLIC);
}

else {
    
    Particle.publish("Water Flow", "Off", PUBLIC);
    
    }
}


void temp(const char *event, const char *data) {
    
    
    digitalWrite(onboardLed, HIGH);
    delay(1000);
    digitalWrite(onboardLed, LOW);
}

Temperature Sensor Code

C/C++
#include <ThingSpeak.h>

int analogvalue = 0;
double temp = 0;

void setup() {
    
    Serial.begin(9600);
    pinMode(D7, OUTPUT);
    pinMode(A0, INPUT);
    
    digitalWrite(D7, HIGH);
    delay(500);
    digitalWrite(D7,LOW);
    Particle.subscribe("Water Flow", WaterFlow, MY_DEVICES);            // Subscribe to motion sensor
   
    Particle.variable("analogvalue", analogvalue);
    Particle.variable("temp",temp);
  
}


void loop() { 
    
    delay(1000);
    analogvalue = analogRead(A0);
    temp = (analogvalue *- .08099688473520249 + 151.99688473520249);    // Convert analog value to degrees Fahrenheit
    delay(2000);

}

void WaterFlow(const char *event, const char *data) {
    
    
    if (strcmp(data, "On") == 0) {
        
        digitalWrite (D7, HIGH);
        Particle.publish("temp", String(temp), PRIVATE);                 // Publish temperature data to ThingSpeak when motion sensor is activated
    }
    
    else if (strcmp(data, "Off") == 0) {
        
        digitalWrite(D7 , LOW);
    }
        
    else {
        
    }
}

Water Flow Sensor Code

C/C++
#include <ThingSpeak.h>

volatile int flowFreq; 
float vol = 0.0;
float LPM;
unsigned char flowsensor = 2;
unsigned long currentTime;
unsigned long loopTime;

void flow () {
    
   flowFreq++;
}

void setup() {
    
    
    pinMode(flowsensor, INPUT);
    pinMode(D7, OUTPUT);
    
    Serial.begin(9600);
    digitalWrite(flowsensor, HIGH);
    attachInterrupt(flowsensor, flow, RISING);
    Particle.subscribe("Water Flow", WaterFlow, MY_DEVICES);    // Subscribe to motion sensor
    
    currentTime = millis();
    loopTime = currentTime;
}


void loop () {
    
   currentTime = millis();
   if(currentTime >= (loopTime + 1000))
   {
    loopTime = currentTime;
    if(flowFreq != 0){
      LPM = (flowFreq / 7.5);                                   // Calculate water flow in liters per minute
      Particle.publish("flow", String(LPM), PUBLIC);            // Publish instantaneous flow rate to ThingSpeak
      LPM = LPM/60;
      vol = vol + LPM;                                          // Calculate total volume 
      Particle.publish("vol", String(vol), PUBLIC);             // Publish cumulative volume data to ThingSpeak
      flowFreq = 0;
    }
  }
}


void WaterFlow(const char *event, const char *data) {
    
    
    if (strcmp(data, "On") == 0) {
        
        digitalWrite (D7, HIGH);
    }
    
    else if (strcmp(data, "Off") == 0) {
        
        digitalWrite(D7 , LOW);
    }
        
    else {
        
    }
}

Credits

Nicholas Braunsteiner
1 project • 0 followers
A student at UNCC working on a project for junior design.
Contact
Connor Trautwein
1 project • 0 followers
Contact
Michael DiRusso
1 project • 0 followers
Contact
Thanks to and .

Comments

Please log in or sign up to comment.