-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSRF05-yuan.ino
58 lines (58 loc) · 1.83 KB
/
SRF05-yuan.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
#define cm195 12401;
#define cm240 12600;
#define cm5 200006;
#define cm50 20100;
#define cm100 221636;
#define cm150 11328;
#define cm200 12422;
int inputPin=4; // define ultrasonic signal receiver pin ECHO to D4
int outputPin=5; // define ultrasonic signal transmitter pin TRIG to D5
String Sdata;
unsigned long ldata;
void setup()
{
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
ldata=200001;
}
void loop()
{
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH); // Pulse for 10μs to trigger ultrasonic detection
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
int distance = pulseIn(inputPin, HIGH); // Read receiver pulse time
distance= distance/58; // Transform pulse time to distance
Serial.println(distance); //Ourput distance
delay(50);
/* int i =1;
while(i){
// digitalWrite(outputPin, LOW);
//delayMicroseconds(2);
digitalWrite(outputPin, HIGH); //
//delayMicroseconds(10);
digitalWrite(outputPin, LOW);
///.delayMicroseconds(12);
}*/
/*int distance = pulseIn(inputPin, HIGH);
if (distance){
distance= distance/58;
Serial.println(digitalRead(distance));
}
*//*while(Serial.available() >0){
Sdata+=char(Serial.read());
delay(4);
}
if (Sdata.length() >0){
ldata=strtoul(Sdata.c_str(),NULL,10);
Serial.println(ldata);
Sdata="";
}
//digitalWrite(outputPin, LOW);
digitalWrite(outputPin, HIGH);
delayMicroseconds(ldata);
digitalWrite(outputPin, LOW);
// delayMicroseconds(2000);*/
}