Pages: [1] 2   Go Down
Author Topic: Why wont my UNO respons to a pulled down LOW input?  (Read 672 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

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
       
     }

Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3453
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the pin wired ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11154
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
      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
Code:
      pinMode(Button1, PULLUP);
      pinMode(Button2, PULLUP);
      pinMode(Button3, PULLUP);
      pinMode(Button4, PULLUP);
      pinMode(Button5, PULLUP);
      pinMode(Button6, PULLUP);
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16499
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually:

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

    
Code:
pinMode(Button1, INPUT_PULLUP);
      pinMode(Button2, INPUT_PULLUP);
      pinMode(Button3, INPUT_PULLUP);
      pinMode(Button4, INPUT_PULLUP);
      pinMode(Button5, INPUT_PULLUP);
      pinMode(Button6, INPUT_PULLUP);


Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16499
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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.
Logged

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

What does the Internal PULLUP do though?

Why should I switch it on or off?

Thanks
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16499
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16499
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Pretty useful stuff !

Thanks guys.

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

Pages: [1] 2   Go Up
Jump to: