Set "Alarm ON" and "Alarm OFF" with Terminal Widget

Hello everyone!
I’ve got a problem with my project. I’m creating a smart house with arduino MKR1000, using Blynk app. I’ve put PIR sensor, and I’ve connected this sensor to a piezo: when PIR is high, the piezo is on, and everything works.
I’d like also to set this “alarm” on and off using the Terminal widget, but I don’t know how to set the code. Can someone help me?

This is the code I set, but it compiles but it’s not working D: the alarm keeps going, even if I set “Alarm OFF”…

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>

int piezoPir;
int pirValue;

WidgetTerminal terminal(V3);

char auth[] = “Token”;

char ssid[] = “Network”;
char pass[] = “password”;

BLYNK_READ(V1) {

Blynk.virtualWrite(V1,piezoPir);
}

BLYNK_WRITE(V3)
{

if (String(“Alarm ON”) == param.asStr()) {
terminal.println(“Alarm is now ON.”);
void loop ();
}
if (String(“Alarm OFF”) == param.asStr()) {

piezoPir=0;
terminal.println(“Alarm is now OFF.”);
}
else if (String(“Alarm OFF”) != param.asStr() && String(“Alarm ON”) !=param.asStr()) {

terminal.print("Unkown command. Please type again.");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();

}

terminal.flush();
}

void setup() {
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);
terminal.println(F(“Alarm System”));
terminal.println(F("-------------"));
terminal.println(F(“Type ‘Alarm ON’ to turn on the alarm;”));
terminal.println(F(“type ‘Alarm OFF’ to turn off the alarm.”));
terminal.flush();
}

void loop() {
Blynk.run();

pirValue=analogRead(A1);
piezoPir=pirValue;
}

Thanks in advance and sorry about my english, I’m italian.

Please read the welcome message and format your pasted code:

You have a void loop() in your BLYNK_WRITE(V3) which is probably one of your problems.

When putting this in your main loop the pin is read many thousands of times each second:

pirValue=analogRead(A1);
piezoPir=pirValue;

Personally, I find no reason for such a high reading frequency and in a small sketch it might not even be a problem combined with Blynk. But Blynk favors the use of Timers to keep the main loop as clean as possible. If you search the forum you’ll find some examples of how others have implemented the use of PIR’s.

Good luck!