-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino.ino
More file actions
42 lines (30 loc) · 717 Bytes
/
Copy pathArduino.ino
File metadata and controls
42 lines (30 loc) · 717 Bytes
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
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(3,2);
int trigPin = 4;
int echoPin = 5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
float duration, distance;
digitalWrite(trigPin, HIGH);
delay(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = ((float)(340 * duration) / 10000) / 2;
delay(1000);
if(BTSerial.available()){
Serial.write(BTSerial.read());
}
if(distance <30)
{
Serial.println(distance);
char data='a';
BTSerial.write(data);
}
}