Let's Make Robots!

Multiple swithces to analog input?

Just had an idea. I'm planning to use a LOT of (tactile) switches on a walking robot. For instance I wanna put several under each foot. But it seems like a waste of pins to use a digital pin for each switch (or use multiplexers). So I thought I might be able to connect the switches in paralel and read several at a time from an analog input using resistors of different sizes connected in serial with each switch. Like this:

switches_s.jpg

Each combination should then output a unique voltage (according to my understanding).

Do you think this would work?

(sorry if this question seems silly/banal but I'm still quite a noob to this electronics mumbo jumbo :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

There are also so-called force sensing resistors available such as: http://www.trossenrobotics.com/c/robot-force-sensor-fsr.aspx Those particular ones seem to have a range from 1.5 psi to 150 psi. Anyway, those are just an example. I'm not meaning to push that particular type. Some place I have also seen a carbon-impregnated rubbery material you can buy that changes resistance with added pressure.

Something else I found interesting in concept, can be found at: http://www.soton.ac.uk/~rmc1/robotics/artactile.htm

Down that page I noticed this idea:

Seems fairly straight-forward to construct.  I have four small optical distance sensors that are good for short distances up to 1/4" max.  [Sorry, I forget where I got them(*), but Solarbotics has some similar http://www.solarbotics.com/products/35140/resources/ that are good for a range between 150 to 500 mils (3.8 to 12.5 mm).] I may play around with using them for touch sensors of this type. It could be good for my next project which is planned to be an animatronic creature that will need some sort of touch sensing.

Anyway, hope these ideas help.

Dan M

 

Addition:  I remember where I got the short-range sensors. It was Satistronics.com (China) and they cost $1.99 (US) a piece plus shipping.

Wikipedia gives a good reference on R-2R networks, that can be used in ADC reading of several switches, or just faking a DAC by using several of just 2 values of resistors. This would allow a more full swing of values over the range of the ADC reading, and more even spacing of those values. Examples seen use 10k and 20k resistors, but I might be inclined to use 1k and 2k values. 

Note what the Wikipedia article says about the tolerances of the resistors. On a lot of electronics, you may find a resistor pack in a Single Inline package (SIP) or Dual Inline Package (DIP) chip. The SIP packages will either have multiple resistors all with a common connection at one end or a set of individual resistors. I find SIP resistor networks on old modems boards and other electronics all the time.

I've never measured to see how close in value all the resistors in one network are. There are going to be different tolerances (5%, 2%, etc.) for resistor networks just like for discrete resistors. However, I would think a resistor network all manufactured in one package would have a good chance at being close in value. 

Good luck! 

A good point, you do have to be aware of the tolerance on resistor values, but fortunately it's easy to measure the larger resistors to within 1% with a properly calibrated multimeter. If you can't find accurate enough resistors you can always use less bits (or in this case fewer switches) connected to a single analog input, but instead use multiple sets of resistors tied to as many analog inputs as you need.

Note to self - don't reinvent the wheel.

I kinda like your setup better. It's simpler, more intuitive and uses fewer resistors...

And generally I think one SHOULD reinvent the wheel once in a while. Who knows.. one might actually make a better wheel :D

Thanks ;)

Like I said this electronics mumbo jumbo still surprises me somewhat. However when I was trying to figure out how to measure the current draw of my servos a while back I became aware that the ADC has a large (100K I believe) resistor build in. So in order to lead the current into the ADC rather than the ground where there is less (~no) resistance, I would need a resistor on the ground. So I came up with this. 

img005s.jpg

Knowing that the peak current draw of the servo was 750mA I calculated that I needed a ~6 Ohm resistor in order to get a full resolution reading on the ADC (5V / 0.75A = 6.666.. Ohm). It turned out 6 Ohm was too much for the servos, so now I'm using a 0.51 Ohm resistor which is large enough to get a useful reading and small enough not to bother my servos.

However I had this on my mind in this case too, but I thought it would be better just to lead all the current directly into the ADC. 

I still don't understand why the ground connection is necesary, but hey I believe you :)

Besides you said: "The current going into an analog pin is very, very low, so by V=I/R we can see that very little voltage will be dropped by the resistor"

I see why the larger resistors make sense to get larger current drops, but I don't see how your setup increases the current going into the ADC?

And you said: "if all the switches are open you'll get erratic readings since the input will be 'floating'". 

I get it. However wont that be the case in your setup too? And couldn't this be solved by adding a permanent resistor in paralel with the switches?

Anyway thanks a lot for the awesome reply. I'll be studying this and trying it out in the days to come :D

Virtually no current flows into an analog input because that would be a bad thing. The ADC would bias the incoming signal by drawing current, plus it would increase the current draw of the circuit. No doubt there are other problems it would cause also.

I chose larger resistors to limit the wasted current flowing through the bias resistor system. The lowest effective resistance from the parallel resistors will be 1.14kΩ, so adding that to the 2kΩ resistor we have a minimum resistance of 3.14kΩ. This means that, in the worst case, only 5V/3.14kΩ = 1.59mA is being consumed by the bias resistors. I could have chosen larger resistors to further reduce the current cost, but if you make them too large you'll make the circuit susceptible to noise problems.

Because the analog input is always connected to the ground via the 2kΩ resistor the output is never floating.

You really helped me to understand a thing or two there :)