Hello,
For some time now i am trying to make a smart door lock, but i have some problems with the sketch. I am using a HM10 for the bluetooth connection and 2 end switches for the detection of the key inside the lock. I have wired a 10k ressistor between the swtiches and the arduino. I have made a simple sketch for the Arduino. The problem is that the lock isn't reliable, the bluetooth part is working but when i send something by bluetooth and after that i press one of the end switches it is supposed to go to a angle but the motor doesn't react on the switches. When i erase the bluetooth part in the sketch and i upload only the switch part it works but when it is combined the lock doesn't react on the switches anymore.
This is the sketch that i made:
#include <Servo.h>
const int buttonPin = 2;
const int buttonPin1 = 7;
int buttonState = 0;
Servo servo;
int tx=1;
int rx=0;
char inSerial[15];
void setup() {
Serial.begin(9600);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin, INPUT);
pinMode(tx, OUTPUT);
pinMode(rx, INPUT);
servo.attach(13);
}
void loop() {
int i=0;
int m=0;
delay(500);
if (Serial.available() > 0) {
while (Serial.available() > 0) {
inSerial[i]=Serial.read();
i++;
}
inSerial[i]='\0';
Check_Protocol(inSerial);
}
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
servo.write(0);
}
buttonState = digitalRead(buttonPin1);
if (buttonState == HIGH) {
servo.write(120);
}
}
void Check_Protocol(char inStr[]){
int i=0;
int m=0;
Serial.println(inStr);
if(!strcmp(inStr,"open")){
servo.write(0);
Serial.println("Servo 0");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
if(!strcmp(inStr,"close")){
servo.write(120);
Serial.println("Servo 120");
for(m=0;m<11;m++){
inStr[m]=0;}
i=0;}
else{
for(m=0;m<11;m++){
inStr[m]=0;
}
i=0;
}}
What has to be changed to let it work with the bluetooth module and the switches?