-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest1.ino
56 lines (45 loc) · 1.07 KB
/
test1.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
#define trigPin 2
#define echoPin 3
#define Buzzer1 11 //active
#define Led1 6//Vibration
int sound = 25000;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(Buzzer1, OUTPUT);
//inMode(Buzzer2, OUTPUT);
pinMode(Led1, OUTPUT);
}
void loop() {
Serial.begin(9600);
//noTone(11);
long duration, distance;
digitalWrite(trigPin, LOW);
delay(2);
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(distance);
digitalWrite(Led1, LOW);
delay(100);
if (distance<40 and distance>20) {
Serial.println("distance is 40");
delay(100);
tone(11,350,500);
}
else if (distance<20 and distance>10) {
Serial.println("distance is 20");
delay(100);
tone(11,800,500);
}
else if (distance<10) {
Serial.println("Distance is 10");
delay(100);
tone(11,2000,500);
digitalWrite(Led1, HIGH);
}
delay(1000);
}