Analog vs Digital Pins with an Uno

Hi

I’m sorry if my questions are a little lame, I’m new to Arduino and electronics in general.

I have a project that reads 4 air pressure sensors, performs some calculations and displays the values on 4 x seven digit displays.
To complete the project, I want to include a 6 position rotary switch so I can select different algorithms that the code can apply to the Analogue values coming from the sensors.

The way I thought of doing this is to connect 5v to the rotary switch with a single output and a set of resistors so that Ii would get varying voltage depending on the selector rotary switch position.

I was going to use one of the Arduino Analogue pins to check the voltage to determine which position the selector is at.
Problem is that I have used up all 6 analogue inputs.

I guess I could use one of the free digital pins and use an analogue to digital converter but I don’t have a lot of space to be adding more boards.

My question is ….
Most of the digital pins are free so can I wire up 6 selector outputs to 6 digital pins and just check in the code which pin is on or off?
I assume the digital pins handle 5 volts directly to them?

Is there another way of doing this using one Digital pin?

Thanks in advance
Sam

Most of the digital pins are free so can I wire up 6 selector outputs to 6 digital pins and just check in the code which pin is on or off?
[Yes]

I assume the digital pins handle 5 volts directly to them?
[Yes]

Is there another way of doing this using one Digital pin?
[Maybe. Need 2 to have software I2C to read an ADC, need 3/4 to perform SPI read of an ADC, or a shift-in register, need 3 pins to select 1 of 8 pins to read from a multiplexer/analog switch.
If you have SPI in place already for other functions, then its just 1 pin more as chip select to another device (ADC, shift-in register).
ADC, shift-in register is 1 chip plus a 0.1uF Vcc decoupling cap.]

Hi Crossroad

Thanks for your response.

For now I think I will go with the Digital pins, I guess it’s much simpler.
The alternative would no doubt have me tearing my hair out. :slight_smile:
Sam

Hi
Further to my previous post,
I may have misunderstood something but I thought I could use pins D2,D3 & D4 to detect when 5 volts was applied to either of them.

So if I put a wire from 5v on the Arduino to either Pins D2,D3 or D4, I expected to get a ‘0’ or ‘1’ when reading that pin.

It sort of works,
i.e. if I run a wire from 5v to D2 , digitalRead returns ‘1’, but it I move the wire to D3, they both continue to show ‘1’ even after I have removed the wire to D2.

I must be totally missing how these digital reads work

Following is the code
//
//
void setup()
{
Serial.begin(9600); //Start serial communication at 9600 for debug statements
Serial.println("------");
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
}
//=============================================================
//
//=============================================================
void loop()
{
Serial.print(digitalRead(2));
Serial.print(digitalRead(3));
Serial.print(digitalRead(4));
delay(200);
}

I must be totally missing how these digital reads work

Read this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
You need to wire the digital inputs correctly.

Make this change

void setup() 
{
  Serial.begin(9600); //Start serial communication at 9600 for debug statements
  Serial.println("------");
  pinMode(2, INPUT);   
digitalWrite(2, HIGH); // enable internal pullup
  pinMode(3, INPUT);   
digitalWrite(3, HIGH); // enable internal pullup
  pinMode(4, INPUT);      
digitalWrite(4, HIGH); // enable internal pullup
}

Then connect pins 2,3,4 to Gnd - will read low
When not connected to Gnd - will read high.
Without the internal pullup, the pins will "float" as discussed in Grumpy_Mike's webpage, with unpredictable results.