I am trying to connect Key Button Module with NodeMCU. The key button module has 3 PINs - VCC, OUT and GND. I connected VCC to 3V3, GND to GND and OUT to D2 of nodemcu. Button purchased here - https://robu.in/product/red-electronic-building-blocks-big-key-button-module-high-level-output/
I have written a small program to blink LED ON/OFF on pressing and releasing a button.
int buttonPin = D2;
int val;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(D4, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(buttonPin);
if (val == LOW) {
Serial.println(val);
int count = 0;
digitalWrite(D4, LOW);
} else {
digitalWrite(D4, HIGH);
}
}
When I press and release the button, LED is not blinking. I am not sure what is going wrong in this simple example. Appreciate any help.
Thanks.