// Author: Nien Lam // Date: 09-15-2009 // Title: Finger Switch Combination Lock // Descr: This is a combination lock where the fingers (index, middle, ring) must be // pressed down in the correct sequence in order to open the lock. One of 3 red LEDs will // light when a finger combination is correct. The master green LED will light once all // 3 combinations are entered. // Digital input pins for finger swtiches. int indexFinPin = 2; int middleFinPin = 3; int ringFinPin = 4; // Digital output pins for the LEDs. int firstLedPin = 8; int secondLedPin = 9; int thirdLedPin = 10; int masterLedPin = 11; // =========== SET COMBINATION HERE ================================ // Lock combinations for fingers {index, middle, ring) int firstComb[] = { 1, 0, 1 }; int secondComb[] = { 1, 1, 0 }; int thirdComb[] = { 0, 1, 1 }; // Counter to track which how many locks are open. int lockOpenCount = 1; void setup() { // Set finger switches as inputs. pinMode(indexFinPin, INPUT); pinMode(middleFinPin, INPUT); pinMode(ringFinPin, INPUT); // Set LEDs as output. pinMode(firstLedPin, OUTPUT); pinMode(secondLedPin, OUTPUT); pinMode(thirdLedPin, OUTPUT); pinMode(masterLedPin, OUTPUT); } void loop() { // Check first finger combination. if (lockOpenCount == 1) { if (digitalRead(indexFinPin) == firstComb[0] && digitalRead(middleFinPin) == firstComb[1] && digitalRead(ringFinPin) == firstComb[2]) { digitalWrite(firstLedPin, HIGH); lockOpenCount++; addDelay() return; } } // Check second finger combination. if (lockOpenCount == 2) { if (digitalRead(indexFinPin) == secondComb[0] && digitalRead(middleFinPin) == secondComb[1] && digitalRead(ringFinPin) == secondComb[2]) { digitalWrite(secondLedPin, HIGH); lockOpenCount++; addDelay() return; } } // Check third finger combination. if (lockOpenCount == 3) { if (digitalRead(indexFinPin) == thirdComb[0] && digitalRead(middleFinPin) == thirdComb[1] && digitalRead(ringFinPin) == thirdComb[2]) { digitalWrite(thirdLedPin, HIGH); lockOpenCount++; addDelay() return; } } // Turn on Master LED if all locks are open. if (lockOpenCount > 3 ) digitalWrite(masterLedPin, HIGH); } // A common delay function. void addDelay() { delay(500); }