Digital code-lock with four switches

Hello everyone,

I’m pretty new to using XOD and programming my Arduino. I’ve been trying to build a code-lock. Plan is to have four rocker-switches that have to be switched (input pin to Low) in a particular order to open a lock (output signal High). In my workspace in XOD I have placed four switches, but I can’t wrap my head around what to do next, what nodes I should select and how to connect them. So much nodes to choose from and I’m not sure how every node functions and what input/output they require. Did the tutorial on how to use switches, but how to combine them to do what I want…

Every help is welcome to get me started. Thanks in advance.

Although this sounds like it should be easy, this is not a trivial project. To start with, you need to be able to remember state so you can determine which Port should be activated next; I would probably use flip-flop nodes for that. The easiest process is to add another button to reset the system (or you can “cheat” and just use the first switch to do this). I’m sure there are other options, but I would probably add another flip-flop to remember if any switches were done out of order. Once you have all the flip-flops laid out, you need to work out how to write them together. One option is to have the reset clear all the flip-flops except the first one that gets set to indicate it is time for the first button. If the correct switch is flipped, then its flip-flop needs reset and the next one set. If a switch is flipped when it’s flip-flop is reset, then the flip-flop for error needs set so lock cannot open.

Even with this info to get you started, actual wiring will not be trivial. You will most likely need some and/or nodes, and perhaps if-else or gate nodes.

Thanks for your reply. I think I found a solution for this. I’ve been using the following nodes succesfully sofar;

  • ‘Mechanical-Switch’ node represent rocker-switches (no momentary switches)
  • ‘Pulse on true’-node
  • ‘Select’-node’
  • ‘Accumulate-String’-node
  • ‘Count’-node
  • ‘Any pulse’-node
  • Some flip-flops
  • Some delay-nodes

The mechanical switches outputs are tied to the ‘pulse on true’ nodes. Each pulse-node is connected to one of the pulse-inputs of the ‘select’-node and to a ‘Any’-pulse node. The node connected to the ‘Select’-node passes through the value (Xn) that’s tied to the corresponding pulse-connection (Sn) and puts that value on the output-pin. This pin is connected to the ‘Char’-input pin of the ‘Accumulate-string’-node. Further, the output-pin of the ‘Any’-pulse node is connected to the ‘push’-pin of the ‘Accumulate-string’-node. So whenever one switch is set to High, the corresponding value will be put in the ‘Accumulate-string’-node (you have to put the ASCII-code of the desired character in the ‘Select’-node, because the ‘Accumulate-string’-requires this, so “1” is 49d). The string that appears at the ‘STR’-pin of this node, will be compared with a string which contains the switch-sequence (for example “312”). If these strings are equal, a ‘Pulse-on-true’-node will fire and cause a flipflop to go high, which can be used to output a signal to energise a relay or something.

Anyway, images say more than a thousand words, so look at attached image. You can see above configuration for just 3 switches. I’ve also added a structure that resets the ‘Accumulate-String’-node when one of the swiches is put back to Low or when the accumulated string is not equal to the ‘code’-string. I tried using the ‘FULL’-connection of the ‘Accumulated-String’-node to determine if all switches are High, but it only pulses when a fourth switch/character (which doesn’t exist) is tried to push into the node, so I had to add a ‘Count’-node to do this. I know, the entire structure may not be as lean as possible, but it works for me now.

That sounds a lot simpler than my suggestion…