Go Down

Topic: DigitalRead always gets me HIGH (Read 672 times) previous topic - next topic

vima

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?

Grumpy_Mike

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

vima

#2
Jan 20, 2013, 06:59 pm Last Edit: Jan 20, 2013, 07:10 pm by vima Reason: 1

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

Thanks man! That was it!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy