Brett Walach
Published © MIT

Retro Rotary Dial Internet Connected Lock

A quick internet-connected combination lock project for your retro rotary dial!

BeginnerShowcase (no instructions)1 hour3,277

Things used in this project

Hardware components

Telephone Rotary Dial
×1
Particle Photon
×1

Story

Read more

Schematics

Simple Wiring 1

The rotary normally closed switch connects to D5 input and GND. There is a 2.2k ohm pull-up resistor from D5 to 3.3V. Super simple!

Simple Wiring 2

Dialing '0' - 10 Pulses

Code

Retro Rotary Lock Code

C/C++
If you have a Particle account, click this shareable code link: https://go.particle.io/shared_apps/5a77f53c5cd0b03e41000062
SYSTEM_MODE(SEMI_AUTOMATIC);

String master_code = "8173";

int set_code(String arg) {
    if (arg.toInt() > 0) {
        master_code = arg;
        return master_code.toInt();
    }
    return -1;
}

void setup() {
    pinMode(D5, INPUT);
    pinMode(D7, OUTPUT);
    Serial.begin();
    Particle.function("setCode", set_code);
    Particle.variable("masterCode", &master_code, STRING);
    Particle.connect();
}

void loop() {
    static int number = 0;
    static unsigned long lastLowPulse;
    static bool printOnce = true;
    static bool firstPulse = false;
    static String code = "";
    static unsigned long lastLockOpen;
    
    if (digitalRead(D5) == HIGH) {
        // Initialize
        if (printOnce == true) {
            number = 0;
            printOnce = false;
            firstPulse = true;
        }
        // Increment Number
        number++;
        while (digitalRead(D5) == HIGH) {
            // Wait for pulse to go LOW
        }
        // Reset Pulse Timer
        lastLowPulse = millis();
    }
    
    // Do we have pulses and has pulse timer expired?
    if ( (firstPulse == true) && (millis() - lastLowPulse > 80) ) {
        if (printOnce == false) {
            printOnce = true;
            
            // Do stuff with our captured number
            if (number == 10) {
                number = 0;
            }
            
            code = code + String(number);
            
            Serial.printlnf("Digit: %d Code: %s", number, code.c_str() );
            
            if (code.length() == master_code.length()) {
                if (code == master_code) {
                    Serial.println("You did it boi!");
                    digitalWrite(D7, HIGH);
                    lastLockOpen = millis();
                    code = "";
                } else {
                    Serial.println("GET OFF MY LAWN SMALL CHILD!!!");
                    code = "";
                }
            } else if (code.length() > master_code.length()) {
                code = "";
            }
        }
    }
    
    if (digitalRead(D7) == HIGH) {
        if (millis() - lastLockOpen > 10000) {
            digitalWrite(D7, LOW);
        }
    }
}

Credits

Brett Walach

Brett Walach

4 projects • 19 followers
Sr. Embedded Hardware/Software Engineer at Particle, Hacker, Maker, Musician

Comments