Using Digital pins as Analog Inputs?

Hi,
Im building an Arduino (Uno) based Robot Platform and im running out of pins on my Arduino.
Looking back I should of got a Mega, but i didn't think id run out of pins.

As my Motor Shield uses A0, A1 for current sensing,
I also have 2 Pots hooked up to A2, A3, and a few I2C Devices aswell (A4, A5).
I want to add a Parallax Ping sensor but ive got no analog Inputs left.
But ive got 5 Spare Digital Pins.

I know you can use analog pins as digital pins aswell. (D14, D15, D16, D17, D18, D19)
But can you do the same with Digital pins as Analog Inputs?

,Thanks In Advance
Alex :slight_smile:

No, you can't. If you could, they would be labelled as analogue pins. Only the analogue pins are connected to the A/D circuit.

You could sacrifice some of your excess digital pins to drive an external analogue mux.

Thanks for the replys,

Are Mux's Straight Foreward to work with?
And how many digital pins am i going to sacrifice?

how many digital pins am i going to sacrifice?

You will use n pins where two to the power n is the number of analogue inputs you will get.
Look at this project for an example of this:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html

Ok it looks pretty straight foreward i think ill use one of them.
Thanks :slight_smile:

Or you could ditch the pots and use rotary encoders instead - although the inexpensive rotary encoders only tell you how much they have moved, instead of telling your their absolute position like a pot does.

Don't Rotary Encoders still use analog inputs?

No, a standard quadrature rotary encoder uses 2 digital inputs. When using several of them, you can use multiplexing to reduce the total number of pins you need.

Thanks, I just Googled them and found a tutorial, they are a simple (and cheap) solution.

Yes but they are continuous rotation, there is no end stop. Normally when you use them in this situation you have some form of level indicator like a display.

I want to add a Parallax Ping sensor

Ping sensors connect to a digital pin.

Actually, you can use digital pins as analog pins. See: How to use photocells, LDRs, CdS cells, photoresistors! and scroll all the way down.

Yes but the point is that it is slow and rubbish.

For about $20 you could build yourself a ATMega1284 duemilanove style board.
32 IO pins, 16K SRAM, 128K FLASH PROM, 4K EEPROM, 2 hardware UARTs.
I have bare boards for $4.50 (see my signature link), you supply the parts, designed to be easily assembled. Can be all new, or use what you have on hand.
core files from maniacbug are downloaded from here

Another option: add an 8-channel SPI controlled ADC chip to your design.

Control it with the 4 SPI pins (SCK, MOSI, MISO, SS), obtain higher resolution results, and free up your digital IO pins.

Actually, you can use digital pins as analog pins.

Not really. That's still a digital switch. It's the same as using pulseIn() on an ultrasonic sensor.

Thanks guys for all your input,
It has really helped in the design of my project.

CrossRoads:
For about $20 you could build yourself a ATMega1284 duemilanove style board.

I Don't think i have the soldering skills to make this yet (as im 14 and new to electronics), but i will consider it.

Grumpy_Mike:
Yes but the point is that it is slow and rubbish.

Aeryck:
Actually, you can use digital pins as analog pins. See: How to use photocells, LDRs, CdS cells, photoresistors! and scroll all the way down.

dxw00d:
Ping sensors connect to a digital pin.

I thought these were Analog Sensors, Sorry.

Grumpy_Mike:
Yes but they are continuous rotation, there is no end stop. Normally when you use them in this situation you have some form of level indicator like a display.

I am just going to use Normal Pots on the Platform, But i will use a Rotary Enoder For scrolling through an LCD (that displays sensor data from the robot) on my controller.

clungzta:
Thanks, I just Googled them and found a tutorial, they are a simple (and cheap) solution.

I don't know which one you found, but some of what's written about rotary encoders is either overkill or doesn't work well. You can find the code I use to read them at Five things I never use in Arduino projects | David Crocker's Solutions blog.

dc42:
I don't know which one you found, but some of what's written about rotary encoders is either overkill or doesn't work well. You can find the code I use to read them at Five things I never use in Arduino projects | David Crocker's Solutions blog.

For the LCD scrolling it doesent have to be acurate it just has to move it up the pages and down using a for loop.
Or i could Just use a rotary switch and a for loop.