« Counting Daily Uses | Main | Dynamic Processing Character »

Combination Lock

Assignment: Come up with your own physical interface for a combination lock, using digital input and output.

I chose to build my own switches, using pushpins and tinfoil on the bottom of wooden blocks to complete the circuit when the block was oriented correctly. The solution requires the colored arrows on the blocks to correctly align with the complementary color on the console.

There is only one correct solution, effected by the alignment of the pins on the blocks, and the placement of the wires in the console. Until the proper combination is achieved, the red LED lights steadily. Once the puzzle is solved, a blue LED blinks to signal success. I added fake terminals to the console so that people couldn't solve the puzzle by simply visually matching the components.

Problems I encountered with this project were that the interface was not particularly intuitive to people asked to solve it, and that the completion of the circuit was somewhat unreliable. I wrapped the wire terminals with tinfoil to increase the likelihood of contact, but there was too much give in the console recepticles to ensure proper placement.

Arduino Code

// declare variables for combination lock:
int switch1Pin = 2;      //  digital input pin for first switch
int switch2Pin = 3;      //  digital input pin for second switch
int switch3Pin = 4;      //  digital input pin for third switch
int greenLedPin = 5;     //  digital output pin for green "win" LED
int redLedPin = 6;     //  digital output pin for red "not yet" LED
int switch1State = 0;    // set the state of the first switch to open
int switch2State = 0;    // set the state of the second switch to open
int switch3State = 0;    // set the state of the third switch to open

void setup() {
  pinMode(switch1Pin, INPUT);       // set the first switch pin to be an input
  pinMode(switch2Pin, INPUT);       // set the second switch pin to be an input
  pinMode(switch3Pin, INPUT);       // set the third switch pin to be an input
  pinMode(greenLedPin, OUTPUT);      // set the green LED "win" pin to be an output
  pinMode(redLedPin, OUTPUT);      // set the red LED "not yet" pin to be an output
}

void loop() {
  // read the switch input:
  switch1State = digitalRead(switch1Pin);
  switch2State = digitalRead(switch2Pin);
  switch3State = digitalRead(switch3Pin);

  if (switch1State == 1 && switch2State == 1 && switch3State == 1)  {
    digitalWrite(redLedPin, LOW);     // turn off the red LED
    digitalWrite(greenLedPin, HIGH);    // turn on the green "win" LED
    delay(300);
    digitalWrite(greenLedPin, LOW);    // turn on the green "win" LED
    delay(300);
  } 
  else {
    // if the combo isn't correct yet:
    digitalWrite(redLedPin, HIGH);     // turn on the red LED - might need to do this after each if?
  }
}

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~km63/cgi-bin/mt/mt-tb.cgi/3

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)