Why wont my UNO respons to a pulled down LOW input?

Hey Guys.

I am having a problem with a Pull-Down LOW input into my Arduino UNO which is weird cause I never had this problem before.
When I set it to react on HIGH it works fine.

Here is the Code.

//DigitalPins as INPUT-BUTTONS.
const int Button1 = 2;
const int Button2 = 3;
const int Button3 = 4;      
const int Button4 = 5;      
const int Button5 = 6;      
const int Button6 = 7;      

//AnalogPins as light ON/OFF.

const int Light1 = A0;
const int Light2 = A1;
const int Light3 = A2;
const int Light4 = A3;
const int Light5 = A4;
const int Light6 = A5;




int GlobalSelect = 0;

//Struct
struct Timer 
  {
    unsigned long InitialTimer;
    char Track;
  };

Timer ButtonDelay = {0,0};

int Light1State = 0, Light2State = 0, Light3State = 0, Light4State = 0, Light5State = 0, Light6State = 0;

//Setup

void setup()
  {
    //DigitalPins - Buttons
      pinMode(Button1, INPUT);
      pinMode(Button2, INPUT);
      pinMode(Button3, INPUT);
      pinMode(Button4, INPUT);
      pinMode(Button5, INPUT);
      pinMode(Button6, INPUT);
      
    //AnalogPins - Lights
      pinMode(Light1, OUTPUT);
      pinMode(Light2, OUTPUT);
      pinMode(Light3, OUTPUT);
      pinMode(Light4, OUTPUT);
      pinMode(Light5, OUTPUT);
      pinMode(Light6, OUTPUT);
  }
  
void loop()
  {
    ButtonReadProto();
    SwitchF(); 
  }
  
  void ButtonReadProto()
 {          
            int Button1R = digitalRead(Button1);
            int Button2R = digitalRead(Button2);
            int Button3R = digitalRead(Button3);
            int Button4R = digitalRead(Button4);
            int Button5R = digitalRead(Button5);
            int Button6R = digitalRead(Button6);     
   
         if (ButtonDelay.Track==0)
          {
          ButtonDelay.InitialTimer = millis();
          ButtonDelay.Track=1;
          }
          
           unsigned long curUni = millis();
            if(curUni - ButtonDelay.InitialTimer > 250) 
            {
              if (Button1R == LOW)
             {
               GlobalSelect = 1;
              
             }
             
              if (Button2R == LOW)
              {  
                GlobalSelect = 2;
              }
              
              if (Button3R == LOW)
              {
                GlobalSelect = 3;
              }
              
              if (Button4R == LOW)
              {
              
              }
              
              if (Button5R == LOW)
               {
               
               }
               
              if (Button6R == LOW)
               {
                 GlobalSelect = 6;
               } 
               
             ButtonDelay.Track=0;     
            }
            else
            {

            }    
 }

void Light1F()
  {
  
    //Light1State = StateChange(Light1State);
   // if (Light1State == 1)
      //{
        digitalWrite(Light1, HIGH);
        digitalWrite(Light2, HIGH);
        digitalWrite(Light3, HIGH);
        digitalWrite(Light4, HIGH);
        digitalWrite(Light5, HIGH);
        digitalWrite(Light6, HIGH);
      //}
  
      
    GlobalSelect = 0;
    
  }
  
  void Light2F()
  {
        
        digitalWrite(Light1, LOW);
        digitalWrite(Light2, HIGH);
        digitalWrite(Light3, LOW);
        digitalWrite(Light4, LOW);
        digitalWrite(Light5, LOW);
        digitalWrite(Light6, LOW);
        GlobalSelect = 0;
    
  }
  
  void Light3F()
  {
        
        digitalWrite(Light1, HIGH);
        digitalWrite(Light2, LOW);
        digitalWrite(Light3, LOW);
        digitalWrite(Light4, LOW);
        digitalWrite(Light5, LOW);
        digitalWrite(Light6, LOW); 
        GlobalSelect = 0;
    
  }
  
  void Light6F()
  {
    digitalWrite(Light1, LOW);
    digitalWrite(Light2, LOW);
    digitalWrite(Light3, LOW);
    digitalWrite(Light4, LOW);
    digitalWrite(Light5, LOW);
    digitalWrite(Light6, LOW);
    Light1State = 0;  
    GlobalSelect = 0;
    
  }
 
 /* 
 int StateChange(int c)
   {
     if (c == 1)
       {
         c = 0;
       }
      else if (c == 0)
       {
         c = 1;
       }
     
     return c;
   }
   */
   
   
   void SwitchF()
     {
       switch(GlobalSelect){
       case 1:
       {
         Light1F();
         break;
       }
       
       case 2:
       {
         
         Light2F();
         break;
       }
       
       case 3:
       {
         
         Light3F();
         break;
       }
       
       case 4:
       {
         
         GlobalSelect = 0;
         break;
       }
       
       case 5:
       {
         
         GlobalSelect = 0;
         break;
       }
       
       case 6:
       {
         Light6F();
         break;
       }
       
       }//SwitchState Exit
       
     }

How is the pin wired ?

ArdGuy:
I am having a problem with a Pull-Down LOW input into my Arduino UNO which is weird cause I never had this problem before.

What problem are you having?

You don't say if you external pullups on your buttons.
Try this to turn on the internal pullups and make sure you have a valid High state when your buttons that ground the pins are open.

      pinMode(Button1, INPUT);
digitalWrite(Button1, HIGH); // enable internal pullup
      pinMode(Button2, INPUT);
digitalWrite(Button2, HIGH); // enable internal pullup
      pinMode(Button3, INPUT);
digitalWrite(Button3, HIGH); // enable internal pullup
      pinMode(Button4, INPUT);
digitalWrite(Button4, HIGH); // enable internal pullup
      pinMode(Button5, INPUT);
digitalWrite(Button5, HIGH); // enable internal pullup
      pinMode(Button6, INPUT);
digitalWrite(Button6, HIGH); // enable internal pullup

or this if you have a later verion of the IDE

      pinMode(Button1, PULLUP);
      pinMode(Button2, PULLUP);
      pinMode(Button3, PULLUP);
      pinMode(Button4, PULLUP);
      pinMode(Button5, PULLUP);
      pinMode(Button6, PULLUP);

Actually:

or this if you have a later verion version => 1.0.3 of the IDE

 pinMode(Button1, INPUT_PULLUP);

pinMode(Button2, INPUT_PULLUP);
     pinMode(Button3, INPUT_PULLUP);
     pinMode(Button4, INPUT_PULLUP);
     pinMode(Button5, INPUT_PULLUP);
     pinMode(Button6, INPUT_PULLUP);

Thanks Lefty. I use the digitalWrite method myself, sure to work across different versions.

CrossRoads:
Thanks Lefty. I use the digitalWrite method myself, sure to work across different versions.

I do too. Also the newest pinMode command does do something a little different then in the past:

In the past a simple pinMode(pin#, INPUT) would switch the mode to input but would not do anything
to the existing output port that might be enabling or disabling the internal pullup for that pin, where as in the newest version that same command will explicitly disable the internal pull-up. May not sound like an issue but some have speculated that it could break some user's past code depending on how they might have been manipulating pinMode and enabling/disabling the pull-up.

Lefty

Hi Guys!

Thanks allot for the quick replies.

Well actually I have a the pull-down circuit as follows.

5V -- > 10Kohm --> PIN and from PIN -- > switch -- Ground.

Now I know this actually does pull the pin LOW cause I have tested the pin with my Multimeter.
But the Arduino doesnt seem to Respond when this happens
Could it be possible that I might have blown my PIN since I applied Clean 5V to it?
I am used to MicroChips and they can handle clean5V onto a pin.

What does the Internal PULLUP do though?

Why should I switch it on or off?

Thanks

ArdGuy:
Hi Guys!

Thanks allot for the quick replies.

Well actually I have a the pull-down circuit as follows.

5V -- > 10Kohm --> PIN and from PIN -- > switch -- Ground.

Now I know this actually does pull the pin LOW cause I have tested the pin with my Multimeter.
But the Arduino doesnt seem to Respond when this happens
Could it be possible that I might have blown my PIN since I applied Clean 5V to it?
I am used to MicroChips and they can handle clean5V onto a pin.

That's an external pull-up not a pull-down. The default input to the pin when the button is not being pushed is +5vdc, so the pin is said to be pulled up. When you push the button the switch grounds out the HIGH through the resistor and the pin reads as a LOW. You could do the same with out the external resistors just by enabling the internal pull-up resistors for the pins you are using with switches.

Lefty

The Internal Pullup helps to present valid High signal on the input pin when nothing is connected, like when your input switch is opened.
Vs having a signal that is just floating, not high, not low, just whatever.
It connects a 30-50K resistor from the pin to Vcc.

So If I make the internal pin HIGH could I simply ground it for a LOW?

Yes, exactly.
Your external pullup does the same, the switch just sinks more current.

ArdGuy:
So If I make the internal pin HIGH could I simply ground it for a LOW?

If you make the pin an input pin and then enable the internal pull-up resistor as CrossRoads showed you, then yes you simply have to ground out the input pin to read it as a LOW. But be aware that if you had by mistake set the pin to output mode and set the output HIGH and then grounded the pin it would create a short circuit and probably destroy the pin and maybe more. Be sure you understand pinMode fully before switching a ground to a pin.

Lefty

Pretty useful stuff !

Thanks guys.

About the Pull-Down Pull-UP...I never really got that :s

Can I use both your ways of setting these pins as INPUT - HIGHS?

Yes, either will work, depending on the version of IDE you have. INPUT_PULLUP only on later versions.
see the Arduino Release notes.

1.0.1 added the pinMode(pinX, INPUT_PULLUP); option.

Works pretty well!

Thanks Guys!