//Voice password protected safety room using android and bluetooth
String voice;
const int
signal1 = 2, //Connect signal 1 To Pin #2
signal2 = 3, //Connect signal 2 To Pin #3
signal3 = 4, //Connect signal 3 To Pin #4
signal4 = 10, //Connect signal 4 To Pin #10
signal5 = 6, //Connect signal 5 To Pin #6
signal6 = 7, //connect signal 6 To pin #7
signal7 = 8, //connect signal 7 to pin #8
signal8 = 9; //connect signal 8 to pin #9
int
counter=0,
count=10;
//--------------------------Call A Function-------------------------------//
//-----------------------------------------------------------------------//
void setup() {
Serial.begin(9600);
pinMode(signal1, OUTPUT);
pinMode(signal2, OUTPUT);
pinMode(signal3, OUTPUT);
pinMode(signal4, OUTPUT);
pinMode(signal5, OUTPUT);
pinMode(signal6, OUTPUT);
pinMode(signal7, OUTPUT);
pinMode(signal8, OUTPUT);
}
//-----------------------------------------------------------------------//
void loop() {
while (Serial.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = Serial.read(); //Conduct a serial read
if (c == '#') {
break;
} //Exit the loop when the # is detected after the word
voice += c; //Shorthand for voice = voice + c
}
if (voice.length() > 0) {
Serial.println(voice);
if(voice == "*hi world") {
digitalWrite(signal1, HIGH);
}
if(voice == "*good morning") {
digitalWrite(signal2, HIGH);
}
if(voice == "*no password") {
digitalWrite(signal3, HIGH);
}
if(voice == "*open the door") {
digitalWrite(signal4, HIGH);
}
if(voice == "*close") {
digitalWrite(signal5, HIGH);
delay(3000);
digitalWrite(signal5,LOW);
}
if((digitalRead(signal1) == HIGH && digitalRead(signal2) == HIGH) && (digitalRead(signal3) == HIGH && digitalRead(signal4) == HIGH))
{
digitalWrite(signal7,HIGH);
delay(3000);
digitalWrite(signal7, LOW);
digitalWrite(signal1, LOW);
digitalWrite(signal2, LOW);
digitalWrite(signal3, LOW);
digitalWrite(signal4, LOW);
}
if(digitalRead(counter)!=digitalRead(count))
{
count ++;
if(digitalRead(counter)==digitalRead(count))
{
digitalWrite(signal6,HIGH);
delay(10);
}
}
digitalWrite(signal8,HIGH);
delay(1000);
digitalWrite(signal8,LOW);
//-----------------------------------------------------------------------//
voice="";
}
} //Reset the variable after initiating