forked from harshavardhana04/Smart-blind-stick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ard_comm.ino
39 lines (36 loc) · 825 Bytes
/
ard_comm.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
#define triPin 2
#define Echo 3
#define vibrator 9
void setup() {
// put your setup code here, to run once:
pinMode(Echo,INPUT);
pinMode(triPin,OUTPUT);
pinMode(vibrator,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float duration;
int distance;
digitalWrite(triPin,HIGH);
delayMicroseconds(10);
digitalWrite(triPin,LOW);
duration=pulseIn(Echo,HIGH);
distance=duration*0.034/2;
//Serial.print("distance = ");
Serial.println(int(distance));
if(distance<20){
digitalWrite(vibrator,HIGH);
delay(100);
digitalWrite(Vibrator,LOW);
}/*
if(distance<25 and distance>10){
tone(Buzzer,500,300);
}
if(distance<10){
tone(Buzzer,1000,200);
}
else{
tone(Buzzer,2000,300);
}*/
}