Similar to a cable tester concept, but for pre-wired switches.

I don't have any useful code to share. After a few false starts, I've decided that I need to seek out conceptual guidance.

Attached are (2) sample schematics to provide some idea of the types of variations we might have to test. These are wired inside of an electromechanical switch to either a 5 pin or an 8 pin connector. There is a 2.2KΩ resistor on the anode side of the led in versions with a pilot light, though it's not shown in the example schematic. In use, the led is driven with 24V dc.

In practice, we may end up with ~30 different useful schematics to deal with. We have considered up to 900 combinations.

I assume we will indicate which "recipe" we're looking for and compare results when the switch is in the normal (set-up) state as shown in the schematics, and then in the actuated (tripped) state when all the contact sets have changed from their normal state.

I don't want to have to ring out more than a handful of these manually if I can avoid it. Looking forward to any helpful guidance.

5 pin

8 pin

Thank you

Conceptually, you connect your 8 pins to 8 inputs on an arduino. You set those pins as INPUT_PULLUP so they will read HIGH when nothing is connected to them.

Then, one by one, you turn one of the pins into an OUTPUT and make it LOW. You then scan the other pins and see if they are HIGH or LOW. HIGH = not connected to test pin, LOW = connected to test pin.

Cycle through all combinations.

Report results.

Thank you for your reply. I appreciate your test method suggestion. I'm still struggling with what format would be best to store the "recipes".

I'm also not sure how it will work when there is a pilot light present.

You could use serial input to set a variable that informs your code of the number of pins. Then use the above methodology. So you would have an 8 pin and a 5 pin function. You could, reasonably easily have the serial port output which pin is connected to which other pins. Working from pin 1 down e.g.
pin 1 is connected to pin 4,5,6
pin 2 is connected to etc

Or, if you know likely patterns you could name the patterns and have the serial monitor print: this is pattern 1 etc

Have a state variable as well so that you compare before and after actuating the switches

I can see a for loop being useful to cycle through things and return the connection combo
then perhaps cases to compare.

makesomething:
Thank you for your reply. I appreciate your test method suggestion. I'm still struggling with what format would be best to store the "recipes".

I'm also not sure how it will work when there is a pilot light present.

You would not want to do this with the system powered up. Pulling pins low could lead to bad things happening

pmagowan:
You could use serial input to set a variable that informs your code of the number of pins. Then use the above methodology. So you would have an 8 pin and a 5 pin function. You could, reasonably easily have the serial port output which pin is connected to which other pins. Working from pin 1 down e.g.
pin 1 is connected to pin 4,5,6
pin 2 is connected to etc

Or, if you know likely patterns you could name the patterns and have the serial monitor print: this is pattern 1 etc

Have a state variable as well so that you compare before and after actuating the switches

I can see a for loop being useful to cycle through things and return the connection combo
then perhaps cases to compare.

Thanks for these ideas. Your "comparing to the patterns" suggestion triggered me to think maybe I should just put the initial (6) patterns (x 2 for both states) in the program. Maybe worry about pulling from an SD card or something down the road, use a MEGA to delay that day by a little bit.

blh64:
You would not want to do this with the system powered up. Pulling pins low could lead to bad things happening

Ok, thanks.

Your schematics show 2 switches, each with a NO and NC connection. Are they independent? Or is it really just a single switch (DPDT)? If they are independent, you will need to test when both are not NO and then when each one in the NC position.

You might want to think about how you would store the “patterns” such that you could compare the actual results and determine which configuration you are dealing with.

For example, given your 8 pin schematic (and there are two independent switches, SW1 and SW2)

NO test
1:5
2:4
3:
4:2
5:1
6:
7:
8:

SW1 closed
1:
2:4
3:8
4:2
5:
6:
7:
8:3

SW2 closed
1:5
2:
3:
4:
5:1
6:7
7:6
8:

IF there is only, ever 1 other pin connected to the test pin, then those 8 pins can be represented in a byte. It makes for a very compact format.

If that isn’t the case, and some configurations have multiple pins tied together than some other storage method will be required.

You could use an array of 8 bits for the pattern so not much space required

blh64:
Your schematics show 2 switches, each with a NO and NC connection. Are they independent? Or is it really just a single switch (DPDT)?...

You might want to think about how you would store the "patterns" such that you could compare the actual results and determine which configuration you are dealing with...

IF there is only, ever 1 other pin connected to the test pin, then those 8 pins can be represented in a byte. It makes for a very compact format...

Thank you for your thoughts. I'm sorry the schematics aren't clear. It's really just a single switch in each of the (2) schematic examples. There should probably be a vertical dotted line between them. My original thought was that the 8 pins would be viewed as a byte. I'm still searching for the best way to store the "patterns".

I'm trying to understand if the patterns (recipes) can be stored, maybe in a 2d array. It seems like it would be better to have the array reside in flash or on an sd card and have the sketch access the memory locations, but not have the array be created by the sketch each time (if that's possible). The array would only need to be changed when a schematic is modified, or when adding a new one. Thanks again for the information you provided.

Ok for patterns:

Max 8 pins so 8 bytes store a pattern
Draw a 8 x 8 grid
Start at top left as pin 1
Then down through all 8
Same across
If a pin is connected to another it is a 1 if not a 0

So byte 1 could be 10000001
Which would mean pin 1 is connected to pin1 and pin8
Byte 2 01000011 means pin 2 is connected to pin 2 and pin 7 and 8
Etc

So you need a maximum of 16 bytes for a before and after actuation pattern

So, do you think declaring an array for the patterns in the sketch is the way to do it? Seems like the most straightforward way. Could use PROGMEM to store them in flash.

And a Mega has 4096 bytes of EEPROM which means you could store/update 256 patterns without having to recompile your code if you just connect to a serial port, update, etc.

blh64:
And a Mega has 4096 bytes of EEPROM which means you could store/update 256 patterns without having to recompile your code if you just connect to a serial port, update, etc.

pmagowan:
Ok for patterns:...

Thank you both for your suggestions. I feel like I have some direction now. I have an Uno tied up with another project, so now a Mega is on the way. I'll try to let you know how it goes. I appreciate your time and the information you provided.

Good Luck! As a start, I’d just put those arrays in regular memory and get everthing working. When things seem to be working, then start to worry about how you can turn your 2-3 test patterns into 100s of patterns stored either in EEPROM or PROGMEM.

Good luck, it is an interesting project and a very practical one. Definitely much better having an inerrant uC checking these things than a human with a multimeter! I would just do one pattern and see how it goes first. I don’t think it will be too problematic but when you go to put the patterns in you need to double and triple check as human error here will be multiplied! Preferably have a real switch to test for each pattern and store them individually before you start trying to combine them as an error could mess the whole code up and be hard to debug.

Also look at hardware as you could probably make an adjustable sensor with the pins able to move to suit different configurations. 2 pins to each connection could detect continuity and thus confirm that there is a connection there so you wouldn’t even have to input the number if connections on the switch.

I like the concept…
Ideally, you’ll plug in an unknown switch, and the program will tell you which ones it thinks it might be.
Then it prompts you to push button ‘x’, and further narrows the choices. Same for button ‘y’, until it determines one choice.

Button data could be stored in an array as suggested above, it wouldn’t take you long to learn all your inventory - let the device do it for itself… save to an SD card, and it’s dome forever.

Whenever there’s ambiguity or an unresolved button signature - either it a new button, or there’s a problem in the connections / switch.

Thanks again for the ideas you provided. This first step is working. Haven't tried to put anything in memory yet to check against. Not much finesse in the code so far I know, but it's working.

/*
 * Initial 8 pin switch simulation.
 */
// set pin numbers:
 const int m12Pin1 = 31;     // m12 connector Pin 1 Wht = Mega Pin 31
 const int m12Pin2 = 32;     // m12 connector Pin 2 Brn = Mega Pin 32
 const int m12Pin3 = 33;     // m12 connector Pin 3 Grn = Mega Pin 33
 const int m12Pin4 = 34;     // m12 connector Pin 4 Ylw = Mega Pin 34
 const int m12Pin5 = 35;     // m12 connector Pin 5 Gry = Mega Pin 35
 const int m12Pin6 = 36;     // m12 connector Pin 6 Pnk = Mega Pin 36
 const int m12Pin7 = 37;     // m12 connector Pin 7 Blu = Mega Pin 37
 const int m12Pin8 = 38;     // m12 connector Pin 8 Red = Mega Pin 38

void setup() {
  pinMode(m12Pin1, INPUT_PULLUP); // initialize 
  pinMode(m12Pin2, INPUT_PULLUP); // pins as
  pinMode(m12Pin3, INPUT_PULLUP); // INPUT_PULLUP
  pinMode(m12Pin4, INPUT_PULLUP); // so they will
  pinMode(m12Pin5, INPUT_PULLUP); // read HIGH
  pinMode(m12Pin6, INPUT_PULLUP); // when nothing
  pinMode(m12Pin7, INPUT_PULLUP); // is connected
  pinMode(m12Pin8, INPUT_PULLUP); // to them.
  int i;
  int readStart = 31;   // start reading at digital pin 31
  int readEnd = 39;     // end reading at digital pin < 39
  Serial.begin(9600);
  Serial.print("Initial pin readings:");     //Before any output(s)
  // Read the pins when they are in the initial state.
  for (int i = readStart; i < readEnd; i++){
  Serial.print(digitalRead(i));
  }
  Serial.flush();                       // Ensure all data is sent.
  Serial.println();
}
void loop() {
  pinMode(m12Pin1, OUTPUT);              // sets m12Pin1 as output
  delay(1000);                           // waits for a second
  digitalWrite(m12Pin1, LOW);            // set m12Pin1 LOW
  delay(1000);                           // waits for a second
  int i;
  int readStart = 31;           // start reading at digital pin 31
  int readEnd = 39;             // end reading at digital pin < 38
  Serial.print("Pin readings w/ 1 LOW:");         //Output m12Pin1
  // Read the pins when m12Pin1 Output is LOW.
  for (int i = readStart; i < readEnd; i++){
  Serial.print(digitalRead(i));
  }
  Serial.println();
  Serial.flush();                      // Ensure all data is sent.
  while(1) {}                          // Stop the void loop.
}

Great start. If you learn a bit about using arrays, it will make it much easier to cycle through all your pins and all the combinations

/*
   Initial 8 pin switch simulation.
*/
// set pin numbers:
/*
  const int m12Pin1 = 31;     // m12 connector Pin 1 Wht = Mega Pin 31
  const int m12Pin2 = 32;     // m12 connector Pin 2 Brn = Mega Pin 32
  const int m12Pin3 = 33;     // m12 connector Pin 3 Grn = Mega Pin 33
  const int m12Pin4 = 34;     // m12 connector Pin 4 Ylw = Mega Pin 34
  const int m12Pin5 = 35;     // m12 connector Pin 5 Gry = Mega Pin 35
  const int m12Pin6 = 36;     // m12 connector Pin 6 Pnk = Mega Pin 36
  const int m12Pin7 = 37;     // m12 connector Pin 7 Blu = Mega Pin 37
  const int m12Pin8 = 38;     // m12 connector Pin 8 Red = Mega Pin 38
*/
const int testPin[] = { 31, 32, 33, 34, 35, 36, 37, 38 };
const int testPinCount = sizeof(testPin) / sizeof(testPin[0]);


void setup() {
  /*
    pinMode(m12Pin1, INPUT_PULLUP); // initialize
    pinMode(m12Pin2, INPUT_PULLUP); // pins as
    pinMode(m12Pin3, INPUT_PULLUP); // INPUT_PULLUP
    pinMode(m12Pin4, INPUT_PULLUP); // so they will
    pinMode(m12Pin5, INPUT_PULLUP); // read HIGH
    pinMode(m12Pin6, INPUT_PULLUP); // when nothing
    pinMode(m12Pin7, INPUT_PULLUP); // is connected
    pinMode(m12Pin8, INPUT_PULLUP); // to them.
    int i;
    int readStart = 31;   // start reading at digital pin 31
    int readEnd = 39;     // end reading at digital pin < 39
  */

  Serial.begin(9600);
  Serial.print("Initial pin readings:");     //Before any output(s)
  // Read the pins when they are in the initial state.
  for (int i = 0; i < testPinCount; i++) {
    pinMode(testPin[i], INPUT_PULLUP);
    Serial.print("Pin ");
    Serial.print(i);
    Serial.print(digitalRead(testPin[i]));
    Serial.print(",");
  }
  Serial.println();
}
void loop() {

  // cycle through each pin, setting it as an output and LOW
  // and then report the other pins

  for (int pin = 0; pin < testPinCount; pin++) {
    pinMode(testPin[pin], OUTPUT);
    delay(1000);
    digitalWrite(testPin[pin], LOW);
    delay(1000);
    Serial.print("Pin readings w/ ");
    Serial.print(pin);
    Serial.print( " LOW:");
    // Read the pins when m12Pin1 Output is LOW.
    for (int i = 0; i < testPinCount; i++) {
      Serial.print("Pin ");
      Serial.print(i);
      Serial.print(digitalRead(testPin[i]));
      Serial.print(",");
    }
    Serial.println();
    pinMode(testPin[pin], INPUT_PULLUP);
  }
  while (1) {}                         // Stop the void loop.
}

blh64:
If you learn a bit about using arrays, it will make it much easier to cycle through all your pins and all the combinations

Thanks for the tip. Can’t say I fully understand arrays yet, but using your code works. Pretty happy with the progress so far.