using digital pins and "pull up" and "pull down" resisters

I am new to my Arduino Uno and am a little fuzzy on the pin voltages and use of "pull up" and "pull down" resisters. I might be thinking wrong but what I am trying to do is attach a couple of switches to the digital pins and modify the "blink" sketch to check the switches (input) and based on which switches are closed select a value to use in the delay(XXXX) portion of the loop. It is my understanding that during the delay the Arduino does nothing but is it safe to change the switches under power? I will be using a DIP switch to select 4 different pins either HIGH or LOW and using the resulting binary combinations to give me 16 selectable values for the delay(). The delay will be from 2 to 32 MINUTES so it will be unlikely to be in middle of switching when board checks the switch settings, but what I am worried about it do I need to remove power/hold reset button when changing the DIP positions?

Am I correct in understanding that the position of the resister determines if pull-down or pull-up and it can be either with the same components. I don't know how to make image here but if:
5V->N/O switch->pin2 set as input->10K resister->GND --- resister here is pull down
5V->10K resister->pin2 set as input->N/O switch->GND --- resister here is pull up
only difference is if check for HIGH or LOW on pin2 correct so far??
and since there is no real difference between a closed DIP switch and a N/O switch with a finger pushing on it continuously or open DIP switch and a N/O switch released, IF is safe to swich under power I can test the sketch with 4 pushbuttons and short delay values first . Just don't want to hurt the board if not safe to do this under power.

Thansk,
dmac257

what I am worried about it do I need to remove power/hold reset button when changing the DIP positions?

Nothing to be worried about. You can change DIP switch positions at any time.

V->10K resister->pin2 set as input->N/O switch->GND --- resister here is pull up

This is the most common, mostly because the Arduino microcontroller has built-in pullup resistors that can be enabled so you don't even need the external resistor. Make sure "V" in your hookup is 5V and not some arbitrary voltage.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

V->10K resister->pin2 set as input->N/O switch->GND --- resister here is pull up

This is the most common, mostly because the Arduino microcontroller has built-in pullup resistors that can be enabled so you don't even need the external resistor. Make sure "V" in your hookup is 5V and not some arbitrary voltage.

In my origional question I had the 5V and will be using the 5V socket on the UNO as source. How do you "enable" the built-in pullup resistors inside the 328? For now I will use the 10K resister but would be nice not to have the extra components.

dmac257

The built-in pullup resistors are enabled by configuring pins as inputs then writing them high as if they were outputs:

pinMode(10, INPUT); // Or whatever pin...doesn't have to be 10...
digitalWrite(10, HIGH);  // Pin 10 now has a pullup resistor enabled

--
The Aussie Shield: breakout all 28 pins to quick-connect terminals

not to thread hijack, but I have a question about pull down resistance. What are the drawbacks/dangers to having a low pull down, say 1k? I don't think I can use pull ups 'cause my switches have diodes in front of them... mm while I'm at it, how much resistance could a poor solder joint add :slight_smile:

hope you're enjoying the arduino so far dmac!

What are the drawbacks/dangers to having a low pull down, say 1k? I don't think I can use pull ups 'cause my switches have diodes in front of them...

There is no fundemental advantage/disadvantage of pull-ups Vs pull-down, it's just whatever is easier to interface what your wiring to. Diodes in from of switches? You have a link to that? If so just wire the switch in the opposite direction?

mm while I'm at it, how much resistance could a poor solder joint add

It can vary anywhere to 'not enough to notice' to 'hey there is no current conduction through that path'. And it can change with the weather and board movement, etc.

Lefty

retrolefty:
There is no fundemental advantage/disadvantage of pull-ups Vs pull-down, it's just whatever is easier to interface what your wiring to.

I'm just wondering if it's a bad idea to have a 1k pulldown, because the tutorials I've read mention 10k as the norm, and I think one said to have them between 4.7k and 100k.

You have a link to that?

it's just a keyboard matrix, same idea as http://highlyliquid.com/blog/up/keyboard-matrix.jpg
I'm using a board from an old casio and I don't want to re-solder 48 diodes unless I really have to :slight_smile:

How does this work? You have pins pulled up with resistors, going thru diodes & a switch to other pins which are floating - so closing the switch may bring them high, but what will take them low?
Is there something I am missing?

i think that one must be the inverse of mine— http://i52.tinypic.com/2s5xoqc.png
The select pins are outputs and only one is high at a time

Ok, so you drive the 4051 ABC to 000, press button 1L (top left), that puts 5V from 4051-X0 to D13, otherwise R above pulls it low.
Pressing 1R at the same time has no effect as the diode keeps D13 from seeing the the state of 4051-X1 (presumably floating, with not enough current in the high state to drive D13 to a high).

Then you drive ABC to 001, press button 1R, that puts 5V to D13, but since you know ABC=001, it is a different keypress than 1L.

So you are time coordinating the key readings with the state of the 4051 ABC.

I would say 1K is good, you will just need to make sure the power supply can provide (5V/1K = 5mA)* the max number of keys you plan to have pressed at any one time: 10 fingers = 50mA?

alrighty! I've been having some weird behaviour if I don't put a slight delay in the code after setting the ABC pins, though. Basically pressing down 1L will send high to D13 no matter what the mux is doing, which is frustrating. Lowering the resistance of the pull downs shortens the necessary delay, but too low and none of the higher keys will register. I ended up with 1k on pin 13, going up to 76k on pin 6. All in all I really have no clue what's going on, but I hope it will perform better when I make the pcb (you don't want to see what I did to the fine-pitch ribbon cable to get it into my breadboard).

btw I made a topic about this project: http://arduino.cc/forum/index.php/topic,57177.0.html ... really didn't mean to hijack!