Hi
I have a large amount of limit switches connected in series that I need to test in situ on occasion (not live).
I was thinking about using the arduino mega, and connecting each junction alternately to a digital output and input. I would output high on the first junction, read the input on the second, set the first output to low, set the third output to high, read the input on the second again, and so on, going through the whole series. Save the output and output it to a display when done.
I would connect current limiting resistors on the outputs to avoid frying the arduino, and pull-down resistors on the inputs.
Is there any reason why this wouldn't work? I don't have an arduino at the moment, so it would be nice with some input before I order one to try it out.
You might use 8-input 3-state multiplexers like the 74HC251. For one multiplexer you will need 5 pins on an Arduino (Chip Select, 3 address pins and the output pin).
For 2 multiplexers you will only need one pin more (6 pins). For each additional multiplexer you will only need one extra pin (chip select). You can share the address lines, because only the selected chip will be active.
You can connect all outputs to a single Arduino input pin (3-state technology). When a chip is not selected, the output will be high impedance and only the active chip will send its signal to the Arduino.
So for 32 switches you will need four 74HC251 chips. They cost close to nothing. And an Arduino UNO will do the job.
Connect each switch to +5V using a 2K2 resistor (please also try higher values to save power). Lets call this pin the "hot-end". Connect the other pin to ground. Now connect the "hot-end" to one of your signal inputs of the multiplexer.
Your code should select the chips one by one and step thru addresses 0 thru 7.
I am not using this forum frequently. So in case you have questions a lot of people will definitely help you.
Thanks for the replies, arduinoaleman. However, I'm not sure your solution does quite what I want. I suppose my original description was a little too unclear, so I'll elaborate.
The switches have 4 sets of contacts (2 NC, 2 NO), of which 3 are used.
All switches in a series connection should be in the same position, however occasionally a switch will malfunction (but from experience it might only be one set of contacts failing). I need to identify that switch.
So I have 3 separate series connections, of which one or two will have all switches open, and the other(s) will have them closed.
As the setup is currently, the simplest way to test would be just 3 switches at a time. The alternative would be 15 switches at a time, but this is problematic due to the way the switches are wired, and rewiring is most likely not a possibility.
Is the current limiting resistor on the output not enough to eliminate the problem of outputs "fighting each other"?
Would setting the pinmode for the output to INPUT after testing a switch solve the problem? This was my initial idea, but I was having trouble getting it to work in simulation so I forgot about it.
According to the documentation the impedance of a digital i/o pin configured as input with the pull-up resistor disabled is 100 megohm.
void loop() {
for (i = 0; i < 4; i++) {
pinMode(outputPin, OUTPUT);
pinMode(inputPin, INPUT);
digitalWrite(outputPin, HIGH);
value = digitalRead(inputPin);
pinMode(outputPin, INPUT);
if (toggle == 0) {
outputPin += 2;
}
else {
inputPin += 2;
}
toggle = !toggle;
}
}