ESP-01 having difficulty with just one input
Posted: Wed Feb 05, 2020 4:29 pm
Hi, I hope someone would be able to show me the way. I have an ESP-01 with two inputs. Basically, I want to monitor a intruder alarm for set and unset. The connection to the esp is with a spdt relay contact. The esp would look at the state of this input and then forward to Blynk on my phone to the status of the alarm. I have this code working but its not consistent. It has two inputs GPIO0 and GPIO2 to give me the status. As I said, I only want one GPIO to do this but its just not reliable. Could anyone help me before I pull out the last remaining hair that I have!
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth Token : ***********************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "**************";
int flag1 = 0;
int flag2 = 0;
void notifyOnButtonPress1()
{
int isButtonPressed1 = digitalRead(0);
if (isButtonPressed1 == 1 && flag1 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now set and he has gone to bed");
flag1 = 1;
}
else if (isButtonPressed1 == 0)
{
flag1 = 0;
}
}
void notifyOnButtonPress2()
{
int isButtonPressed2 = digitalRead(2);
if (isButtonPressed2 == 1 && flag2 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now unset");
flag2 = 1;
}
else if (isButtonPressed2 == 0)
{
flag2 = 0;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup notification button on pin 0
pinMode(0, INPUT_PULLUP);
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
timer.setInterval(16000L, notifyOnButtonPress1);
timer.setInterval(16000L, notifyOnButtonPress2);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
Alistair
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Auth Token : ***********************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "**************";
int flag1 = 0;
int flag2 = 0;
void notifyOnButtonPress1()
{
int isButtonPressed1 = digitalRead(0);
if (isButtonPressed1 == 1 && flag1 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now set and he has gone to bed");
flag1 = 1;
}
else if (isButtonPressed1 == 0)
{
flag1 = 0;
}
}
void notifyOnButtonPress2()
{
int isButtonPressed2 = digitalRead(2);
if (isButtonPressed2 == 1 && flag2 == 0) {
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Dad's alarm is now unset");
flag2 = 1;
}
else if (isButtonPressed2 == 0)
{
flag2 = 0;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup notification button on pin 0
pinMode(0, INPUT_PULLUP);
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
timer.setInterval(16000L, notifyOnButtonPress1);
timer.setInterval(16000L, notifyOnButtonPress2);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
Alistair