Reading the state of DIP-switches via 4017. Something escapes me...

Dear all,
I apologize for a question that shows my incompetence as well as my arrogance - I engage in projects that I deem easy but obviously are not in my grasp.

To make things worse, my English leaves much to desire… :slight_smile:

I’m using Arduino with three 4017 IC to scan sequentially three packages of 4 DIP switches.

My aim is to understand which switches are in the “ON” position and which are in the “OFF” position. To that purpose, I use a common “output” line for all the DIP packages. By powering one switch at a time, I should read a non-zero voltage for every switch closed.

Attached please find the circuit.

Two things puzzle me.

  1. As soon as I close switch 4 in the rightmost or in the leftmost 4-switches DIP package, I begin to get random readings in all the values (the reading of every switch - including the open ones! - is different from zero) - but this does not apply when I close switch 4 on bank 2 (see photo of the board and a screenshot of correct serial output, showing the sequential readings from left to right that I get with the configuration shown in the picture).
    It’s not a matter of a defect in the DIP switch pachage, I substituted them with other similar new items, and the error persists. I’m almost sure that there is something very obvious that escapes me, please accept my apologies for asking you to state the obvious.

  2. (Very obviously), even though I power each 4017 individually, the more switches I close (ON position), the lower voltage I read. This tension drop is a consequence of the number of “rivulets” that I open by closing each switch. I wonder which is the easiest way to get an higher tension that would make open/close discrimination safer (currently I think that a threshold of “above 10/1024th” may be taken as “switch closed” and any analog reading below 10 as “switch open”). By “the easiest way” I mean the simplest breadboardable circuit, with the fewest components.

Thanks for your help and again, excuse my clumsiness.

Cesare Brizio
briziocesare@gmail.com

dip_switch_scanner.ino (3.35 KB)

Is this a similar chip to the one you are using ? http://www.ti.com/lit/ds/symlink/cd4017b.pdf

It appears to be a decade counter and the switch which you say causes instability appears to short an IC output to ground.

For determining the position of banks of switches without using up too many arduino pins, a multiplexer chip (say 4051) or 8 to 3 encoder (say CD4532B) would be a more usual choice.

Edit.
I've just now seen that you are using the lower ground rail on the breadboard for another purpose so my comment above may not apply.

Thank you 6v6gt, if a solution does not emerge, I’ll seriuously consider trying with the chips that you suggested, that I already have employed in other contexts.
Again thank you and all the best,
Cesare

The 4017 is not an “open drain” chip, which means that when you have more that one switch closed, you’ll be connecting a +5 output to a gnd output, which is not a good thing. You could probably fix it with a bunch of diode, or since you’re using an analog input, perhaps some carefully chosen resistors, in series with each switch/4017 connection…

Thank you westfw, I supposed that the 220 kOhm resistor that lays where the common line from the switches reaches the ground output (immediately after the point where I read the tension) would avoid direct contact between the switches / the 4017 and the ground.
I'll try to refactor the breadboard, perhaps I'll need two breadboards.
Again thank you for your advice.
Cesare