Button draw issues

When I am using four buttons as configured in this tutorial:

I find that using three or four buttons just draws too much out of my arduino.

Any ideas how to have buttons that use logic highs? I've been through trying to do that before and it was extremely difficult.

I tried using smaller resistors (currently 330 ohm) but more than two still don't work.

Would using LEDs work instead? I am really stuck on this one.

Perhaps a power supply for my arduino would remedy this issue, but I find that excessive.

SO I am really just wondering - how am I supposed to use more than two buttons :frowning:

Thanks

Use large resistors - 1k to 10k. You don't need much current to detect a closed switch.

Even better, skip the external pullup resistor altogether, and use the ATmega's internal pullup (which is enabled bit writing a 1 to the pin after it has been set as an input).

-j

I tried using 1k, 10k and then setting the inputs to 1 initially.

None of these worked... couldn't even make one button work with the 10k resistors :frowning:

The setup detects the logic LOW -- so I think that running four at once is too much. Even with the large resistors :frowning: I still just get strange errors with the other resistor setups with just one button.

Any thoughts?

Worked like a charm with the 300 ohm resistors with a single / double button. Anything more and there would be complete loss of functionality.

Ack!

Just as a self-suggestion.. I think I will try to reverse the logic so that the buttons only draw when closed.

Therefore they will not 'all draw' during no press.

Like I said - the button setup is identical to the example, which detects logic LOWs.

Anyone think this could solve the issue? :o

Hi,
One thought, the pins can have dual use.
Digital IO pins 0 and 1 are connected to the USB serial via 1k, that can be a reason you needed low values of the resistors and 10k did not work.

Look at the schematic and use some IO-ports that are not connected to anything.

Magnus

Ok - so I just reversed all of the logic.

Now I have four buttons that 'work' but I think they are still 'using' too much power...

Any thoughts?

Would powering the arduino off AC rather than USB remedy this issue?

I think they are still 'using' too much power...
Any thoughts?

Got any evidence to support that theory?

I'll say it again, for low power consumption and the simplest circuit, just use the internal pullups.

Button logic is often inverted, because it frequently works out the easiest to pull the line up to Vcc. Just deal with it in software. On occasion I have even created #defines for ENABLED and DISABLED to save myself confusion with active low signals (especially on a system that has active low peripherals and active high peripherals). e.g.:

#define BUTTON_DOWN 0
#define BUTTON_UP 1
#define BUTTON 2
....
setup()
{
  pinMode(BUTTON, INPUT);
  digitalWrite(BUTTON, 1); // enable pullup
}

loop()
{
  if (digitalRead(BUTTON) == BUTTON_DOWN)
  {
     // do something interesting
  }
}

-j

Oh wow, I was doing the internal pullup initialization incorrectly.

Thanks for the clarification - am going to give this a shot.

I was just basing it off.. my own suspicions! Why would 2 work, but not 3 or 4.

Thanks for the help though - excuse my foolishness :frowning:

<- embarassed :-[

A reply to the last post - of code..

When using the internal pullup - you do not need to use any physical resistors with the switches right?

I can just vcc -> to button -> to input pin...?

Is that correct?

Thanks :slight_smile:

pinMode(inputPin, INPUT);
digitalWrite(inputPin, HIGH);

Ground -> button -> inputPin.

If you push the button, LOW is seen on the input.

If you don't push the button, HIGH is seen on the input.

Ok - So I tried that setup and things did not work :frowning:

Here is the init code I have

void setup() {
  pinMode(ledPin, OUTPUT); 
  
  
  pinMode(upPin, INPUT);
  pinMode(downPin, INPUT);  
  pinMode(leftPin, INPUT);
  pinMode(rightPin, INPUT);
  
  digitalWrite(upPin, HIGH);
  digitalWrite(downPin, HIGH);
  digitalWrite(leftPin, HIGH);
  digitalWrite(rightPin, HIGH);
  
  xservo.attach(10);
  yservo.attach(9);

  xaxis = 0;
  yaxis = 0;
}

Then for code within my loop:

void loop(){
  up = digitalRead(upPin);
  down = digitalRead(downPin);
  left = digitalRead(leftPin);
  right = digitalRead(rightPin);
  
  
  //begin right
  if (right == LOW) {   


....


if (left == LOW) {

.... etc. etc. etc.
etc. etc.

The buttons do not respond.. and my test LED on board is pretty dim.. instead of bright orange.. any ideas?

What else is connected to the arduino? Are the switched wired pin -> switch and switch -> ground, as indicated earlier?

-j