Components and supplies
Arduino Nano R3
RGB Diffused Common Cathode
Ultrasonic Sensor - HC-SR04 (Generic)
ISD 1820 voice recorder
Apps and platforms
Arduino Web Editor
Arduino IDE
Project description
Code
H20asis full code
c_cpp
1 2#define REC 2 3#define PLAY_E 3 4#define FT 4 5#define playTime 5000 6#define recordTime 5000 7 8 9const int trigPin = 10; 10const int echoPin = 11; 11long duration; 12int distance; 13 14const int redPin = 12; 15const int greenPin = 13; 16 17const int pumpPin = 6; 18 19const int mainpressPin = 7; 20const int pressure1Pin = 8; 21const int pressure2Pin = 9; 22 23void setup() 24{ 25 pinMode(redPin, OUTPUT); 26 pinMode(greenPin, OUTPUT); 27 28 pinMode(REC,OUTPUT);// set the REC pin as output 29 30 pinMode(PLAY_E,OUTPUT);// set the PLAY_e pin as output 31 pinMode(FT,OUTPUT); 32 Serial.begin(9600); 33 34 pinMode(pumpPin, OUTPUT); 35 36 pinMode(trigPin, OUTPUT); 37 pinMode(echoPin, INPUT); 38 39 pinMode(mainpressPin,INPUT); // first pressure sensor 40 pinMode(pressure1Pin,INPUT); // second pressure sensor 41 pinMode(pressure2Pin,INPUT); // third pressure sensor 42} 43 44 45void loop() 46{ 47 char ch; 48 if (Serial.available() > 0) 49 { 50 ch = Serial.read(); 51 // start recording 52 if( ch == 'r'){ 53 digitalWrite(REC, HIGH); 54 Serial.println("Recording started"); 55 delay(recordTime); 56 digitalWrite(REC, LOW); 57 Serial.println("Recording Stopped"); 58 } 59 else{ 60 //TODO make this only print once 61 // Serial.println("### Enter r to record"); 62 } 63 //TODO make this only print once 64 //Serial.println("###Serial Monitor Exited"); 65 } 66 delay(500); 67 68 //check if first pressure sensor is pressed 69 int val=0; 70 val=digitalRead(mainpressPin); //TODO make 7 a global variable 71 72 if (val==1) 73 { 74 digitalWrite(trigPin, HIGH); 75 digitalWrite(echoPin, HIGH); 76 77 //digitalWrite(pressure1Pin,HIGH); 78 //digitalWrite(pressure2Pin,HIGH); 79 digitalWrite(greenPin, HIGH); 80 digitalWrite(pumpPin,LOW); 81 Serial.println("###System Activated"); 82 } 83 84 if (val!=1){ 85 digitalWrite(trigPin,LOW); 86 digitalWrite(echoPin, LOW); 87 88 // digitalWrite(pressure1Pin,LOW); 89 //digitalWrite(pressure2Pin,LOW); 90 digitalWrite(greenPin, HIGH); 91 digitalWrite(pumpPin,LOW); 92 } 93 94 //check if second pressure sensor is pressed 95 96 int val_press=0; 97 val_press=digitalRead(pressure1Pin); 98 99 int val_touch=0; 100 val_touch=digitalRead(pressure2Pin); 101 102 if ((val_touch ==1 || val_press ==1) && val==1) 103 { 104 digitalWrite(redPin, HIGH); 105 digitalWrite(greenPin,LOW); 106 digitalWrite(PLAY_E, HIGH); 107 digitalWrite(pumpPin, LOW); 108 Serial.println("Step back please"); 109 } 110 else 111 { 112 digitalWrite(redPin, LOW); 113 digitalWrite(PLAY_E, LOW); 114 digitalWrite(pumpPin, LOW); 115 } 116 117 //calculate distance 118 119 long duration, distance; 120 digitalWrite(trigPin, HIGH); 121 delay(1000); 122 digitalWrite(trigPin, LOW); 123 duration=pulseIn(echoPin, HIGH); 124 distance=(duration/2)/29.1; //TODO double check 29.1 125 delay(10); 126 127 //use distance of hand to control water flow 128 if((distance>20)) 129 { 130 digitalWrite(pumpPin, LOW); 131 Serial.println("Water stopped"); 132 } 133 else if(distance<=20 && distance!=0 && val_press!=1 && val_touch!=1 && val==1) 134 { 135 digitalWrite(pumpPin, HIGH); 136 Serial.println("Water flowing"); 137 } 138}
Pressure sensor
c_cpp
Code to test pressure sensor(s)
1const int mainpressPin = 7; 2 3void setup() 4{ 5 pinMode(mainpressPin, INPUT); // first pressure sensor 6 Serial.begin(9600); 7} 8 9void loop() 10{ 11 int val = 0; 12 val = digitalRead(mainpressPin); 13 14 if (val == 1) 15 { 16 Serial.println("1"); 17 } 18 19 else 20 { 21 Serial.println("0"); 22 } 23}
H20asis full code
c_cpp
1 2#define REC 2 3#define PLAY_E 3 4#define FT 4 5#define playTime 6 5000 7#define recordTime 5000 8 9 10const int trigPin = 10; 11const int 12 echoPin = 11; 13long duration; 14int distance; 15 16const int redPin = 12; 17const 18 int greenPin = 13; 19 20const int pumpPin = 6; 21 22const int mainpressPin = 23 7; 24const int pressure1Pin = 8; 25const int pressure2Pin = 9; 26 27void setup() 28 29{ 30 pinMode(redPin, OUTPUT); 31 pinMode(greenPin, OUTPUT); 32 33 pinMode(REC,OUTPUT);// 34 set the REC pin as output 35 36 pinMode(PLAY_E,OUTPUT);// set the PLAY_e pin 37 as output 38 pinMode(FT,OUTPUT); 39 Serial.begin(9600); 40 41 pinMode(pumpPin, 42 OUTPUT); 43 44 pinMode(trigPin, OUTPUT); 45 pinMode(echoPin, INPUT); 46 47 48 pinMode(mainpressPin,INPUT); // first pressure sensor 49 pinMode(pressure1Pin,INPUT); 50 // second pressure sensor 51 pinMode(pressure2Pin,INPUT); // third pressure sensor 52} 53 54 55void 56 loop() 57{ 58 char ch; 59 if (Serial.available() > 0) 60 { 61 62 ch = Serial.read(); 63 // start recording 64 if( 65 ch == 'r'){ 66 digitalWrite(REC, HIGH); 67 Serial.println("Recording 68 started"); 69 delay(recordTime); 70 digitalWrite(REC, LOW); 71 72 Serial.println("Recording Stopped"); 73 } 74 else{ 75 76 //TODO make this only print once 77 // Serial.println("### 78 Enter r to record"); 79 } 80 //TODO make this only print once 81 82 //Serial.println("###Serial Monitor Exited"); 83 } 84 delay(500); 85 86 87 //check if first pressure sensor is pressed 88 int val=0; 89 val=digitalRead(mainpressPin); 90 //TODO make 7 a global variable 91 92 if (val==1) 93 { 94 digitalWrite(trigPin, 95 HIGH); 96 digitalWrite(echoPin, HIGH); 97 98 //digitalWrite(pressure1Pin,HIGH); 99 100 //digitalWrite(pressure2Pin,HIGH); 101 digitalWrite(greenPin, HIGH); 102 103 digitalWrite(pumpPin,LOW); 104 Serial.println("###System Activated"); 105 106 } 107 108 if (val!=1){ 109 digitalWrite(trigPin,LOW); 110 digitalWrite(echoPin, 111 LOW); 112 113 // digitalWrite(pressure1Pin,LOW); 114 //digitalWrite(pressure2Pin,LOW); 115 116 digitalWrite(greenPin, HIGH); 117 digitalWrite(pumpPin,LOW); 118 } 119 120 121 //check if second pressure sensor is pressed 122 123 int val_press=0; 124 val_press=digitalRead(pressure1Pin); 125 126 127 int val_touch=0; 128 val_touch=digitalRead(pressure2Pin); 129 130 if ((val_touch 131 ==1 || val_press ==1) && val==1) 132 { 133 digitalWrite(redPin, HIGH); 134 135 digitalWrite(greenPin,LOW); 136 digitalWrite(PLAY_E, HIGH); 137 digitalWrite(pumpPin, 138 LOW); 139 Serial.println("Step back please"); 140 } 141 else 142 { 143 144 digitalWrite(redPin, LOW); 145 digitalWrite(PLAY_E, LOW); 146 digitalWrite(pumpPin, 147 LOW); 148 } 149 150 //calculate distance 151 152 long duration, distance; 153 154 digitalWrite(trigPin, HIGH); 155 delay(1000); 156 digitalWrite(trigPin, LOW); 157 158 duration=pulseIn(echoPin, HIGH); 159 distance=(duration/2)/29.1; //TODO double 160 check 29.1 161 delay(10); 162 163 //use distance of hand to control water flow 164 165 if((distance>20)) 166 { 167 digitalWrite(pumpPin, LOW); 168 Serial.println("Water 169 stopped"); 170 } 171 else if(distance<=20 && distance!=0 && val_press!=1 && 172 val_touch!=1 && val==1) 173 { 174 digitalWrite(pumpPin, HIGH); 175 Serial.println("Water 176 flowing"); 177 } 178}
Downloadable files
H20asis
H20asis
H20asis
H20asis
H20asis
H20asis
H20asis
H20asis
Comments
Only logged in users can leave comments
takethebypass
0 Followers
•0 Projects
Table of contents
Intro
0
0