Pages: [1]   Go Down
Author Topic: DigitalRead always gets me HIGH  (Read 561 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I am using this simple code that I have used so many times before:

Code:
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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: January 20, 2013, 01:10:39 pm by vima » Logged

Pages: [1]   Go Up
Jump to: