-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBT Test Lock Arduino
87 lines (75 loc) · 2.42 KB
/
BT Test Lock Arduino
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 2 //sheild has pin BT_RX set to 7
#define TxD 3 //shield has pin BT_TX set to 6
#define lockPin 13 //pin we want to blink the led on
#define ledOn 1
#define ledOff 0
SoftwareSerial blueToothSerial(RxD,TxD);
void setup(){
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(lockPin, OUTPUT);
pinMode(ledOn, OUTPUT);
pinMode(ledOff,OUTPUT);
digitalWrite(ledOn, LOW);
digitalWrite(ledOff, LOW);
setupBlueToothConnection();
}
void loop(){
char recvChar;
if(blueToothSerial.available()){//check if there any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
}
if(Serial.available()){//Check if there any data sent from the local serial terminal
recvChar = Serial.read();
blueToothSerial.print(recvChar);
}
switch(recvChar){
case '1':
LockOn();
blueToothSerial.println("DOOR IS LOCKED");
break;
case '0':
LockOff();
blueToothSerial.println("DOOR IS UNLCOKED");
break;
}
/*if(recvChar=='a'){
LedOn();
}
if(recvChar=='b'){
LedOff();
}*/
}
void LockOn(){
digitalWrite(lockPin, HIGH);
digitalWrite(ledOn, HIGH);
digitalWrite(ledOff, LOW);
//delay(500);
}
void LockOff(){
digitalWrite(lockPin, LOW);
digitalWrite(ledOn, LOW);
digitalWrite(ledOff, HIGH);
//delay(500);
}
void setupBlueToothConnection(){
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBT\r\n"); //set the bluetooth name as "SeeedBT"
blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
//blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
Serial.println("2 seconds passed");
//char recstatus;
//blueToothSerial.print("\r\n+RTSTA:XX\r\n");
// recstatus = blueToothSerial.read();
//Serial.print(recstatus);
blueToothSerial.flush();
}