Blynk iot overide sensor

Hello Blynk Team
i am working on alarm project and i am using a magnetic sensor for door when the door is open the buzzer will HIGH, So now i want to override (bypass) the sensor using Botton, example once Button is on the sensor pin is need to disable.

i hope you hear me soon

Best Regard
Maaz

#define BLYNK_DEVICE_NAME           "Device"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
#define USE_WROVER_BOARD
//#define USE_TTGO_T7

#include "BlynkEdgent.h"
bool alarm_mode = false ;
int ZONE1 = 32;
int buzzer = 22;
int botton = 2;
BlynkTimer timer;
void myTimerEvent(){
  if(digitalRead(ZONE1) ==0){
    Blynk.virtualWrite(V1,"CLOSE");
    
  }
  if(digitalRead(ZONE1) ==1){
    Blynk.virtualWrite(V1,"OPEN");
    if(alarm_mode == true){
      digitalWrite(buzzer, HIGH);
     }
  }
}
BLYNK_WRITE(V2)
{
  if ( param.asInt () == 1)    // <------ ZONE 2 BYPASS
{
  digitalWrite(32,HIGH);
}
  else
  {
    digitalWrite(32,LOW);
  }
}
void setup()
{
  pinMode(ZONE1,INPUT_PULLUP);
  pinMode (botton,OUTPUT);
  pinMode (buzzer,OUTPUT);
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();
  timer.run();
  Blynk.run();
}

When you post code to the forum, the triple backticks need to be on a line of their own - otherwise the first line of your sketch disappears.

You should give some thought to trying to make your code more efficient. For example, this function…

requires two digital.reads to be performed. As the result of the first digital.read can only be 1 or 0 then it makes more sense to use an else rather than the second if.

In this function…

You have hard-coded 32 into your sketch, rather than using the ZONE1 variable that you’ve defined earlier.
In addition, I’m not sure what you’re hoping to achieve with this function, but whatever it is it don’t work the way you’re hoping.

I’d suggest that you use a Boolean variable as a flag. Maybe call it something like Zone1_Override’. Set it to true(1) if you want the sensor to be ignored, then test this flag variable at the beginning of yourmyTimerEventfunction and of it’struethen do nothing. If it’sfalsethen read the value of theZONE1` pin.

EDITED TO ADD…

This should NOT be in your void loop if you’re using Edgent.

Pete.

thanks for Reply sir
sir can you please help me to send the example code i try my best allready sir but i cant do it

Maaz

I’m not going to write your code for you.

Pete.

ok thank you sir no problem i will try again

thank you sir

Maaz