-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voice_Controlled_Extension_Box.ino
64 lines (51 loc) · 1.17 KB
/
Voice_Controlled_Extension_Box.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
59
60
61
62
63
64
#include <SoftwareSerial.h>
SoftwareSerial BT(0, 1); //TX, RX respetively
String readvoice;
void setup() {
BT.begin(9600);
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
}
//-----------------------------------------------------------------------//
void loop() {
while (BT.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = BT.read(); //Conduct a serial read
readvoice += c;
}
if (readvoice.length() > 0) {
Serial.println(readvoice);
if(readvoice == "both switch on")
{
digitalWrite(3, LOW);
digitalWrite (4, LOW);
delay(100);
}
else if(readvoice == "both switch off")
{
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
delay(100);
}
else if (readvoice == "first switch on")
{
digitalWrite (3, LOW);
delay (100);
}
else if ( readvoice == "second switch on")
{
digitalWrite (4, LOW);
delay(100);
}
else if (readvoice == "first switch off")
{
digitalWrite (3, HIGH );
delay (100);
}
else if (readvoice == "second switch off")
{
digitalWrite (4, HIGH);
delay (100);
}
readvoice="";}} //Reset the variable