Things used in this project

Hardware components:
13285 01
PIR Motion Sensor (generic)
×1
1/8" Acrylic - Fluorescent Green
×1
Purple LED
×2
1/8 Acrylic - Translucent White
×1
Acrylic Welding Solution
×1
Speaker
×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
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
Wires
×18
11114 01a
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1

Custom parts and enclosures

axon_20for_20arduino_20enclosure.stl

Sketchfab still processing.

Code

faucet.inoPlain 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

2014 01 10 11.35.15
Alexandra Greenspan

Computer Science and Cognitive Science double major

Pic
Clare Lin

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.

1463759 595382937187452 471581188 n
Yang Zhao

4th year, Computer Science (HCI)

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Community Skill Show (Have a Go Hero) Workshop
  • 47
  • 1

Workshop held on the 22nd of March 2017 at the College of North West London Skills Show event. Pictures and report from the event.

Unlock your door with a knock
  • 13,964
  • 46

Full instructions

Open your door with a special knock using Arduino, Android Phone and 1Sheeld

DIY Relay Outlet Arduino
  • 19,465
  • 23

Full instructions

Control a wall outlet using an Arduino using this DIY solid state relay outlet.

Uber Home Automation
  • 23,508
  • 111

Work in progress

Wireless Arduino sensor nodes and awesome home automation platform called OpenHAB.  Know when your dog barks.

Magoo
  • 4,642
  • 25

Work in progress

An obstacle-detection and GPS-enabled navigation wearable for the visually impaired.

Magoo

4 members

Arduino to Excel using V-USB
  • 31,006
  • 30

Full instructions

Log 6 analog and 8 digital pins from Arduino Uno simultaneously in Excel.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback