Faucet

The Sink That Can Think

Full instructions provided2,236
Faucet

Things used in this project

Hardware components

PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
1/8" Acrylic - Fluorescent Green
×1
1/8 Acrylic - Translucent White
×1
Purple LED
×2
Speaker
×1
Acrylic Welding Solution
×1
Cardboard Tube (for resonance chamber)
×1
Velcro
×1
Electrical Tape (for resonance chamber)
×1
Flex Resistor
×1
NPN Tip120 Power Transistor
×1
SD Card Sound Board
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Wires
×18
Arduino Pro Mini 328 - 3.3V/8MHz
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1

Story

Read more

Custom parts and enclosures

axon_20for_20arduino_20enclosure.stl

Sketchfab still processing.

Code

faucet.ino

Plain text
faucet.ino
/*
  A = motion sensing = 0000, 0001, 0009, 0011; 0013
  B = water flow
  C = hardcode
 */

/*
  Sounds and Corresponding File Names:
  SUE
  0000 = Whoa, I'm feeling a bit of rain through my pipes today!
  0001 = (A) You know, the microwave was just talking about you
  0002 = (A) The silverware was just telling me there's a drought?!
         That can't be good.
  0003 = (C) Hey, be kind to my handles! Slow and steady now.
  0004 = (B) Oh that looks like it could use some soap.
  0005 = (B) The water keeps talking about the Hetchy reservoir.
         Seems like its spent a lot of time there.
  0006 = (B) Cut back on the water! I'm in charge of it! Understand?
  0007 = (B) Did you know this water came all the way from the Sierra Nevada?
         Give it some respect please!
  0008 = (B) I'm giving you an important task. Keeping me clean.
         I want to shine like an ice cube.
  0009 = (A) I feel like you could use a nice glass of water right now.
  0010 = (B) Ah. Now isnt thaat nice?
  0011 = (A) A sponge a day keeps the mildew away.
  
  STUART
  0012 = (C) Hey! The waters scalding!
  0013 = (A) Hope youre having a good day!
  0014 = (B) Heres some Sierra Nevada...*water plays*
  0015 = (B) You know what this reminds me of? *song plays*
 */

#include <Wtv020sd16p.h>
//#include <Event.h>
//#include <Timer.h>

int resetPin = 2;  // The pin number of the reset pin.
int clockPin = 3;  // The pin number of the clock pin.
int dataPin = 4;  // The pin number of the data pin.
int busyPin = 5;  // The pin number of the busy pin.

int flexPin = A0;
int motionPin = 7;

int stuartMotionPhrases[] = {13};
int stuartWaterPhrases[] = {14,15};
int stuartSpecialPhrases[] = {12};

int sueMotionPhrases[] = {0,1,2,9,11};
int sueWaterPhrases[] = {4,5,6,7,8,10};
int sueSpecialPhrases[] = {3};

int demoPin = 12;

int count = 0;

int flexValueCenter = 770;

int pirVal;
int flexValue;
int prevFlexValue;

int motionDetected = 0;
int waterDetected = 0;

int waterFlowTotalTime = 0;
int motionTotalTime = 0;

int flexEnabled = 1;
int motionEnabled = 1;


int SUE = 0;
int STUART = 1;
int voice = 1;

int water = 0;
int motion = 1;
int special = 2;


/*
Create an instance of the Wtv020sd16p class.
 1st parameter: Reset pin number.
 2nd parameter: Clock pin number.
 3rd parameter: Data pin number.
 4th parameter: Busy pin number.
 */
Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);

void setup() {
  //Initializes the module.
  Serial.begin(9600);
  wtv020sd16p.reset();
  pinMode(flexPin, INPUT);
  pinMode(motionPin, INPUT);
  pinMode(demoPin, INPUT);
  
  flexValue = analogRead(flexPin);
  prevFlexValue = flexValue;
  delay(5000);
}


void loop() {
  
  if(motionEnabled) {
    pirVal = digitalRead(motionPin);
  } else {
    pirVal = HIGH;
  }
  prevFlexValue = flexValue;
  delay(300);
  if(flexEnabled) {
    flexValue = analogRead(flexPin);
  } else {
    flexValue = prevFlexValue;
  }
  
  
  //Serial.println("FLEXV")

  if(pirVal == LOW){ //was motion detected
    Serial.println("Motion");
    if (digitalRead(demoPin)) {
      speakDemo();
    } else {
      speak(motion);
    }
   
  } else if (flexValue - prevFlexValue > 5 ) {
    Serial.println("Flex");
    Serial.println(prevFlexValue);
    Serial.println(flexValue);
    prevFlexValue = flexValue;
    if(digitalRead(demoPin)) {
      speakDemo();
    } else {
      speak(water);
    }
  } 
}


void speak(int phraseGroup) {
  if(voice == SUE) {
    if(phraseGroup == water) {
      int value = (int)random(6);
      wtv020sd16p.asyncPlayVoice(sueWaterPhrases[value]);
      
    } else if (phraseGroup == motion) {
      int value = (int) random(5);
      wtv020sd16p.asyncPlayVoice(sueMotionPhrases[value]);
      
    } else if (phraseGroup == special) {
      int value = (int) random(1);
      wtv020sd16p.asyncPlayVoice(sueSpecialPhrases[value]);
      
    }
  } else if(voice==STUART) {
    if(phraseGroup == water) {
      int value = (int)random(2);
      wtv020sd16p.asyncPlayVoice(sueWaterPhrases[value]);
      
    } else if (phraseGroup == motion) {
      int value = (int) random(1);
      wtv020sd16p.asyncPlayVoice(sueMotionPhrases[value]);
      
    } else if (phraseGroup == special) {
      int value = (int) random(1);
      wtv020sd16p.asyncPlayVoice(sueSpecialPhrases[value]);
    }
  } 
  delay(500);
  while(digitalRead(busyPin)) {
        //busy wait
  }
}

void speakDemo() {
  Serial.println("Demo");
  Serial.println(voice);
  
  if(voice == SUE) {
    if(count > 11) {
      count = 0;
    }
    
  } else if (voice == STUART) {
    if (count > 15 || count < 12) {
      count = 12;
    }
  }
  Serial.println(count);
  wtv020sd16p.asyncPlayVoice(count);
    delay(500);
    while(digitalRead(busyPin)) {
      //busy wait
    }
  count++;
  delay(2000);
}

Credits

Alexandra Greenspan

Alexandra Greenspan

11 projects • 5 followers
Computer Science and Cognitive Science double major
Clare Lin

Clare Lin

5 projects • 1 follower
I enjoy reading fiction, playing music and games, and consuming dark chocolate and jasmine green milk tea, though generally not all at the same time.
Kelsey Brennan

Kelsey Brennan

3 projects • 0 followers
Yang Zhao

Yang Zhao

4 projects • 1 follower
4th year, Computer Science (HCI)

Comments