-
Notifications
You must be signed in to change notification settings - Fork 16
/
arduino.ino
48 lines (38 loc) · 856 Bytes
/
arduino.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
/*
Any kind of data can be sent using the similar code.
Here, we are using an ultrasonic sensor and sending the data obtained by it.
Connections
Vcc- 5V
Gnd- Gnd
Trig-12
Echo-11
*/
#include<SoftwareSerial.h>
SoftwareSerial BTserial(0,1);
const int trigPin=12;
const int echoPin=11;
void setup() {
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(13,OUTPUT);
BTserial.begin(9600);
/* while(BTserial.available()==0)
{BTserial.print(5);
delay(2000);}*/
}
void loop() {
float duration,distance;
digitalWrite(trigPin,LOW);
delayMicroseconds(100);
digitalWrite(trigPin,LOW);
digitalWrite(trigPin,HIGH);
delayMicroseconds(5000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=duration/29/2;
if(BTserial.available()==0)
{BTserial.print(distance);
BTserial.print("\n");
delay(500);
}
}