Key Code Cutter

by JonMackey in Circuits > Arduino

741 Views, 15 Favorites, 0 Comments

Key Code Cutter

Key Code Cutter

This project cuts keys for traditional round pinned locks based on a manufacturer's keyway specification and the code stamped on the original keys provided with the lockset. The code can also be determined by measuring the depths manually. The software supports cutting custom non-standard key depths by entering the custom depth for each pin.

Supplies

The mechanical parts for the frame and the estimated project cost is in BOM.txt.

My CNC board and parts list is available on PCBWay here.

My 4 inch display board is available on PCBWay here. You can also use an off-the-shelf 4 inch board and convert it to use an FFC cable using my display conversion board that is available on PCBWay here. Note that only my 4 inch display board will fit the enclosure I designed for this project.

All boards from PCBWay are bare boards unless you opt for the PCBWay assembly service. PCBWay also offers 3D printing services here.

Downloads

The Boards

Anotated Board.jpeg
My 4 inch board.jpeg

This project requires two custom boards, my CNC board and my 4 inch display.

Both of these bare boards are available from PCBWay. The CNC board is the first board I designed that contains a STM32 mcu. Over a period of a few weeks it took three revisions to get it right. The first correction was for interrupt pin assignments. The 2nd was to add a high-side switch and digital potentiometer, and the final version was when I decided to assign PWM timers to the stepper module step pins.

Note that PCBWay paid for one of the four versions of the CNC board because they liked some of the 27 boards I've shared on their site. I've used PCBWay for several years and I've never had any issues with the quality of the boards they produce. Their customer service is very responsive and helpful. PCBWay also offers a PCB assembly service. I've never used their assembly service but I assume it's worth the money if you don't feel confident or don't have the time to assemble the boards yourself. Assembling these boards should not be considered if you've never assembled boards containing parts with 0.5mm pin pitch (unless of course you need the practice.)

Tip: The CNC board's 64 pin mcu isn't easy to solder using a hot air soldering gun, and most likely impossible using a soldering iron. The gap between each pin is 0.2mm so it's very easy to end up with solder bridges. I use a hot air gun to solder the mcu as the first part on the board. I then use a DVM to test the continuity of each pin to its pad. Only after all pins pass, and there are no pins shorted together, do I add the rest of the parts.

The dip switch next to each stepper driver sets the micro step value. The software expects 32 micro steps. Set the X and Z switches to 101.

Downloads

The Hardware

Key Code Cutter Side.png
Key Code Cutter Top.png

Frame

The frame is a smaller 280x250x280 version of a frame I used in my build of a DIY Ultimaker 3D printer by JasonAtePaint: https://www.thingiverse.com/thing:811271. This project uses the same DIY Ultimaker 3D printed parts to reinforce the corners. The only difference is 2 additional 2020 extrusions used to support the gantry. All 18 of the 2020 extrusions are 250mm long. The gantry supports are attached using 8 L-shaped joint brackets. I used a total of 26 joint brackets to stiffen the frame, but the minimum is 8.

The top hole of the four 2020 side posts need to be tapped to accept M5x10 screws.

Assemble the back/power supply side, and the opposite (front) side using 2020 T-nuts and M3x10 flathead screws. Before attaching the top and middle beams to the post, slide in two 2020 L brackets on each beam for attaching the gantry beams.

Without the stepper motor in place, loosely attach the 3D printed Z axis motor mount using (4) M3 T-Nuts, (2) M3 button head and (2) M3 flat head screws to the bottom gantry support beam. The stepper motor mount goes within the 50mm space described below.

Assemble the remaining sides and the gantry support beams. The gantry beams are offset 50mm from the left side. The beams are held in place using the 2020 L brackets inserted earlier. I cut a 50mm block of wood to act as a spacer during assembly. The accuracy of the spacer isn't critical. What is critical is that both gantry beams are placed at exactly the same offset.


Gantry

Gantry

The 70x250 gantry deck as shown in the photo is made of 4 scrap 5mm 70x95 surplus aluminum caster plates connected together. I modeled the gantry in Fusion 360. I used the Fusion 360 file to create a drawing that can be used to layout the gantry deck on a single piece of aluminum, see Gantry Deck Drilling Guide.pdf.

As noted, the gantry deck as-built is 4 pieces. Because of this, if the deck is a single piece, the blade guard may need to be offset 5mm down to properly center over the cutter blade. If anyone decides to build this, and you use a single piece of aluminum for the deck, let me know and I will rework the design to get you the correct blade guard STL.

Cut the two 8mm lead screws and 8mm smooth shafts to 170mm. Cut another 8mm smooth shaft to ~130mm to act as the axle for the saw blade.

Assemble the gantry by attaching the two vertical pillow blocks to the underside of the gantry deck. Slide on the axle and loosely tighten one of the pillow block set screws to keep the axle from moving laterally. Attach the 8mm shaft to M10 spindle adapter used to hold the 16x60x6mm key cutting blade. Attach the 3D printed blade guard made up of 2 top brackets, a bottom bracket and the blade guard back. Do not attach the key cutting blade and 3D printed blade guard front at this time.

Attach the two brass lead screw nuts, motor mount and LMF8LUU vertical bearings. Thread the two trapezoidal screws into the lead screw nuts. Slide on a GT2 36T pulley on the underside of each with the pull set screw down, and loosely tighten to keep them from sliding off. Loop on a GT2-380 belt onto the 36T pulleys. Slide on a GT2 20T pulley with the set screw up, onto the underside of the front trapezoidal screw and loosely tighten to keep it from sliding off. Loop on a GT2-110 belt onto the 20T pulley. Slide on a KFL08 horizontal pillow block on each end of the two trapezoidal screws. Again, loosely tighten the set screws to keep the pillow blocks from falling off. Insert the smooth shafts into the vertical bearings. Cap each shaft with a 3D printed Z Linear Shaft Support.

Using M5 and M3 2020 T-Nuts, M5 DIN912 Socket head screws for the pillow blocks, and M3 button head screws for the 3D printed shaft supports, loosely attach the bottom pillow blocks and shaft supports to the bottom 2020 beam. Flip the frame over and do the same for the top beam. To determine the final placement of the blocks and shaft support, move the gantry down by turning the trapezoidal screws making sure to keep the gantry deck parallel to the beam. The rear pillow block should be flush with the end of the beam. Tighten the T-Nut screws. Flip the frame over and do the same for the top pillow blocks and shaft supports on the top beam. If the gantry deck was drilled precisely, the GT2-380 belt should now be tight. Note that the GT2-20T pulley sits on the pillow block, and the GT2-36T pulley sits on the 20T pulley. The opposite 36T pulley should be set at the same height.

Attach the motor to the motor mount on the gantry as shown below along with 20T and 60T pulleys, and a GT2-300 belt.

Gantry


Carriage

The carriage is a single 5mm 70x96 piece of aluminum. I don't have a drilling guide for this. The 4 SCS8UU Block bearings are mounted as shown flush to each corner. The 3D printed T8 Nut Holder is mounted on the underside centered on the right side. The 3D printed Jaw Mount is mounted on the top side, 10mm from the left, and 21mm from the back (the edge closest to the power supply.) The holes for the SCS8UU under the jaw mount will have to be chamfered. The holes used to attach the Jaw Mount are also chamfered. The key holder jaw has to be drilled and tapped to accept the two M4x14 button head screws. You can use the 3D printed Jaw Mount to determine where to drill out the metal key holder.

Attach one of the vertical pillow blocks to the 3D printed X Spacer using (2) M5x20 DIN912 socket head screws, M5 washers, and M5 nylon insert locknuts. Loosely attach the X Spacer and two 8mm vertical shaft supports on the right middle beam using M5x16 DIN912 socket head screws and M5 T-Nuts.

Mount the X axis stepper to the X axis motor mount using M3 screws and washers.

Loosely attach the 3D printed X Axis Motor Mount and two 8mm vertical shaft supports on the left middle beam using M5x16 DIN912 socket head screws, M3 button head screws, M5 and M3 T-Nuts.

Attach the key cutter blade to the spindle adapter using the 10mm to 16mm thick washers and special wrench (see BOM.txt)

Cut two pieces of 8mm smooth rod to 285mm. Slide the rods into the shaft supports part way, then slide on the assembled carriage. Slide the rods the rest of the way to mate up with the opposite shaft supports. Loosely tighten the nuts on the shaft supports. Chuck a house key blank in the carriage key holder. Move the gantry down till the blade nearly touches the key blank. Determine the location of the carriage by centering the key under the key blade making sure the supports are equidistant to the side posts on either end of the carriage way. The gap between the frontmost shaft supports and the front posts is approximately 40mm. Tighten the screws.

Determine where the Z axis stepper motor mount will be located by sliding on a 20T pulley onto the stepper shaft (do not tighten.) Insert the stepper shaft through the hole in the mount at the same time loop the GT2-110 belt onto the pulley. Using (4) M3 button head screws with M3 washers, attach the stepper to the mount. Slide the Z axis stepper motor mount towards the front of the frame till the belt is tight. Tighten the two button head screws on the underside of the gantry beam. Remove the stepper and tighten the stepper mount screws on the side of the gantry beam. Reinsert the stepper into the mount and secure. Tighten the pulley nuts to the shafts.

Slide on the 5 to 8mm flexible shaft coupler to the X axis stepper. Insert the 300mm 8mm X axis lead screw through the X axis pillow block. Spin the shaft into the brass lead screw nut on the carriage till the lead screw is inserted into the shaft coupler. Tighten the shaft coupler and pillow block screws.


Electronics

Mount the 12V DC power supply using the 3D printed Power Supply Brackets using flat head M3 screws. Note that the 20A power supply is oversized for this project. I used it because that's what I had on hand. I'm running the key cutter with an ammeter module inserted on the supply line, and the most I've ever seen it reach is 3.5 amps.

Mount the motor speed controller using the 3D printed Speed Controller Bracket. Note that the mounting screw on the speed controller front mounting threaded insert is extended so it sticks out the bottom of the speed controller. By doing this you're creating a stud that can be used to attach the bracket with an M3 nut. The other threaded insert is not used by the speed controller and is available to be used by the bracket. This initial mounting of the speed controller will be used to determine the length of the control cable that runs from the CNC board to the controller.

Gantry


I've included a 3D printed Switch Box that can be mounted on the back frame near the power supply on the rear left post. The receptacle is a common IEC320 C14 type found on many desktop computers and older monitors. The receptacle switch module noted in the BOM.txt expects FDFN1.25-187 (3/16") or similar female spade connectors to connect and jumper the wires. Both hot and neutral wires are switched so you need to build short jumper cables. The switched outbound wire to the power supply is held in place with a 3D printed internal clamp. The mounting hole pattern within the switch box is the same as the 3D printed Sides_Bottom_Bracket. To mount, remove the original screws and use longer screws to attach the box to the frame. You need to insert an M2x3 brass knurled thread insert on each corner to attach the cover using M2 flathead screws. The brass inserts can be inserted using a soldering iron with an M2 insert tip. The Switch Box Cover screw holes will have to be chamfered to accept flat head screws.

Gantry


The 3D printed KM Enc Base print requires M2x3 brass inserts on the corners to mount the top. It also needs (3) M3x4 brass inserts on the bottom to mount the 3D printed round CableTieMounts. Mount the (3) CableTieMounts to the underside of the KM Enc Base using M3 flathead screws. Mount the KM Enc Base to the frame using (2) M3 button head screws and 2020 M3 T-Nuts so that the KM Enc Base is roughly in the center of the top front frame beam. Mount the assembled CNC board in the enclosure using (4) M2x5 button head screws.

Gantry


The 4 inch display board is mounted in the 3D printed KM Disp Top print using M2x4 button head screws. Insert the 15cm 12P FFC cable into the FFC connector on the display board (blue tab visible.) Thread the FFC cable through the slot in the KM Disp Base print, then connect the top to the base using M2x4 flathead screws. You may need to chamfer the holes so the flathead screws are flush.

Thread the FFC cable through the top of the 3d printed KM Enc Top. Attach the display to the Enc Top Using (2) M3 flathead screws, washers, and M3 nylon insert locknuts. Insert the FFC cable into the vertical FFC connector on the CNC board (blue tab towards the 12 DC connection.) Don't attach the KM Enc Top to the base, just set it on the KM Enc Base for now. After all of the wiring is completed, use (4) M2x18 flathead screws to attach it to the base.

The 4010 12V DC cooling fan supply wire needs to be shortened to about 8cm and terminated with a 2P HX2.54 connector. Mount the fan to the cover using M3 flathead screws and M3 nuts. The fan draws power from the unused Y stepper motor driver header by inserting a 90° pin header in at pins 15 and 16 as shown.

Gantry


There are four end stops. The end stop modules attach to the 3D printed brackets using an M3 button head screw and an M3 nut. The X-axis end stop brackets are X Endstop R and X EndStop L. The X-axis brackets attach to the 2020 frame using M3 flathead screws and M3 2020 T-Nuts. The R and L suffix refers to the placement on the right and left side of the carriage. They should be placed so that the end stop limit switch arm will make contact with the carriage's 5mm plate.

Gantry


The Z-axis end stop brackets are Z EndStop T and Z EndStop B. The Z-axis brackets attach to the 2020 frame using M3 button head screws, M3 washers, and M3 2020 T-Nuts. The T and B suffix refers to the placement on the top and bottom relative to the gantry deck plate. They should be placed so that the end stop limit switch arm will make contact with the gantry deck plate. The lower end stop bracket is adjustable. It should be set to trip just before the cutter blade hits the top of the key holder.

Gantry


Wiring

Gantry

The wire colors shown above reflect the wire colors that come with the end stops and stepper motors specified in the BOM.txt. I cut the wires to length and terminated them with XH2.54 connectors.


The two cables for the motor speed controller are terminated with XH2.54 connectors on both ends. The colors used don't matter so long as you make them pin for pin the same on both ends. Use 22 to 26 awg wire.

Gantry

It's important that the speed controller specified in the BOM.txt is used if at some point you decide to programmatically control the motor speed. This speed controller has 5V logic so it's compatible with the digital potentiometer on the CNC board. Other speed controllers may look similar to this board but the logic is unregulated and is generally the same as the input power on the board. If you do use a non-5V controller, simply don't use the digital potentiometer connection on the CNC board, in which case you would use the mechanical potentiometer that came with the controller board to set the speed. The high-side switch on the CNC board can and should be used for either case because it's not voltage sensitive.

The emergency stop button is mounted using the 3D printed EM Stop print. This holds a 3 pin 6MM Momentary switch with a red cap. Run two wires from the XH2.54-2P EMERG STOP connector on the CNC board to the normally open pins on the switch. To cut down on noise, solder on a 0.1uf ceramic capacitor between these pins on the switch.

Using 18 awg or heavier wire and #8 fork connectors, run 12V from the power supply to the CNC board and the motor speed controller.

Connect the motor to the speed controller using 22 to 18 awg wire with one end terminated with FDFN1.25-187 female spade connectors, and the other #8 fork connectors. For the motor to spin in the correct direction, connect the negative lead from the speed controller to the positive tab on the motor.

To secure the wires to the frame use 3D printed CableTieMounts. The square mounts come in four angles: 45, 90, 135, and 180. The most useful angle is CableTieMount90. OR you can simply use just the round CableTieMounts, they can be mounted at any angle. The downside of the round mounts is they may not hold a set angle. Note that the cable tie mounts should be printed without any support.

The Software

Arduino Tools Setting.png

The software for this project can be downloaded from GitHub here.

If you don't already have the STM32 boards package loaded, you can load it via Arduino IDE->Tools->Board->Boards Manager... Then load the "STM32 boards groups". I'm using version 2.5.0.

The CNC board's mcu is a STM32F103RET6. The software only uses about 25% of the 512KB flash memory. The reason for using the E version of this chip is that it has twice as many timers as the next lower density chip. STM32F103xB, C, and D only have 4 timers whereas the STM32F103xE has 8.

If you haven't done so already, apply power and verify that you can measure 12V, 5V and 3.3V on the CNC board. There's a 5 pin header for measuring these voltages near the 12V power connector.

Configure the board in the Arduino IDE's Tool menu based on the screenshot above.

Open the Arduino IDE Settings and point the Sketchbook Location to the Key Machine folder.

Open the sketch KeyMachine.ino and verify that it builds.

If there are no errors, attach your ST-Link to the ST-Link header on the CNC board, and upload the sketch. Note that you should only connect 3 wires: GND, SWCLK and SWIO. You don't want to power the CNC board via the ST-Link cable.

Gantry

If there are no errors, proceed to the next step.

Operation

Info Screen.png

Before the touch panel can be used it must be aligned the first time it's used. There are two buttons on the CNC board labeled Enter and Cancel. Pressing the Enter button will display the display alignment screen as shown below.

Alignment

Follow the displayed instructions. Keep selecting the white dot within the circle till the magenta dot covers or nearly covers the white dot.

Alignment Accuracy

Alignment Done

As noted in the instructions within the screenshot, you keep selecting the white dot within the white circle till the accuracy is acceptable. Acceptable is defined as the magenta dots completely or mostly covering the associated white dots. You then press the Enter button on the CNC board to save the alignment parameters to the EEPROM. All preferences, such as the alignment parameters and setup settings described next are stored on a 24C64 EEPROM.

The Main Menu

Setup Origin MM

Note that all of these screenshots were made using my Mac OS ArduinoDisplayTester app.


Setting The Origin

Before cutting a key for the first time, the origin must be defined. The origin defines the bottom left corner of the key holder. This operation should only have to be performed once for the life of the machine. The origin defined here will work for all keys from any manufacturer. There is no need to perform this operation when using a different key blank.

Using a micrometer, measure and save the width of a key blank blade in mm. Mount this key blank in the key holder.

Key Origin

From the main menu, select Setup Origin.

Gantry

When you select Setup Origin the X and Z steppers are homed. The carriage will move below the cutter, and the cutter head will move to approximately 10mm above the expected location of the key holder.

Using the stepper button and the increment popup, enter the width of your key blank in the Zero Offset Z field. In the above example it's 6.35mm. The Zero Offset X field should generally always be left as 0.00.

The goal is to move the cutter so that it just barely touches the key blank shoulder and the top edge of the key blank. You move the cutter head using the Left, Right, Up and Down buttons. The amount the cutter head will move for each press is determined by the Increment popup. The increment is one of 10, 1, 0.1 and 0.01mm. You do not want to drive the cutter head into the key blank, so use the smaller increments.

Once you've positioned the cutter head so that it just barely touches the key blank shoulder and the top edge of the key blade, press Set. This will save the defined origin to EEPROM. The cutter head will rise out of the way and the carriage will move out from under the cutter head.


Cutting a Key

To cut a key, mount a key blank in the key holder and then select Cut Key from the main menu.

The Cut Key dialog will appear as shown below.

Cut Key 1

From the Keyway popup, select your key's key profile/keyway. From the pin count popup select the number of pins. For example Kwikset locks can be the standard 5, or 6 for Kwikset Titan. Unused pin positions are drawn with a greyed out X. If you know your key's pin code you can enter it by selecting a pin position and use the stepper button to increment or decrement the displayed pin size. If you don't know your pin code, take a micrometer and measure each key cut from bow to tip. You would then use the stepper button to select the pin depth closest to the measurement for that cut/pin. For example the pin depth of Kwikset pin size number 4 is 6.60mm.

Note that the current pin depth corresponding to the pin position selected is displayed in the Pin Depth field. It's not unusual for a micrometer reading to not be exactly the same as the value in the Pin Depth field due to wear or an inaccurate key copy.

Once all of the pin numbers have been entered, press Cut.

The cutter head and carriage will home, then the carriage will move under the cutter. The cutter will lower to a few mm above the key and pause while the cutter motor starts. Once the motor is at full speed, the cutting will commence. The cutter moves relatively slowly. Once the last cut is made the cutter head will move up and the carriage will move out from under the cutter head and stop. At this point you can remove the key from the key holder. Use a nylon bristle abrasive brush to remove the brass burrs on key to clean it up.


Cutting a Custom Key

To cut a custom key, follow the procedure above for cutting a key by code. Use the pin size stepper to find the standard pin closest to the custom pin depth for that position. Use the stepper to the right of the Pin Depth field to adjust the depth to the custom depth. Once a depth is set to a non-standard depth, the pin size number will change to a C.

Cut Key C


Adjusting the Origin

After you make your first key you may need to adjust the origin. Measure the cut depth of the new key and compare this to the manufacturer's published pin size depth (aka root depth.) Subtract the published depth from the measured depth. Do the same for the expected center of the first cut.

Open the Adjust Origin dialog by selecting Adjust Origin from the main menu. The following dialog will be displayed.

Adjust Origin

Enter the difference between the measurements in the Delta X and Z fields. As noted in the dialog, positive values will shift the X and Z right and down respectively. Press Set to save your changes.

Cut a new key to verify the accuracy of your changes.


That's it. I hope you found this project interesting. Send me a message if you have any questions.