ESP8266 Wemos D1 Mini

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();
    }
    
}

I am using a resistor 10K with the 3v3 with ground connect to a button.

Can you please attach a simple sketch of how you have the button switch wired?

I am using just one button in D5 pin

You are setting up the interrupt in the wrong way. check this to show you that you should use

digitalPinToInterrupt()

But then again, you don't use the interrupt as such, since you 'poll' the function within loop(), so i suggest you comment out this line

// attachInterrupt(TELEGRAM_BUTTON_PIN, test, RISING);

I put this

digitalPinToInterrupt(TELEGRAM_BUTTON_PIN)

And comment this line

// attachInterrupt(TELEGRAM_BUTTON_PIN, test, RISING);

it continues triggering by itself again.

i tried this too:

attachInterrupt(digitalPinToInterrupt(TELEGRAM_BUTTON_PIN), test, RISING);

but continues triggering byitself

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.

Still triggering by itself :pensive:

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.

That can be done for sure, but let's focus on the basics.

I would try a stronger pull down resistor. Perhaps 2.2K instead of 10K.

You could also try and convert from a breadboard circuit to something on soldered perf board incase there is something flakey in the connections.

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!

May be in need of a capacitor (0.1uF from the input/sw pin to Ground).

PE - that's what it took here (see last 4, 5 posts)
Wemos D1 clone: digitalRead is unreliable - Using Arduino / General Electronics - Arduino Forum
"We" used a stronger Pull-up, but the caps set things right. I would have asked that he try with the added pull-ups removed, but left "well-enough" alone.

1 Like

Where i connect a capacitor 0.1uF D5 with GND?
if so, i keep the resistor?

So i put a capacitor 0.1uF instead a resistor 10K?

One end to D5 and the other to GND (leave everything else the same).

1 Like

OK, i will try that, thanks!

I put a capacitor 0.1uF = 104 capacitor, One end to D5 and the other to GND (and leave everything else the same). In my case on pin D5.
CC-0.1UF

You have to put this capacitor with the resistor.
Thank you very very much to @runaway_pancake !!!!!!!!!!!!!!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.