State Change Detection

Hello friends,

i want to count how many time push button pressed, for this i used state change detection of example in arduino IDE softeare with my nodemcu. i just change input pin number , on uploading when i press push button i show well as coded " on push button press 1" but when i press second time push button it not counting and showing on serial monitor.
any one can help me what is the problem..
please see attached file..

Please post your code, your expectations and observations.

The circuit that accompanies the tutorial includes a pull down resistor: does yours?

no, i do not use pull down resister. actually i use with nodemcu. i directly apply pushbutton . is it necessary to use pull down resistor?

Asif138:
is it necessary to use pull down resistor?

If you don't there's no guarantee that the pin is low when the button isn't pressed, and if it's not, then pressing the button won't cause a transition.

(I'm not saying the lack of resistor is your problem necessarily, but it ought to have one, and putting one in removes one possible cause of the problem.)

Thanks, it was due to not using pull down resister, after using resister it is working fine.

Thanks,

It's unnecessary to use external resistors. Almost all microcontrollers have built-in pull-up resistors.*

Enable it by using pinMode(pin, INPUT_PULLUP), and connect your switch between the IO pin and ground.

(*) The ESP8266 has a pull-down resistor on GPIO 16.

Pieter