Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: vima on Jan 20, 2013, 06:34 pm

Title: DigitalRead always gets me HIGH
Post by: vima on Jan 20, 2013, 06:34 pm
Hello I am using this simple code that I have used so many times before:

Code: [Select]
const int buttonSwitchA=9;

void setup()
{
Serial.begin (57600);
pinMode(buttonSwitchA, INPUT);
}

void loop()
{
  buttonStateA=digitalRead(buttonSwitchA);
  if (buttonStateA==HIGH) {
    Serial.println("printing");
    delay(1000);
  }
}


I have a switch in my breadboard. One pin is in the 5V and the other is my "free" pin. My switch works fine because I checked with  using a voltometer, when i press the switch and measured voltage the free pin. (basiccally i do not know how to explain this but I used that mode when there is path, you hear the beep sound. When switch is pressed sound is heard, otherwise not).

So my switch works.

When i plug in the free pin in the arduino input 9, it always read HIGH and prints the message. I tried wit other inputs but still nothing.

Is it a problem of code or what should I checked?
Title: Re: DigitalRead always gets me HIGH
Post by: Grumpy_Mike on Jan 20, 2013, 06:37 pm
You can not leave a pin unconnected, you need a pull up or pull down.
Please read:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html (http://www.thebox.myzen.co.uk/Tutorial/Inputs.html)
Title: Re: DigitalRead always gets me HIGH
Post by: vima on Jan 20, 2013, 06:59 pm

You can not leave a pin unconnected, you need a pull up or pull down.
Please read:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html (http://www.thebox.myzen.co.uk/Tutorial/Inputs.html)

Thanks man! That was it!