Problem is that when I press the button led is off and when button released led is on.
I measured Voltage on the digital pin when button is pressed and is 3.3v as expected.
What am I doing wrong???
Thx all
My Code is
const int buttonPin = 5; // the number of the pushbutton pin
const int ledPin = 16; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
That tutorial is not how you wire up a push button.
Wire it between the input and ground. Then enable the internal pull up resistor on the pin you are using for input.
Just had a minor argument over this at an Amateur Radio meet yesterday, but for this (different levels) and general safety (or "fail safe") reasons, it is bad design to connect signal buttons to the supply rail. Both the Arduino and the ESP8266 provide internal pull-up facilities so that buttons can simply be wired from an input to ground.