Question regarding inputs.

So, I've been figuring out my programming and everything is going well but I've run out of digital I/O points on my UNO.

My question, that I can't seem to find an answer to, is can you use an analog input simultaneously with a digital input?
On the surface the question seems simple but on the tutorials I've been watching they set the analog inputs the same way they do digital inputs, assigning them with just a pin number. So wouldn't the Arduino board get confuzzled with digital "1" and analog "1" if you set the input as "1"?

The reason I ask is I want to use an analog input as a switch input. Should work fine. That way I can use the digital I/O points as all outputs.

Sound right? Possible? Do I have to address the analog inputs as A0, A1, A2, etc?

The arduino knows which is which because of context.
I use pins 14, 15 and so in to address the analogue pins in a digital mode.

Grumpy_Mike:
The arduino knows which is which because of context.
I use pins 14, 15 and so in to address the analogue pins in a digital mode.

Can you expand on this?
Let's say I want to use digital 1 as an input (if pin1=HIGH) and analog 1 as an (faux digital) input (if analog1>0), how would I address those in the code so the arduino knows to expect a digital signal or an analog signal?

how would I address those in the code so the arduino knows to expect a digital signal or an analog signal?

It doesn't care. Use digitalRead() on an analogue pin and you will get back HIGH or LOW. To address the analogue pins with digitalRead you can either user the board pin numbers (14 - 18 on a Uno) or the aliases A0 to A4

UKHeliBob:

how would I address those in the code so the arduino knows to expect a digital signal or an analog signal?

It doesn't care. Use digitalRead() on an analogue pin and you will get back HIGH or LOW. To address the analogue pins with digitalRead you can either user the board pin numbers (14 - 18 on a Uno) or the aliases A0 to A4

Very useful information and will help a lot.

Just to be certain, though, I can use the line "#define BTN_01 A0" or "const int buttonPin = A0;"
OR, instead of "A0" I can use "14"?

Thanks again.

analog 1 as an (faux digital) input

No it is a real digital input. The processor pins can be switched between a real digital input or output and an analogue input. Using the pinMode function.
As I said if you want to use analogue input 0 as a real input just call it pin 14.

Cool. It works now. I had one wire that wasn't plugged in all the way on my breadboard. That's what was messing me up and causing confusion.

Hallo,

did I understand correct? You are running out of pins, due to push buttons?

http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)

In the shield that I bumped into recently four buttons are connected to a single analog pin.
The buttons are connected with voltage devider resistors, so that e.g. button 1 ->1V button 2 -> 2Volts. etc... -> there is also some example coding.

Maybe it is an additional option.

Greetings

If you want more inputs for buttons you could try charlyplexing them:-
http://forum.arduino.cc/index.php?topic=141978.0;topicseen

Bastelbude:
Hallo,

did I understand correct? You are running out of pins, due to push buttons?

Arduino_LCD_KeyPad_Shield__SKU__DFR0009_-DFRobot

In the shield that I bumped into recently four buttons are connected to a single analog pin.
The buttons are connected with voltage devider resistors, so that e.g. button 1 ->1V button 2 -> 2Volts. etc... -> there is also some example coding.

Maybe it is an additional option.

Greetings

Ah yes, I forgot that I could build a resistor ladder to make a few more buttons on the input.
The only problem with the resistor ladder is that when two, or three, buttons are pressed simultaneously the feedback level can venture into a different range.
I'd just have to be (very) careful with the range of the resistors.

I found out something else. On my UNO board, a 220K resistor is inadequate as a pull down resistor on pin zero and pin one. It works on all the other pins though.

That's where a LOT of my problems understanding this stuff came from. I was thinking my code must be wrong but it was purely hardware.

UGH, the learning curve.

I am not surprised that pins zero and one are different because they are connected to other circuits used for serial output not just the chip itself. Pin 13 may also be a problem because of its LED.

Is there a reason why you didn't enable the built in pullup resistors and thus remove the need for external resistors ?

Yes, there is a reason. I'm ignorant to there being internal resistors.

That's where a LOT of my problems understanding this stuff came from.

Then it behooves you to stop bragging about your IQ and get a bit of humility because every mistake you make in this game is your fault, that goes for everyone even me.

a 220K resistor is inadequate as a pull down resistor

Yes why on earth did you think it would be? Using TTL logic 300 ohms is about the limit. With CMOS then 10K should not be exceeded otherwise you erode the noise margin of your setup.

Grumpy_Mike:
Then it behooves you to stop bragging about your IQ and get a bit of humility because every mistake you make in this game is your fault, that goes for everyone even me.

Was that really necessary? Now I know why you call yourself Grumpy.

a 220K resistor is inadequate as a pull down resistor

Yes why on earth did you think it would be? Using TTL logic 300 ohms is about the limit. With CMOS then 10K should not be exceeded otherwise you erode the noise margin of your setup.
[/quote]
Why did I think it would be? Just simplistic thinking.
As I said, this is a hobby project. Something to occupy my time and mind during the dreary days. It's not a life ambition and, as thus, it's a learning experience.
Not knowing how sensitive these boards are, a bit of my experiences will be hit and miss.

It's like I told my son when my grandson was learning to walk. "Look, he's going to fall down a few times. Accept it". And, like my grandson, I'm learning each time I fall.

Bittsen:
Yes, there is a reason. I'm ignorant to there being internal resistors.

See pinMode() - Arduino Reference
pinMode(pinNum, INPUT_PULLUP);turns on the internal pullup resistor for the pin. Using them can tidy up project wiring quite a bit and they are guaranteed to be a suitable value.

Was that really necessary?

I could ask you the same thing is that tag really necessary?

You are looking here? Really? Why? Nothing important here... OK, so about me. I am not a programmer, I'm not an electronics engineer. I am a hobbyist. I like to get involved in all kinds of things. I'm actually considered a genius, with a high IQ (160+

like my grandson, I'm learning each time I fall.

Good that is exactly the attitude we like around here, which is why the IQ boast sits so ill and is a bit provocative.

If you want more information about inputs then have a read of this page I put up.
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Grumpy_Mike:

Was that really necessary?

I could ask you the same thing is that tag really necessary?

You are looking here? Really? Why? Nothing important here... OK, so about me. I am not a programmer, I'm not an electronics engineer. I am a hobbyist. I like to get involved in all kinds of things. I'm actually considered a genius, with a high IQ (160+

like my grandson, I'm learning each time I fall.

Good that is exactly the attitude we like around here, which is why the IQ boast sits so ill and is a bit provocative.

If you want more information about inputs then have a read of this page I put up.
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Hey, the IQ thing isn't a boast. It's a humbling statement. Why? Simple... it shows that just because someone has a high IQ, doesn't mean they can't learn from others. Maybe I could write the "about me" part better. It was done at 1AM after staring at code for a few hours. I've been running on less than six hours of sleep each night trying to live my life, learn Arduino, and working like a sole mule in a 1800's gold mine.

Sorry if I offended you.
Wait, I'm not sorry if you were offended as I didn't "try" to offend you. If I wanted to offend you, I would and you'd know it was supposed to offend.

I do appreciate the help I'm getting here. I really mean that.
No matter my IQ, I always feel like a child when I learn something new.

So, have you ever had your IQ measured?

UKHeliBob:

Bittsen:
Yes, there is a reason. I'm ignorant to there being internal resistors.

See pinMode() - Arduino Reference
pinMode(pinNum, INPUT_PULLUP);turns on the internal pullup resistor for the pin. Using them can tidy up project wiring quite a bit and they are guaranteed to be a suitable value.

I'm going to look into this as I just spent 45 minutes chasing a ghost.
I changed out the 220K resistor on pin 0 and pin 1 with 10K resistors and still can't use them both as inputs.

I had 220K on pin 0 as an input and it was working last night. I added an input on pin 1 today with a 220K and then started having problems. (Of course I didn't realize there was an issue til I updated the code I was working on so I thought it was a code issue).

At any rate, I can use pin 1 as an input now but not pin 0. No matter the resistor size or even if there's anything connected to it at all. It acts like there's a button turned on once I assign it.

Pins 0 and 1 are connected to the serial lines used to communicate with the computer through the USB port. So even without anything connected you have another device holding the RX pin high. This is connected through a 1K resistor to protect that device in case you happen to connect something else to it. Therefore for these two pins 10K is way too high if you want to use them as a normal input. Even if you put a 1K pull down that would give you 2.5V on that pin which is just about on the threshold of a zero / one. You need to go way lower say 300R to reliably pull this down. In general pull ups are preferred to pull downs.