Arduino Bluetooth receive message and unlock/lock door using servo motor

Hi, I am new to Arduino programming…I am doing a project using Arduino and HC 06 Bluetooth Module to receive message from a mobile application. I would like to add an unlock/lock door feature using servo motor. Meanwhile, if the user type 0, the door is locked and type 1 to unlock the door…If user type other message except than 0 and 1, the LCD will show the message. I am using a LCD as well. So far I have done these 2 parts in seperate sketch…BUT I face problem when combining both sketches…Any help please? Thanks.

The first code below is unlock/lock door coding while second is receive message coding:

[#include <Servo.h>
Servo myservo;
int pos = 0;
int state; int flag=0;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
myservo.write(60);
delay(1000); }
void loop()
{
while(Serial.available())
{
state = Serial.read();
flag=0;
} // if the state is ‘0’ the DC motor will turn off
if (state == ‘0’)
{
myservo.write(8);
delay(1000);
Serial.println(“Door Locked”);
}
else if (state == ‘1’)
{
myservo.write(55);
delay(1000);
Serial.println(“Door UnLocked”);
}
}]

[#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); //LCD Pin position
String readString;
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
lcd.print(“Check message from Bluetooth”);
delay(200);
}

void loop() {
while(Serial.available()){
delay(3);
char c = Serial.read();
readString += c;
}
if(readString.length()>0){
lcd.clear();
Serial.println(readString);
lcd.print(“Receiving…”);
delay(500);
lcd.clear();
lcd.print(readString);

}
readString="";
// delay(200);
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(300);
}

}]

BUT I face problem when combining both sketches

You did not post your attempt at combining the sketches, OR describe what the resulting program actually does or how that differs from what you expect. Hard to help that way.

This is the code when I was trying to combine both of them. But when I connected my programmed arduino to power source, it seems like it keeps receiving data…I know the problem occurs at the receiving data part, but I am enable to solve it…Any help will be appreciated. Sorry for my poor programming skill…

#include <Servo.h>
Servo myservo;
int pos = 0;
int state; int flag=0;

#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); //LCD Pin position
//#include <SoftwareSerial.h>
//SoftwareSerial BTSerial(5,6);
String readString;

void setup()
{
myservo.attach(9);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print(“Check msg from”);
myservo.write(60);
delay(1000); }

void loop() {
while(Serial.available())
{
state = Serial.read();
char c = Serial.read();
readString += c;
flag=0;
}
if (state == ‘0’)
{
myservo.write(8);
delay(1000);
Serial.println(“Door Locked”);
}
else if (state == ‘1’)
{
myservo.write(55);
delay(1000);
Serial.println(“Door UnLocked”);
}
else{
lcd.clear();
Serial.println(readString);
lcd.print(“Receiving…”);
delay(500);
lcd.clear();
lcd.print(readString);

}
}

I have edited my code…Now it is able to unlock and lock when I type 0 or 1. However, if I type other message, the lcd will show onl some character of the message…(not full message). Help me please. Thanks

#include <Servo.h>
Servo myservo;
int pos = 0;
char state; int flag=0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5); //LCD Pin position
//#include <SoftwareSerial.h>
//SoftwareSerial BTSerial(5,6);
String readString;

void setup() {
myservo.attach(9);
Serial.begin(9600);
lcd.begin(16,2);
myservo.write(60);
lcd.print(“Check message from Bluetooth”);

delay(1000);
}

void loop()
{
while(Serial.available())
{
state = Serial.read();
char c=Serial.read();
flag=0;
readString += c;
} // if the state is ‘0’ the DC motor will turn off
if (state == ‘0’)
{
myservo.write(8);
delay(1000);
Serial.println(“Door Locked”);
//Serial.println(readString);
}
else if (state == ‘1’)
{
myservo.write(55);
delay(1000);
Serial.println(“Door UnLocked”);
}
else if (readString.length()>0)
{
lcd.clear();
Serial.println(“Receiving…”);
delay(500);
lcd.clear();
lcd.print(readString);
//readString ="";
}
readString ="";
}

while(Serial.available())
{
state = Serial.read();
char c=Serial.read();
flag=0;
readString += c;
}     // if the state is '0' the DC motor will turn off

Read one character, and store it in state. Read the next character, and store it in c and append it to the String instance.

Of course you are not going to get anything like a complete message.

Tyraigeeycaatradsoigte l in the String.