I'm looking to set up a series of steps that when you step on them, the computer processes some data and reacts differently depending on which step you make contact with. Several of the Arduino products list analog and digital pins. I'm looking to have these steps connected to a pair of wires that when contact is made, the wires will touch. I then want the computer to know they touched. Would I need to use analog of digital? Or could I use either or both?
There are several possibilities of realizing this.
If you used an analog pin and you have 6 steps you could use 1V/step and detect the voltage with an analogRead(). So 0V is step 1, 1V step 2, .. 5V step 6. You'd only need one pin to do this.
If you cannot produce different voltage levels you could use a pin for each step and detect if there is HIGH or LOW voltage (around 5V / 0V) and depending on how many digital pins have a high level at the input calculate the current step.
In scenario one, is it possible to have two on at the same time? It would seem that if step one and two are on, then it would read it at 3V and would think the 3rd step is being touched. Am I right?
jcase16:
In scenario one, is it possible to have two on at the same time? It would seem that if step one and two are on, then it would read it at 3V and would think the 3rd step is being touched. Am I right?
No that is not possible. 3V could mean step 4 or step 3 and step 1.
If you want to short a connection (connect two wires) then i'd recommend using separate digital ports anyway, you can use 5V on one wire and connect the other part to a digital input pin. If the wire is connected the digitalRead() will show 1 and you know that step is active. You can do this for each step and also see if more than one step is active.
digital pin 1 -> step 1: active when digitalRead(1) == 1
digital pin 2 -> step 2: active when digitalRead(2) == 1
..
Awesome, so digital pins make the most sense. Any recommendations on which hardware to use assuming I want somewhere between 40 and 60 separate digital pins?
I don't understand why I would need those products of yours or why they would help. I'm expecting my wire for each step to go into on of the Mega's pins and then hooking up the Mega to the computer through USB. The computer will always be on. Then I expect that I would put the ground and the 5V to a bread board which would have a separate wire to complete each pair and each of these wires will be connected to a step as well. So each step will have one wire going to the Mega pin and one going to the breadboard to get voltage. Does this sounds correct? Assuming it is correct, how do those two recommended products help me?
I would trade some software to dramatically reduce the pin needs.
If you set up a matrix and scan
for the inputs all you need is 16 pins to handle 64 inputs.
You could do this on a standard arduino and still have a few
extra pins left over for analog or digital uses for other things.
To do this you set up an 8x8 matrix.
8 pins for the rows 8 pins for the columns.
Each input switch connects a column to a row.
You then scan row by row column by column
and look for the inputs.
Yes you have to deal with the multiple switches pressed cases,
but that is fairly easy to handle in software.
If you only needed 40 inputs then the pin needs reduces to only 13 pins
as you would have something like 7 columns and 6 rows for a total of 42 inputs.
You could reduce the pin count down even further if you used resistor ladder networks
on multiple analog inputs.
(Similar to the first suggestion but using multiple analog inputs)
In this case rather than a NxM matrix you have a multiple input switches
using a single analog input on N analog inputs each with its own ladder network.
So you could cut it down to probably as small as 3-4 analog pins if you pick your resistor values
carefully.
Each switch would return a given analog value on a give analog pin.
But to do this, you have to guarantee that only a single switch on a given analog pin
is used. If you will never have more than 2 switches pressed at time
(because the person is never standing on more than two steps at the same time) this is not a big
deal to handle in the wiring by just ensuring that adjacent steps don't share
the same analog pin for the switch inputs.