My Arduino ESP8266 Wemos D1 Mini is Trigger by itself without pressing the button in D5 on my board, and if i power up on my computer works fine for a couples of hours after that than trigger by itself.
Also if i power up on a phone charger works fine for a couples of hours, some days trigger by itself.
I am using a resistor 10K with the 3v3 with ground connect to a button.
I am using for get a message on my telegram with BOTFATHER
#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#define BOT_TOKEN "" // your Bot Token (Get from Botfather)
#define CHAT_ID "" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)
#define BOT_TOKEN2 ""
#define CHAT_ID2 ""
#define BOT_TOKEN3 ""
#define CHAT_ID3 ""
#define TELEGRAM_BUTTON_PIN D5
WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);
UniversalTelegramBot bot2(BOT_TOKEN2, client);
UniversalTelegramBot bot3(BOT_TOKEN3, client);
String ipAddress = "";
volatile bool telegramButtonPressedFlag = false;
void ICACHE_RAM_ATTR test(){
}
void setup() {
Serial.begin(9600);
client.setInsecure();
// Initlaze the buttons
pinMode(TELEGRAM_BUTTON_PIN, INPUT);
attachInterrupt(TELEGRAM_BUTTON_PIN, test, RISING);
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
ipAddress = ip.toString();
}
void telegramButtonPressed() {
int button = digitalRead(TELEGRAM_BUTTON_PIN);
if (button == HIGH)
{
telegramButtonPressedFlag = true;
}
return;
}
void sendTelegramMessage() {
bot.sendMessage(CHAT_ID, "I am at the door!");
bot2.sendMessage(CHAT_ID2, "I am at the door!");
bot3.sendMessage(CHAT_ID3, "Answer the door!");
telegramButtonPressedFlag = false;
}
void loop() {
telegramButtonPressed();
if (telegramButtonPressedFlag) {
sendTelegramMessage();
}
}
Maybe it's a wiring issue, Normally a button is connected to a GPIO pin using a Pullup resistor rather than the pull-down that you are using.
Also there is a pinMode available for that that uses the internal pullup resistors
pinMode(TELEGRAM_BUTTON_PIN, INPUT_PULLUP);
and of course now we test for
if (button == LOW)
{
telegramButtonPressedFlag = true;
}
That is the right method, mind you, your callback function is empty, and the function that actually does do the work is being called repeatedly. You can remove the whole interrupt part of your code.
I just want to receive a message on my Telegram app, by pressing a simple button to know that somebody is at the door, while i am listening to music on my headphone.
I am not using a breadboard, i soldered the pins that came with it, also i tried a 1k resistor it does not worked.
Just like i said, When i power up with the cable USB in my notebook works for a couples of hours after that triggers by itself, and when i use a charger connected to the 5v and ground it triggers forever!