Hello!
I am relatively new to arduino and am trying to make a simple door notification system. I have a magnetic switch hooked up to my arduino as well as an LCD screen. When the door becomes open the sensor detects so and sends my phone an alert and when it is closed it continues to scan the sensor. This all works the problem comes in when I try to have it print to the LCD screen that the door is opened or closed, the loop completely stops running and stops checking the door sensor. If you could help me out that would be great! Below is the code I have so far.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Bridge.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleYun.h>
#include <Keypad.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*******";
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Bridge.begin();
Blynk.begin(auth);
// make the pushbutton's pin an input:
pinMode(pushButton, 2);
}
void loop() {
// the loop routine runs over and over again forever:
// read the input pin:
int buttonState = digitalRead(pushButton);
Blynk.run();
// print out the state of the button:
Serial.println(buttonState);
if (buttonState > 0) {
Blynk.notify("Door Opened!");
lcd.init();
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Door Opened!");
delay (5000);
}
else{
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Door Closed");
}
}