Hello. Im new to Arduino and Im currently working on my first projekt (in Tinkercad) which is a door lock system. Programing was going smoothly so far but now im stuck on a problem. As my last part of the projekt I added a button which was meant to be on the other side of of the door and when pressed it was suppose to open the door just as it would with the correct password from the other side. Im not sure whether its the code or the conections that is the problem. Im able to run the code but when I press the button nothing changes.
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#define Password_Length 5
Servo servo1;
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
int buzzerPin = 12;
const int buttonPin = 8;
int buttonState = 0;
char Data[Password_Length];
char Pass[Password_Length] = "1111";
byte data_count = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3};
byte colPins[COLS] = {4, 5, 6, 7};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
servo1.attach(9);
servo1.write(0);
lcd.begin(16, 2);
lcd.print("door locked");
lcd.clear();
pinMode(10, OUTPUT);
pinMode(11,OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
Open();
if (buttonState == HIGH){
void Button();
}
}
void Button(){
servo1.write(90);
lcd.print("door open");
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(5000);
lcd.clear();
lcd.print("door locked");
noTone(buzzerPin);
delay(1000);
servo1.write(0);
}
void clearData() {
while (data_count != 0) {
Data[data_count--] = 0;
}
}
void deleteChar() {
if (data_count > 0) {
data_count--;
Data[data_count] = 0;
lcd.setCursor(data_count, 1);
lcd.print(' ');
}
}
void Open() {
lcd.setCursor(0, 0);
lcd.print("enter password");
digitalWrite(10, LOW);
digitalWrite(11, LOW);
noTone(buzzerPin);
customKey = customKeypad.getKey();
if (customKey) {
if (customKey == '#') {
deleteChar();
} else {
Data[data_count] = customKey;
lcd.setCursor(data_count, 1);
lcd.print(Data[data_count]);
data_count++;
tone(buzzerPin, 440);
delay(500);
}
}
if (data_count == Password_Length - 1) {
if (!strcmp(Data, Pass)) {
lcd.clear();
servo1.write(90);
lcd.print("door open");
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
tone(buzzerPin, 440);
delay(5000);
lcd.clear();
lcd.print("door locked");
noTone(buzzerPin);
delay(1000);
servo1.write(0);
}
else {
lcd.clear();
lcd.print("incorrect password");
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
noTone(buzzerPin);
delay(2000);
}
delay(1000);
lcd.clear();
clearData();
}
}