forked from adarshpandey10t/Hacktoberfestmine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisinfectant
More file actions
95 lines (48 loc) · 1.27 KB
/
Disinfectant
File metadata and controls
95 lines (48 loc) · 1.27 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#define potentiometer A0
#define echopin A2 // echo pin
#define trigpin A3 // Trigger pin
int read_ADC =0;
long set_time =0;
long rememTime;
long dis_cm;
long ultra_time;
int set_cm = 80;
int relay = 2; // Out for light
int flag=0;
void setup(){
Serial.begin(9600);// initialize serial communication at 9600 bits per second:
pinMode(potentiometer, INPUT);
pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT);
pinMode(relay, OUTPUT);
delay(1000); // Waiting for a while
}
void loop(){
//*************************
ultra_read();
//*************************
read_ADC = analogRead(potentiometer);
set_time = map(read_ADC, 0, 1023, 1000, 20000);
Serial.print("Dis :");Serial.println(dis_cm);
Serial.print("Time:");Serial.println(set_time);
if(dis_cm<set_cm && flag==0){flag=1;
digitalWrite(relay,HIGH);
Serial.println("Relay On");
rememTime = millis();
}
if(dis_cm>set_cm){flag=0;}
if((millis()- rememTime) > set_time){
digitalWrite(relay,LOW);
Serial.println("Relay Off");
}
delay(100);
}
//**********************ultra_read****************************
void ultra_read(){
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
ultra_time = pulseIn (echopin, HIGH);
dis_cm = ultra_time / 29 / 2;
}