HI i am new on blynk app i have a magnetic door switch connected to a wemos d1 esp 8266 monitoring on the print screen the on off status normally open normally closed .How can i monitor this status thru blynk application i will appreciate if someone could help me . Here is the code that i use. I know after reading blynk forum that is have to do with BLYNK_WRITE() if (param.asInt()) but i don’t know how to put this in my code. Thank you!
#define BLYNK_PRINT Serial
const int buttonPin = D3;
const int ledPin = BUILTIN_LED;
int buttonState = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
// set initial state, LED off
digitalWrite(ledPin, buttonState);
}
void loop() {
// read button state, HIGH when pressed, LOW when not
buttonState = digitalRead(buttonPin);
// if the push button pressed, switch on the LED
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // LED on
Serial.println("ON");
} else {
digitalWrite(ledPin, LOW); // LED off
Serial.println("OFF");
}
}
This will send a HIGH or LOW signal to the blynk app at the virtual port V2. So if you put a button on the virtual port V2 and set it as push the app will show if it’s On or Off.
The param.asInt() you mentioned before would be used in case you want to control the motor from the app. Something like this:
Just a reminder. This will show you if it is closing or opening. To check if it’s closed already you need some sensor to detect when it’s closed and than you use the same logic to detect the sensor state.