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.