how to get correct counter

//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

from above program i fixed counter=10 but i get output at count 13.,
can any one resolve

post a schematic

schematic diagram

You only have OUTPUTs configured in Setup and you're doing digitalReads on pins that have been setup as outputs. Could that be a problem ? I've never tried that myself and this tutorial on digitalRead seems to suggest that a pin needs to be congifured as an INPUT to do a Read.

Hi, apart from what rashemmel has said, what do you expect to get from input 0, it the serial Rx pin, so it will be data stream from the Bluetooth.
If you are trying to measure the number of messages you receive from the Bluetooth, you will need to count the number of times

voice +=c;

occurs?

Can you edit your post and use code # tags to display your sketch, please.
Also an explanation of what you are trying to do overall will help us, you have all the info and we need it so we can give you answers that are going to help you in the quickest time.

I ASSUME you have a PC that sends via Bluetooth the characters "good morning", "hi world" then the arduino responds by configuring the output LEDs and/of the motor driver?

Tom.... :slight_smile:

I'm sorry but I am just not getting what the connection is between the schematic you posted and the code you posted.
Can you please walk me through the code and explain how the messages you are sending relate to anything on the hardware ?
If you had a conventional display like an LCD or VFD it would make sense but with only 4 leds I don't see how that is supposed to work.
Is there something you are not showing us ? Can you post a photo of your circuit so we can see what you are talking about ?