-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathultra_with_buzzer.ino
61 lines (55 loc) · 1.54 KB
/
ultra_with_buzzer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <LiquidCrystal.h> //Load Liquid Crystal Library
const int rs = 12, en = 11, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal LCD(rs, en, d4, d5, d6, d7);
#define trigPin 10//Sensor Echo pin connected to Arduino pin 13
#define echoPin 9 //Sensor Trip pin connected to Arduino pin 12
const int buzzer = 8;
const int LED = 13;
const int LED1 = 7;
const int LED2 = 2;
float duration, distance;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LED, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
LCD.print("STATUS:");
LCD.setCursor(5, 1);
LCD.print(distance);
if(distance>14){
digitalWrite(LED2, HIGH);
LCD.print("EMPTY ");
delay(1000);
}else{
digitalWrite(LED2, LOW);
}
if(distance<14 && distance >5){
digitalWrite(LED1, HIGH);
LCD.print("HALF FILLED ");
delay(1000);
}else{
digitalWrite(LED1, LOW);
}
if(distance<5){
digitalWrite(buzzer,HIGH);
digitalWrite(LED, HIGH);
LCD.print("TIME TO CLEAN!!! ");
delay(10);
}else{
digitalWrite(buzzer,LOW);
digitalWrite(LED, LOW);
}
}