Puzzle lock with Arduino

Newbie question here.

I am building a kind of puzzle lock for "exit room". The lock works so that there are 10 bare wire ends and user needs to combine them into 5 pairs to open the electric lock. Red to green etc. Lock should not open when all the wires are connected in bunch nor for any other combination.

At the moment I have it working with voltage window comparator circuit. Hooking up the wires in pairs creates a loop with specific resistance and the relay activates. The issue is that there are several combinations that will open the lock.

Is there a beginner way to achieve something like that with Arduino? Goal is that user needs to connect specific wire pairs in order the relay to activate.

I am just starting out with Arduino and any nudge to the right direction is greatly appreciated.

Thanks

I would use a port expander and have half the wires inputs and the others outputs. Then I would toggle the outputs and see if one and only the right one of the inputs toggles in sympathy.

You should distinguish valid from invalid connections. Valid connections are easy to check, there is only one set of values. Checking for invalid connections is a bit more complicated.

You can configure all connected pins as digital inputs. Then configure one pin as an output, and check which other connections are affected when you pull that pin high or low. Do that for all pins.

Five wires with random value resistors in series connected to +5volt.
Five wires with random value resistors in series connected to five analogue inputs and ground.

Only a good combination will give five exact analogue values.
Leo…

Erx27: I am building a kind of puzzle lock for "exit room". The lock works so that there are 10 bare wire ends and user needs to combine them into 5 pairs to open the electric lock. Red to green etc. Lock should not open when all the wires are connected in bunch nor for any other combination.

At the moment I have it working with voltage window comparator circuit. Hooking up the wires in pairs creates a loop with specific resistance and the relay activates. The issue is that there are several combinations that will open the lock.

Is there a beginner way to achieve something like that with Arduino? Goal is that user needs to connect specific wire pairs in order the relay to activate.

I am just starting out with Arduino and any nudge to the right direction is greatly appreciated.

That's a typical "wire tester" application. No additional hardware required, except the cables.

It is easy with Arduino and can be done like this: 5 pairs of wire = 10 pins.

Set all 10 pins to pinMode INPUT_PULLUP and then start the test cycle with two nested for loops: In the outer for-loop you set one (and only one) pin to OUTPUT/LOW and in the inner loop you check which of the input pins also goes LOW. If any wrong input pins goes LOW in this test or if any input pins do not go LOW while they should (because of the existing connection), the whole test cycle is a fail.

So the simple trick is: Do not watch out for good connections, but watch out for wrong cabled connections and for not cabled connections. If you find a single one of them, the test is a fail. And if none of the connections is wrong, the test is passed.

since you are a beginner, you need to read and re-read post #4 from JURS.

the arduino digital pin has the ability to be high or low. set them all to high by setting the internal pullup .

you can then test by setting any one pin low. this will pull down any wire (pin) connected to it. then read which pins got pulled low as a result of being connected.

if you want pins 1,2,3,4,5 as your setA, then, when you test, if any from 6,7,8,9,10 get pulled low, you have not solved the puzzle.

but you also have to test to make sure that EACH of pins 1,2,3,4,5 are all connected. if all of the pins in set A are NOT connected (test good) then the test fails.

if this is a blind puzzle and only the correct answer has any feedback, then you only need to test with one from set A and one from set B.

if you are offering feedback, you may want to test all of the pins individually by setting each pin low to get results.

Thank You

I was going on Jurs recommendation and I came out with this simplified scetch with 4 wires (just to understand how it works).

// set pins to wires

int blackWire = 1;
int greyWire = 2;
int brownWire = 3;
int greenWire = 4;

int openDoor = 11;  //pin to control the relay (door opens on HIGH)

void setup() {

  pinMode(blackWire, INPUT_PULLUP);  //make  pins with wires INPUT_PULLUP at the start
  pinMode(greyWire, INPUT_PULLUP);
  pinMode(brownWire, INPUT_PULLUP);
  pinMode(greenWire, INPUT_PULLUP);

  pinMode(openDoor, OUTPUT); //make pin with door relay  to OUTPUT pin
  digitalWrite (openDoor, LOW); // make the output value LOW
}

void loop() {

  pinMode(blackWire, OUTPUT); //set only black Wire to OUTPUT/LOW
  digitalWrite(blackWire, LOW);

  if (greyWire == LOW && brownWire == HIGH && greenWire == HIGH) {  //set that grey wire is connected to black
    pinMode (blackWire, INPUT_PULLUP); //set black Wire back to default

    pinMode (greyWire, OUTPUT);
    digitalWrite (greyWire, LOW);

    if (blackWire == LOW && brownWire == HIGH && greenWire == HIGH) {
      pinMode (greyWire, INPUT_PULLUP);

      pinMode (brownWire, OUTPUT);
      digitalWrite (brownWire, LOW);

      if (greyWire == HIGH && blackWire == LOW && greenWire == HIGH) {
        pinMode (brownWire, INPUT_PULLUP);

        pinMode (greenWire, OUTPUT);
        digitalWrite (greenWire, LOW);

        if (blackWire == HIGH && greyWire == HIGH && brownWire == LOW) {

          pinMode (greenWire, INPUT_PULLUP);  //greenWire back to default

          digitalWrite (openDoor, HIGH);  //activate relay
          delay (5000); //keeps door open for some time
          digitalWrite (openDoor, LOW);  //door shut again
        }

      }

    }

  }

}

I have not yet tested it as I get my Arduino over the weekend. I appreciate any feedback, especially if something is terribly wrong (there must be).

With 10 wires it will be a nightmare when put this way, so if this works, then the plan would be to use for statement and check that pin 1 is connected to pin 2, 3to4 etc.

Erx27:
I appreciate any feedback, especially if something is terribly wrong (there must be).

You will have to use structured programming, arrays and for-loops.

And the programming logic will be absolutely the same, no matter how many pins you are using.

Strictly avoid using pin-0 and pin-1 as these are the RX- (receive) and TX- (transmit) pins used for “Serial” on your UNO board!

Here is a programming base frame, that can be worked out:

// define pins at the start of the cable
byte cableStartPins[]= {3,4,5,6,7};

// define pins at the end of the cable
byte cableEndPins[] = {8,9,10,11,12};

// the assumed 'correct' wiring would then be: 3-8, 4-9, 5-10, 6-11, 7-12

#define NUMCONNECTIONS (sizeof(cableStartPins))

void setOutputPin(byte pinNumber)
{ // First set all pins to INPUT_PULLUP
  for (int i=0; i<NUMCONNECTIONS; i++)
  {
    pinMode(cableStartPins[i],INPUT_PULLUP);
    pinMode(cableEndPins[i],INPUT_PULLUP);
  }
  // Finally set one (and only one!) pin to OUTPUT/LOW
  pinMode(pinNumber,OUTPUT);
  digitalWrite(pinNumber, LOW);
}

void DoOneTest()
{
  // fill in test code here
  Serial.println("Test result: ???");
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("################################################");
  Serial.println("#                   CABLE TEST                 #");
  Serial.println("################################################");
  Serial.println();
}


void loop()
{
  DoOneTest();  // do one test
  delay(1000); //  wait one second
}

Included are these function:

  • setup() function to enable Serial debugging
  • loop() function to start one test per second
  • setOutputPin() function to set all pins to INPUT_PULLUP, except one which is set OUTPUT/LOW

For a complete program you need to write the actual testing code in the DoOneTest() function.
Hint: Use two nested for-loops running the test!

Got an idea? Or do you need additional hints?