takethebypass
Published © GPL3+

H20asis

Tasty thirsty-safety firsty-a touch-less water dispenser.

IntermediateFull instructions provided1,449
H20asis

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
ISD 1820 voice recorder
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

H20asis

H20asis

Code

H20asis full code

C/C++
#define REC 2
#define PLAY_E 3
#define FT 4
#define playTime 5000
#define recordTime 5000 

 
const int trigPin = 10;
const int echoPin = 11;
long duration;
int distance;

const int redPin = 12;
const int greenPin = 13;

const int pumpPin = 6;

const int mainpressPin = 7;
const int pressure1Pin = 8;
const int pressure2Pin = 9;

void setup() 
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT); 

  pinMode(REC,OUTPUT);// set the REC pin as output

  pinMode(PLAY_E,OUTPUT);// set the PLAY_e pin as output
  pinMode(FT,OUTPUT);
  Serial.begin(9600);
 
  pinMode(pumpPin, OUTPUT);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);  
  
  pinMode(mainpressPin,INPUT); // first pressure sensor
  pinMode(pressure1Pin,INPUT); // second pressure sensor
  pinMode(pressure2Pin,INPUT); // third pressure sensor
}


void loop() 
{
      char ch;
      if (Serial.available() > 0)
      {
          ch = Serial.read(); 
          // start recording
          if( ch == 'r'){
            digitalWrite(REC, HIGH);
            Serial.println("Recording started");
            delay(recordTime);
            digitalWrite(REC, LOW);
            Serial.println("Recording Stopped"); 
          }
          else{
          //TODO make this only print once
           // Serial.println("### Enter r to record");
          }
        //TODO make this only print once
        //Serial.println("###Serial Monitor Exited");
    }
    delay(500);

    //check if first pressure sensor is pressed
    int val=0;
    val=digitalRead(mainpressPin); //TODO make 7 a global variable

    if (val==1)
    {
       digitalWrite(trigPin, HIGH);
       digitalWrite(echoPin, HIGH);
       
       //digitalWrite(pressure1Pin,HIGH);
       //digitalWrite(pressure2Pin,HIGH);
       digitalWrite(greenPin, HIGH);
       digitalWrite(pumpPin,LOW);
       Serial.println("###System Activated");
    }

   if (val!=1){
       digitalWrite(trigPin,LOW);
       digitalWrite(echoPin, LOW);
       
      // digitalWrite(pressure1Pin,LOW);
       //digitalWrite(pressure2Pin,LOW);
       digitalWrite(greenPin, HIGH);
       digitalWrite(pumpPin,LOW);
  }

  //check if second pressure sensor is pressed

  int val_press=0;
  val_press=digitalRead(pressure1Pin);

  int val_touch=0;
  val_touch=digitalRead(pressure2Pin);

   if ((val_touch ==1 || val_press ==1) && val==1)
   {
       digitalWrite(redPin, HIGH);
       digitalWrite(greenPin,LOW);
       digitalWrite(PLAY_E, HIGH);
       digitalWrite(pumpPin, LOW);
       Serial.println("Step back please");
   }
   else 
   {
       digitalWrite(redPin, LOW);
       digitalWrite(PLAY_E, LOW);
       digitalWrite(pumpPin, LOW);
   }

   //calculate distance
 
   long duration, distance;
   digitalWrite(trigPin, HIGH);
   delay(1000);
   digitalWrite(trigPin, LOW);
   duration=pulseIn(echoPin, HIGH);
   distance=(duration/2)/29.1;  //TODO double check 29.1
   delay(10);

   //use distance of hand to control water flow
   if((distance>20))
   {
        digitalWrite(pumpPin, LOW);
        Serial.println("Water stopped");
   }
   else if(distance<=20 && distance!=0 && val_press!=1 && val_touch!=1 && val==1)
   {
         digitalWrite(pumpPin, HIGH);
         Serial.println("Water flowing");
   }
}                                                                                                                      

Pressure sensor

C/C++
Code to test pressure sensor(s)
const int mainpressPin = 7;

void setup()
{
  pinMode(mainpressPin, INPUT); // first pressure sensor
  Serial.begin(9600);
}

void loop()
{
  int val = 0;
  val = digitalRead(mainpressPin);

  if (val == 1)
  {
    Serial.println("1");
  }

  else
  {
    Serial.println("0");
  }
}

Credits

takethebypass

takethebypass

0 projects • 0 followers

Comments