Cyber-Lock Challenge

12-21-2017 11-50-10 AM.gif

 

I challenged Mason with the task of building a “cyber lock” using an Arduino, Keypad and a Servo Motor to represent the lock. First we mocked it up on Circuits.io (now part of Tinkercad) and then we constructed the actual circuit using similar parts. The complete “specifications” we came up with for the project along with the accompanying code are available below.

 

 

Cyber-Lock Specifications

Version 1 – Last update: Nov 11, 2017

Use a Hex Keypad, LCD, Red & Green LED, and a Servo, along with an Arduino to create a “Cypher” lock.

Components:

  • Arduino Nano (Micro / whatever)
  • 16-Key Keypad
  • LCD Display
  • Red LED
  • Green LED
  • (2x) 220 Ohm Resistors
  • Other assorted items as required

Goal:

Create a “Cypher” lock using the above components that will “unlock a door” (turn the servo) when the correct code is entered at the Keypad.

Requirements:

  • The code shall consist of any 4 symbols except “*” and “#” which appear on the keypad. So “1234”, “ABCD”, “12AB”, etc. are all legitimate codes. “123#” is not.
  • The “#” symbol shall be interpreted as “Enter”, such that codes are entered followed by “#” to enact. Example: “1234#” would instruct the program to try the code “1234”.
  • When the “door” is “unlocked”, the servo shall rotate to the “unlocked” position and then the RED LED shall turn off and the Green LED shall turn on.
  • When the door is “locked”, the servo shall rotate to the “locked” position and then the Green LED shall turn off and the Red LED shall turn on.
  • The “” symbol on the keypad shall be used to signal the program to “Lock” the door if the door is unlocked. If the door is already unlocked then the “” symbol shall have no effect.
    The program shall only accept four symbols, not including either the “*” and the “#”. If additional symbols are pressed, the display shall “wrap around” and start again at the beginning. Only a maximum of four symbols shall be shown on the LCD display.
  • When the “*” symbol is entered, the four symbols shown beside the ‘Code:’ prompt shall be used to try the lock. If successful the lock shall open. If unsuccessful the display shall clear and be reset for a new attempt.

Notes:

This simulated version of the lock is a bit sluggish in responding compared to a real world version. Sometimes keys pressed on the keypad do not register (appear on the screen) as they should. We have never seen this issue with the same components in our real world version. However, it is not a serious problem, simply press the key again until it registers. Everything else seems to work the same way as the “real” version.

 

Source Code

(For Arduino “Nano” Controller)

//--------------------------------------------------------------
// MASON & DADDY'S CYPHER LOCK CODE
// 2016-OCT-20
//--------------------------------------------------------------

// include libraries to support our components
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <string.h>

//--------------------------------------------------------------
// set up our indicator leds
const int LED_UNLOCK = A4;
const int LED_LOCK = A5;

int state = 0; // 0 = unlocked, 1 = locked;
int i = 0;

//--------------------------------------------------------------
// Setup our Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns

// Define the Keymap
char keys[ROWS][COLS] = {
 {'1','4','7', '*'},
 {'2','5','8', '0'},
 {'3','6','9', '#'},
 {'A','B','C', 'D'}
};

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 8, 7, 6, 5 };

// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 9 };

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//--------------------------------------------------------------
// setup positions for our servo for door locked and unlocked
const word POS_UNLOCK = 1500;
const word POS_LOCK = 0;
int servo_delay = 500;
//--------------------------------------------------------------

const int SERVO_PIN = 13;

// create servo object to control a servo
Servo myservo;

// Connect the LCD to these interface pins (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(3, 4, A0, A1, A2, A3);

// define our password
char pword[] = "ABCD";
char buf[5];

//--------------------------------------------------------------
// the setup routine runs once when you press reset:
void setup() {
 // set our indicator led pins to output mode
 pinMode(LED_UNLOCK, OUTPUT);
 pinMode(LED_LOCK, OUTPUT);
 // pinMode(A1, OUTPUT);
 // pinMode(A2, OUTPUT);
 // pinMode(A3, OUTPUT);
 pinMode(A4, OUTPUT);
 pinMode(A5, OUTPUT);

// turn off both leds
 digitalWrite(LED_UNLOCK, LOW);
 digitalWrite(LED_LOCK, LOW);
 
 // attaches the pin to the servo object
 myservo.attach(SERVO_PIN);

// set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 lock();
}

//--------------------------------------------------------------
// the loop routine runs over and over again forever:
void loop() { 
 // handle the keypad
 char key = kpd.getKey();
 
 if(key) { // Check for a valid key.
 switch (key) {
 case '*':
 lock();
 break;
 case '#':
 if (strcmp(buf, pword) == 0) {
 unlock();
 }
 else {
 show_state();
 }
 break;
 default:
 buf[i] = key;
 lcd.setCursor(i + 6, 0);
 lcd.print(key);
 i++;
 if (i >= 4) {
 i = 0;
 }
 break;
 }
 }
}

void show_state() {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("CODE: ");
 lcd.setCursor(0, 1);
 if (state) {
 digitalWrite(LED_UNLOCK, LOW);
 digitalWrite(LED_LOCK, HIGH);
 lcd.print("-LOCKED-");
 }
 else {
 digitalWrite(LED_LOCK, LOW);
 digitalWrite(LED_UNLOCK, HIGH);
 lcd.print("-UNLOCKED-");
 }
}

void show_change_state() {
 lcd.clear();
 lcd.setCursor(0, 1);
 if (state) {
 digitalWrite(LED_UNLOCK, LOW);
 digitalWrite(LED_LOCK, HIGH);
 lcd.print("-UNLOCKING-");
 }
 else {
 digitalWrite(LED_LOCK, LOW);
 digitalWrite(LED_UNLOCK, HIGH);
 lcd.print("-LOCKING-");
 }
}

void lock() {
 show_change_state();
 memset(buf,0,sizeof(buf));
 myservo.write(POS_LOCK);
 delay(servo_delay);
 state = 1;
 show_state();
}

void unlock() {
 show_change_state();
 memset(buf,0,sizeof(buf));
 myservo.write(POS_UNLOCK);
 delay(servo_delay);
 state = 0;
 show_state();
}

CNC Routers

I have a lot of CNC Router project logs to transfer over. It’s going to take some time. So for now I’m going to include some links to the Google Albums so you can see some of our projects.

20171228_174223.jpgThe New CNC Router – Bigger & Stronger

The time has come to build a new CNC router. The old one is okay and works well enough for wood, but my attempts to use it to cut metal (aluminum, light-gauge steel) have been a little disappointing. The other issue it has is that seems perpetually either “too big” or else “not big enough” for whatever project I’m doing. It’s cutting envelope just doesn’t lend itself well for the range of projects that I want to work on.

 

So I spent some time back in January working on the old router, including rebuilding the Z-axis, and while it is now better than it was, it still doesn’t really solve the whole problem to my satisfaction. So after some deliberation, I have decided to build a new one to tackle these issues. Plus, let’s just be honest, I was kind of looking for an excuse to have a new machine project to work on… ๐Ÿ˜‰

 

20141129_215700.jpg

The Old CNC Router – First Foray into CNC Machining

This is the first foray for my kids and I into the world of CNC routers. I based this largely on the ‘OX’ design put out by Mark Carew of the OpenBuilds community. As you can see it uses the typical V-Slot ‘roller bearing’ arrangement which is promoted through OpenBuilds. So, while I did not buy all the components together specifically as a “kit”, I did go through the BOM (Bill of Materials) of the Ox and several other projects to accumulate a list of necessary components. The gantry plates and carriage assembly plates were all fashioned by Chris Laidlaw (‘ChrisClub’ on eBay). Chris is very easy to work with and has even made some custom parts for me which you’ll see later on in the photos.


 

You can also check out the links in the sidebar for additional projects related to the CNC routers.

 

 

First Blog Post

Howdy! Welcome to my new site. There’s not much here yet…. I guess I should probably put up some sort of a picture. Anyway, I got this site so we– my kids and I– can start keeping all of our stuff in one place. In the upcoming months the goal is to start migrating over project logs and albums that we’ve been keeping in other online locations to begin to chronicling our activities in a more comprehensive way. There’s only so much you can do with Google Photo Albums for instance. So we need a better way to start organizing all of these logs and records.

So hello and welcome aboard! Please feel free to follow along and make any comments, ask whatever questions, and do share links to your own projects and ideas. We’re always interested in seeing what other folks are up to.

I suppose I’m a little eclectic in getting updates up. It depends upon how busy I’ve been with work and “Honey-do’s” whether or not I’ve gotten in any time on projects. I try to plan stuff to do every weekend and sometimes it works out ๐Ÿ˜‰ Whenever I accumulate enough progress that it seems like it could be interesting, I put up a new post. So maybe once a week or two on average, I’d say.

Thanks for stopping by!