112 switches need reading

I have 112 switches that output a 0 or 5 volts. I need a way to send this to an Arduino, MEGA2560 , by the serial port, using some CMOS logic or? so that I can tell which switches have changed state. Normal condition is that all 112 are HI=5 volts. Ideas please. The Arduino and the switches are about 5 feet apart but in a noisy environment.
thanks

A 10x12 (120) matrix and a 14x8 (112) matrix would both take up 22 pins, but the 10x12 would have room for adding more switches later! ( :

themotorman:
I have 112 switches that output a 0 or 5 volts. I need a way to send this to an Arduino, MEGA2560 , by the serial port, using some CMOS logic or? so that I can tell which switches have changed state. Normal condition is that all 112 are HI=5 volts. Ideas please. The Arduino and the switches are about 5 feet apart but in a noisy environment.
thanks

Well you state the switches already have a 0 or +5vdc signal value. Scanning 112 'dry contact' switches is pretty straight forward in simple 2D matrix scan using 22 arduino I/O pins, however if the switches already have a 'foreign' voltage (no free 'dry contacts') wired to them then it's not possible as the arduino has to be able to activate voltage on one dimension of the matrix to then read back the other dimension to tell is a specific switch is closed or not. So what are the switches now controlling and or wired too?

So assuming the switches are performing some electrical function already and you just want to 'monitor' their output states, then you probably need to use lots external logic chips like input shift registers (parallel in/serial out) or digital encoder chips (say lots of 16 in /1 out mux chips. It will not be a low parts count application that is for sure.

Lefty

THey are as you described external and I don't have any way to connect to the Arduino except as a serial line. I am hoping someone will have some idea of what CMOS logic chips might do the job. I realize that this is not a simple problem but I am willing to build the PCB to put the chips on it. Just haven't worked with CMOS for some time and need some help with the CMOS family, decoders, etc... also need to take the logic output and have a way to read the data. I did think that a way would be to use 2 MEGAs, since that would give me enough inpins and then send the data from these to the remote ARduino via the serial line. Although not cheap it it seems that it might be the simplest... Opins?

How many will be LOW at any one time? Just a few or potentially many?

themotorman:
THey are as you described external and I don't have any way to connect to the Arduino except as a serial line. I am hoping someone will have some idea of what CMOS logic chips might do the job. I realize that this is not a simple problem but I am willing to build the PCB to put the chips on it. Just haven't worked with CMOS for some time and need some help with the CMOS family, decoders, etc... also need to take the logic output and have a way to read the data. I did think that a way would be to use 2 MEGAs, since that would give me enough inpins and then send the data from these to the remote ARduino via the serial line. Although not cheap it it seems that it might be the simplest... Opins?

Well before you start designing something one really needs to understand the circuitry the existing switching is wired in. There are questions like is there a common ground used in the existing wiring and connection available for any new logic or arduino additions. Are the voltage states always defined electrically, or is there a 'floating input pin' possible problem to be aware of? I would not start the effort or expense of such a project without a compete electrical schematic of what you are working with. At least that is my advice.

Lefty

Seven CD4067 mutiplexers, driven by a binary counter which is clocked and reset by the arduino, or directly from 11 pins of the arduino, with one input back from the multiplexers.

thanks for the advice. I suddenly realized that I can arrange the 112 as a 7 x16 array , read it with an Arduino and send the data to the main Mega... I am sure that the code to read an array is in a library... anyone know where I could look for this? The switches are all fully floating so making them as an array is simple.
thanks

try keypad.h

themotorman:
I suddenly realized that I can arrange the 112 as a 7 x16 array...

That's 23 pins.

.

have to use a mega

themotorman:
thanks for the advice. I suddenly realized that I can arrange the 112 as a 7 x16 array , read it with an Arduino and send the data to the main Mega... I am sure that the code to read an array is in a library... anyone know where I could look for this? The switches are all fully floating so making them as an array is simple.
thanks

The switches are all fully floating

What does that mean? Does it mean there are no existing wires and voltages on the switches? If there is, there is a problem reading them in a classic arduino driven matrix method.

You failed to understand my first post on this issue. You can only use an arduino to scan the switches in a matrix setup, and read the switches if there is no external voltage already on the switch terminals. Scanning a switch matrix involves the arduino setting an output pin high (+5vdc) on only one of the 'Y' matrix lines and then reading all the 'X' inputs, one at a time, via arduino analog input pins. It then sets that 'Y' line to input mode and outputs a +5vdc on the next 'Y' matrix line and then again reads all the 'X' matrix lines, lather, rinse, repeat for all the 'Y' lines then start all over.

If there already is external voltages (ground or +5vdc) on the switch terminals, the arduino will read back false values for the switches. So unless you replace all 112 switches with DPST switches and use one set of contacts for the arduino and one set for the existing circuit you really won't be able to scan the switches using the matrix method, you instead need 112 independent digital input points to read the switches.

That make better sense?

Lefty

THanks , the switches are just SPDT, not connected to anything yet, so I can do whatever I like. Looks like the array is simpler than using shift registers with PISO system. I have to do a PCB to mount all the switches which are the other half of the switches on 112 relays.
Even using another Mega is less than doing a board with the CMOS logic as it already has the serial built in.

If more than 2 switches may be closed at a time, the you'll need to connect a diode (1N4148 or similar) in series with each switch, otherwise you won't be able to determine exactly which ones are closed.

A 10x12 matrix would use one less pin than a 7x16 matrix.

As an alternative to using a Mega, if you will be connecting diodes in series with the switches, then you could use a 74HC4515 demultiplexer to generate 16 column lines from 4 pins. Then you can read a 7x16 matrix using just 11 Arduino pins (i.e. 4 for the column outputs and 7 for the row inputs).

Thanks for the demultiplexer idea, Not sure that you need the diodes , my thoughts run like this: assume it is a 7 x 16 crosspoint array and they are A thru G for the the 7 lines and 1 thru 16 for the 16 lines. If A is connected to 1 and A is also connected to 2. Then if you put a hi on the pinin that is A and read out the 1 thru 16 lines then you would get a Hi on pinin 1 and also pinin 2 , this then says that both A1 and A2 are closed. What am I missing when you say I need diodes?

As I said in my reply, it's when more than two switches are closed at once that you must have the diodes. Suppose switches A1 and B1 are closed. Then lines A and B are shorted together. So when you discover that driving A causes line 5 to be detected (as well as lines 1 and 2), you don't know whether it is A5 or B5 (or both) that is closed.

Yes, I am stupid today!! Adding the diodes is easy .
In case you wondered what this is all about.. here's the quick view.. I have 112 cells in a nom. 400 volt battery pack for my electric car that I am building. Need to know as a minimum if the pack is discharging as when being driven if any cells are lower than the low limit . Also when charging except that I just have shunting across any cell that has reached full charge allowing the rest to get fully charged too. This is called a BMS, battery management system, and is the biggest PITN . There are chips that are meant to do this but the ones from MAXIM have shown a failure mode that makes their use questionable, ( EMAIL ME DIRECTLY IF INTERESTED IN THIS ) so I am designing a simple system with relays for isolation. Each cell will have it's own relay and the contacts are what is forming the 7 x 16 array. I can have number of these open or closed depending on the individual cell condition. so diodes it is.