Can anyone explai what is happening?

This code is just a test to find out what is happening o my main code.
Button is set on pin 5, pin 5 os set as INPUT.
LED is set on pin 13 (built in led) pin 13 is set as OUTPUT.

if(digitalRead(Button HIGH))
    {
        digitalWrite(LED, HIGH);
    }
    else
    {
        digitalWrite(LED, LOW);
    }

As shown on pic, pin 5 state is LOW and the led keeps always on, the led only turn off if i put LOW on pin 0 that is also tx pin.

Fatal syntax errors.

if(digitalRead(Button == HIGH))

and

if(digitalRead(Button HIGH))

Are both wrong.

I think you mean:

if(digitalRead(Button) == HIGH)

The circuit in post#1 is not inherently wrong, but there is a risk of short circuiting +5V and GND.
Advice: omit the +5V line and use the internal pull up resistor - pinMode(pin, INPUT_PULLUP) - simpler circuit AND less risk.
Mind that the value is inverted.

You don't need the connection to +5V, the internal pullup will pull pin 5 HIGH when the switch is open (OFF).

digitalWrite(LED, digitalRead(Button));

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

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