problem with Digital Read Serial

im new to arduino !! i setup the digital read circuit as shown in tutorials ! the TX led is always on even if i didnt push the button !!! i also tried making an LED light if when some push button is pressed ! but also it acts like the button is always pressed !!

in another way when i configure a pin to be an INPUT it always reads HIGH without doing anything to it !!

is my UNO board defective ??

Can you post your code and tell us how your circuit is wired? It sounds like you have a floating input.

i used exactly the code from examples menu !! also i wired the circuit as shown in here with exactly the same resistance !

for the other circuit i used a code just like that !

int button = 2; int led = 12;

void setup() { pinMode(led,OUTPUT); pinMode(button,INPUT); }

void loop()

if (digitalRead(button)==HIGH) { digitalWrite(led,HIGH); delay(5000); } else { digitalWrite(led,LOW); }

your code misses some {} the code below should reflect the state of the button Do you have an external pullup/pulldown resistor connected to the button?

The leds should instantaneous follow the button

int button = 2;
int led = 12;

int state
void setup()
  pinMode(led, OUTPUT);
  pinMode(button, INPUT);

void loop()
  if (digitalRead(button)==HIGH)
    digitalWrite(led, HIGH);

Maybe the switch is wired wrong - try rotating the switch 90 degrees.

still not working guys .. i tell u what exactly happening now !! i upload code to board ... i connect LED with pin 12 and GND ........ then when i just approach my finger to pin 2 without even touching the black insulation .. THE LED LIGHTS UP !!!!!!!! im going crazy guys !!

else im not connecting any external power source ... just the usb cable !!!!

another question is there any difference between the 3 GND pins on the Arduino Board !

You have a floating input. The behaviour you describe is entirely normal, which is why resistors are used to pull up or pull down inputs.

Is there something wrong with your punctuation keys?

i see now .

i think its my mistake now !!

sry about punctiation.

can u please explain in very short word what is the function of pull up or pull down resistors ! and how to choose their values ! ?

The input pins have very high impedance, and will pick up junk from just about source, as you have found.

The input logic can't then easily decide if the pin is high or low, which is why it is called floating.

If you connect it via a resistor to either the supply or the ground, then the pin is tied high or low, but a short circuit (like a closed switch) will defeat the pull up or pull down. Typical values are 10k ohms and up.

When you close the switch in the circuit shown on the tutorial page, you take the pin to 5v, agree?

But what if the switch is open? When the switch is open, just because the pin's not high, doesn't mean it's low... could be any value, so it needs to be forced, and that's what the resistor does, takes the pin low. When the switch is closed, the connection to 5v (with no resistance) is much "firmer" than the connection through the resistor to ground, so 5v wins that little battle.

(You can't just connect the pin to low with no resistance for the times the switch is open though, because then when you do close the switch, you'll short 5v to 0v and boom.)

Thank u alot Brother :) u 've been very helpful to me :)

will get to u with another big question soon ! :)

mtf011: will get to u with another big question soon ! :)

Yay! Looking forward to that.... :roll_eyes: