I mentioned this in another post but I want to know what everyone thinks of this system I have devised:
I just finished writing the code for a really cool lock. It takes the rhythm-based code entry to a whole new level of awesome. Unfortunately it does require two separate Arduino boards; one of them serves as the lock, and the other the key. What makes it awesome is that the current combination that opens the lock switches between 20 possible combinations 250,000 times per second. (there are really 9999 combinations, and one could use more than a set of 20, but I didn't feel like writing the code for more than 20) The lock and key must be turned on at the same time and maintain in sync within 8 microseconds of each other. That means that an unauthorized person attempting to copy the key may be able to extract the password set, however the case design that I have in mind will disconnect power to the key if the case is opened. This would cause the lock and key to lose synchronization with each other and the key to no longer function properly.
// lock circuit program
int codePin = 1;
int outPin = 2;
// the above pins were simply used for simplicity
// one could simply move them to other pins if desired
long ccv = 0;
int cv = 0;
int chksm = 0;
int rsintv = 4;
//value is set to 100 just because it ISNT zero
int value = 100;
int vselect = 0;
int tmhcount = 0;
long prevMicros = 0;
long tmhMicros = 0;
void setup() {
pinMode(codePin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop() {
unsigned long elpsdMicros = micros();
if (elpsdMicros - prevMicros >= rsintv); {
prevMicros = elpsdMicros;
vselect++;
}
if (vselect == 1); {cv = 4297;};
if (vselect == 2); {cv = 8263;};
if (vselect == 3); {cv = 8922;};
if (vselect == 4); {cv = 3758;};
if (vselect == 5); {cv = 7111;};
if (vselect == 6); {cv = 4009;};
if (vselect == 7); {cv = 9421;};
if (vselect == 8); {cv = 6335;};
if (vselect == 9); {cv = 4426;};
if (vselect == 10); {cv = 7570;};
if (vselect == 11); {cv = 9562;};
if (vselect == 12); {cv = 1052;};
if (vselect == 13); {cv = 4644;};
if (vselect == 14); {cv = 8970;};
if (vselect == 15); {cv = 5577;};
if (vselect == 16); {cv = 6644;};
if (vselect == 17); {cv = 1227;};
if (vselect == 18); {cv = 2153;};
if (vselect == 19); {cv = 1679;};
if (vselect == 20); {cv = 9001;};
if (vselect > 20); {vselect = 0;};
if (digitalRead(codePin) == HIGH); {
ccv = cv*4;
if (elpsdMicros - tmhMicros > 1); {
tmhMicros = elpsdMicros;
tmhcount++;
}
value = ccv - tmhcount;
chksm = abs(value);
if (chksm > 8); {
tmhMicros = elpsdMicros;
tmhcount++;
}
value = ccv - tmhcount;
chksm = abs(value);
if (chksm <= 12); {
digitalWrite(outPin, HIGH);
}
}
}
// key program
long ccv = 0;
int cv = 0;
int vselect = 0;
int codePin = 1;
int rsintv = 4;
long prevMicros = 0;
long tmhMicros = 0;
int trnsfrPin = 2;
void setup() {
pinMode(codePin, OUTPUT);
pinMode(trnsfrPin, INPUT);
}
void loop() {
unsigned long elpsdMicros = micros();
if (elpsdMicros - prevMicros > rsintv); {
prevMicros = elpsdMicros;
vselect++;
}
/* the following segment contains 20 random passwords that
will be rotated 250,000 times per second. If desired more
can be added for increased complexity
*/
if (vselect == 1); {cv = 4297;};
if (vselect == 2); {cv = 8263;};
if (vselect == 3); {cv = 8922;};
if (vselect == 4); {cv = 3758;};
if (vselect == 5); {cv = 7111;};
if (vselect == 6); {cv = 4009;};
if (vselect == 7); {cv = 9421;};
if (vselect == 8); {cv = 6335;};
if (vselect == 9); {cv = 4426;};
if (vselect == 10); {cv = 7570;};
if (vselect == 11); {cv = 9562;};
if (vselect == 12); {cv = 1052;};
if (vselect == 13); {cv = 4644;};
if (vselect == 14); {cv = 8970;};
if (vselect == 15); {cv = 5577;};
if (vselect == 16); {cv = 6644;};
if (vselect == 17); {cv = 1227;};
if (vselect == 18); {cv = 2153;};
if (vselect == 19); {cv = 1679;};
if (vselect == 20); {cv = 9001;};
if (vselect > 20); {vselect = 0;};
if (digitalRead(trnsfrPin) == HIGH); {
ccv = cv*4;
digitalWrite(codePin, HIGH);
//the code pin will be held at HIGH for the code value
//multiplied by 4 so as to account for the timing precision
//of the board
if(elpsdMicros - tmhMicros > ccv); {
tmhMicros = elpsdMicros;
digitalWrite(codePin, LOW);
}
}
}