Tutorial Part 4: Custom Symbols and Footprints

The circuit would be improved by adding a switch to turn the LED on and off. The process to add this switch will require creating a new symbol and footprint library, drawing a switch symbol, and creating a footprint for the switch.

The specific switch that will be used in this guide is the NKK M2011S3A1W03, an SPST toggle switch. Many other switches could be used, but the pin numbering and footprint dimensions may need to be adjusted.

Library and Library Table Basics

Symbols and footprints are organized into libraries. A library can hold symbols or footprints, but not both.

KiCad keeps track of the user’s symbol libraries and footprint libraries in the symbol library table and footprint library table, respectively. Each library table is a list of library names and the location of where each library exists on disk.

In addition to global symbol and footprint library tables, there are also project library tables for symbols and footprints. Symbols and footprints that are added to the global tables are available in all projects, while symbols and footprints in the project-specific tables are available only for that specific project. Users can add their own libraries to the global library tables or to project-specific tables.

The symbol library tables can be viewed or edited with PreferencesManage Symbol Libraries…​ in the Schematic Editor or Symbol Editor windows. The footprint library tables can be viewed or edited with PreferencesManage Footprint Libraries…​ in the Board Editor or Footprint Editor. Both library tables can also be accessed from the Project Manager.

symbol library table

Often, paths to libraries are defined with path substitution variables. This enables a user to move all of their libraries to a new location without modifying the library tables. The only thing that needs to change is to redefine the variable to point to the new location. KiCad’s path subsitution variables are edited with PreferencesConfigure Paths…​ in the Project Manager or any of the Editor windows.

One useful path substitution variable is ${KIPRJMOD}. This variable always points at the current project directory, so it can be used for including project-specific libraries that are stored inside the project directory.

On first run, KiCad prompts the user to set up the symbol library table and footprint library table. To go through this setup again, delete or rename the symbol library table or footprint library table files. Make a backup of the tables before deleting them.

The location of the symbol and footprint library table files depends on operating system.

  • Windows: %APPDATA%\kicad\6.0\sym-lib-table and %APPDATA%\kicad\6.0\fp-lib-table

  • Linux: ~/.config/kicad/6.0/sym-lib-table and ~/.config/kicad/6.0/fp-lib-table

  • macOS: ~/Library/Preferences/kicad/6.0/sym-lib-table and ~/Library/Preferences/kicad/6.0/fp-lib-table

Creating New Global or Project Libraries

The first step in drawing a new symbol or footprint is to choose a library in which to store it. For this guide, the switch symbol and footprint will go into new project-specific libraries.

Open the Symbol Editor from the Project Manager. Click FileNew Library, and select Project. Choose a name for the new library (e.g. getting-started.kicad_sym) and save it in the project directory. The empty new library is now selected in the Libraries pane at left, and has been automatically added to the project library table (check the Project Specific Libraries tab in PreferencesManage Symbol Libraries…​).

Creating New Symbols

Now create the switch symbol in the new library. With the getting-started library selected in the Libraries pane, click FileNew Symbol…​. In the Symbol name field, enter the part number: M2011S3A1W03. Switch symbols should have reference designators that start with SW, so change the Default reference designator field to SW. All other fields can remain as the defaults.

In the Libraries pane, the M2011S3A1W03 symbol now appears under the getting-started library. In the canvas, a cross indicates the center of the footprint, and text has been added for the symbol name and reference designator. For now, move the text away from the center of the footprint to get it out of the way.

Symbol Pins

Start drawing the symbol by adding a pin. Click the Add a pin button pin 24 on the right toolbar, then click on the canvas. The Pin Properties dialog will appear. Set Pin name to A, Pin number to 2, Electrical type to Passive, and Orientation to Right. Set X Position to -5.08 and Y Position to 0. Click OK, then click on the canvas to place the pin. If the pin moved after clicking OK, it might be necessary to edit the pin’s properties again (double click the pin, or right click on the pin → Properties…​) to set the position correctly.

pin properties

Add a second pin, but this time don’t use the Add a pin tool. Instead, press Insert. A new pin numbered 3 is added to the symbol, just below pin 2.

In many places in KiCad, pressing Insert will repeat the last action. The location of the new item will be shifted and the numbering incremented automatically, as applicable. In the Symbol Editor, this can be used to place a large number of pins quickly. In the Schematic Editor, it can be used to repeatedly place a component, or to label a large component’s pins with numbered labels. Insert can be useful in the Footprint and Board Editors as well.

Pin 3 will be on the right side of the switch symbol, so edit the properties of pin 3 and change X position to 5.08, Y position to 0, and Orientation to Left. Also, change Pin name to B.

Graphical Features

With the pins placed, use the circle add circle 24 and line add line 24 tools to make the symbol look like an SPST switch. For this step, it will be useful to switch to a finer grid: right click the canvas and select a smaller grid in the Grid submenu. After adding the graphical shapes, switch back to a 50 mil grid.

Small grids are useful for graphical features, but symbol pins must always be placed on a 50 mil (1.27 mm) grid. Pins which are not aligned to a 50 mil grid will not be able to connect to wires in the schematic.

symbol drawn

Symbol Properties

Now edit the properties for the whole symbol with FileSymbol Properties, or by double clicking on the canvas. Add spst switch toggle to the Keyword field to make it easier to find the symbol by searching. For this symbol, the pin names do not add any useful information, so uncheck Show pin name to make the symbol visually simpler.

symbol properties

The symbol is now complete. Save it and move on to creating a footprint.

Creating New Footprints

Open the Footprint Editor and create a new project-specific footprint library named getting-started.pretty (FileNew Library…​). As with symbol libraries, the new footprint library is added to the project library table. With the new library selected in the Libraries pane, create a new footprint (FileNew Footprint…​). Set the name to Switch_Toggle_SPST_NKK_M2011S3A1x03 and the type to Through hole.

Footprint Pads

The switch has two pins, numbered in the datasheet as 2 and 3, and spaced 4.7 mm apart. For ease of placement, adjust the grid to match the pad spacing. Click ViewGrid Properties…​ and change the User Defined Grid sizes to 4.7 mm. Switch to the user grid at the bottom of the Grid: dropdown in the top toolbar.

By convention, through-hole footprints have pin 1 located at (0,0) and are oriented with pin 1 in the top left. The SPST version of the switch does not have pin 1, so the footprint will leave (0,0) empty and place pads 2 and 3 at (0, 4.7 mm) and (0, 9.4 mm). Note that in KiCad’s default coordinate system, the positive Y-axis is oriented downwards.

Use the Add a pad tool pad 24 in the right toolbar to place a pad one grid division below the origin, which is (0, 4.7 mm). Press Escape to exit the pad tool, then double click on the pad to edit its properties. Change the pad number to 2 and verify that the position is correct. The switch pins are 1.17 mm x 0.8 mm, which gives a diagonal (maximum pin dimension) of 1.42 mm. Therefore set the X hole size to 1.42 mm + 0.2 mm = 1.62 mm, and the pad size to 1.62 mm + 2*0.15 mm = 1.92 mm to provide a sufficient annular ring.

pad properties

Now use the Add a pad tool again to place the other pad at (0, 9.4 mm). Notice that the pad number is automatically incremented and the properties including pad size and hole size are copied from the previous pad.

With both pads placed, the annular rings look slightly small. The switch will be easier to solder and mechanically more robust if the annular rings are made larger. Increase the annular ring thickness from 0.15 mm to 0.3 mm by editing pad 2 and changing the pad size to 1.62 mm + 2*0.3 mm = 2.22 mm. Do not change the hole size. Note that the pad size field accepts mathematical expressions, so 1.62+2*0.3 can be entered directly and will evaluate to 2.22 mm.

Many text boxes in KiCad support mathematical expressions, including unit conversions.

Make the same annular ring modification to the other pad as well. As a shortcut, right click on pad 2, click Push Pad Properties to Other Pads…​, and then click Change Pads on Current Footprint.

Footprint Graphics

A good footprint will have the exact part outline drawn on the fabrication layer (F.Fab), a slightly larger outline on the silkscreen layer (F.Silkscreen), and a courtyard (F.Courtyard) surrounding the entire footprint to prevent overlaps with other footprints.

Switch to the front fabrication layer by clicking F.Fab in the Layers panel at right. The fabrication outline should precisely match the physical dimensions of the part, which is 7.9 mm wide and 13 mm tall. Use the line add line 24, rectangle add rectangle 24, or polygon add graphical polygon 24 tools to draw the outline of the part as shown in the screenshot below. One way to precisely place the outline is to set the user grid as follows:

  • X grid: 7.9 mm

  • Y grid: 13 mm

  • X origin: 7.9 mm / 2 = 3.95 mm

  • Y origin: 4.7 mm - (13 mm / 2) = -1.8 mm

fab outline coordinates

Next, switch to the F.Silkscreen layer. The silkscreen outline should be just outside of the part outline, so the silkscreen lines are moved outwards from the fabrication drawing by 0.11 mm. The exact coordinates are shown in the screenshot below, and helpful grid settings are:

  • X grid: 7.9 mm + 2 * 0.11 mm = 8.12 mm

  • Y grid: 13 mm + 2 * 0.11 mm = 13.22 mm

  • X origin: 8.12 mm / 2 = 4.06 mm

  • Y origin: -1.8 mm - 0.11 mm = -1.91 mm

silk outline coordinates

Finally, select the F.Courtyard layer. The courtyard outline should surround the part with a 0.25 mm clearance.

Use a different strategy to draw this layer. Switch to a 1mm grid instead of the User grid, and draw a rectangle roughly surrounding the footprint. Double click on the rectangle to edit its properties, and enter the corner coordinates of the rectangle directly — they are shown in the screenshot below.

courtyard outline coordinates

After completing the outlines, position the text as shown below. The footprint is complete.

completed switch footprint

Kicad Library Conventions

To maintain high-quality symbol and footprint libraries, KiCad has a KiCad Library Conventions document, which is a set of guidelines for symbols and footprints. It is not necessary to follow these conventions for personal libraries, but they are a good starting point. Footprints and symbols in the official library are required to follow KLC. KLC is used as a basis for the symbol and footprint in this guide.

Add Switch to Schematic

Now that the footprint is complete, the switch symbol can be modified so that the matching footprint is used for it by default.

Go back to the symbol editor and open the switch symbol. Edit the Symbol Properties. Click in the Footprint field, then click the library book icon small library 16 that appears. Browse to the project footprint library and double click on the switch footprint. Save the symbol.

The switch footprint is now assigned to this symbol by default; the footprint does not need to be manually selected each time the symbol is added to a schematic.

switch footprint set as default for symbol

Open the schematic, add a new symbol, and select the new switch symbol. Wire it to connect or disconnect the LED and the battery.

Reannotate the schematic to set the switch’s reference designator to SW1. It isn’t necessary to manually choose a footprint for the switch, because the switch symbol already specifies a footprint. Run ERC to make sure that the modified schematic doesn’t violate any electrical rules.

schematic edited to include switch

Add Switch to Layout

Make sure the schematic is saved, then open the Board Editor to add the symbol to the layout. Update the PCB with the schematic changes using ToolsUpdate PCB from Schematic…​ and place the switch footprint onto the board as shown.

board with switch added, before routing

The ratsnest shows the new connections that need to be routed. Additionally, the connection between the battery and the resistor needs to be deleted.

First, delete the unneeded traces. Select one of the traces between the the battery and the resistor — it doesn’t matter which. Press U several times to expand the selection to include all the segments between the battery and resistor. Press Delete to remove the connection.

Route the new traces between the battery and the switch, and between the switch and the resistor. Press B to refill the zones.

Finally, re-run DRC to make sure the modified board doesn’t violate any design rules.

board with switch added, before routing

Linking Symbols, Footprints, and 3D Models

Symbols and Footprints

As described in the footprint assignment section, each symbol in the schematic needs to have a footprint assigned to it during the schematic entry process. The name of the footprint assigned to each symbol is stored in the Footprint field of the symbol’s properties.

footprint field in symbol properties

Symbols can specify a preselected footprint. Footprints do not need to be manually assigned to such symbols, because a footprint was chosen when the symbol was created. Users can override the preselected footprint during the footprint assignment process as normal. Defining a default footprint is a good idea for symbols that will usually or always have the same footprint assigned to it, for example a component which is only available in one package. The switch footprint was set as the default for its matching symbol.

Symbols can also specify footprint filters, which can be used to hide footprints that are incompatible with the symbol. For example, the 74HC00 symbol has footprint filters that result in only the applicable DIP and SO14 footprints being displayed in the assign footprints tool.

footprint filters for 74HC00

The KLC requirements for footprint filters contain some useful tips for effective footprint filters.

Footprints and 3D Models

3D models for components are stored in separate files. Filenames for the component’s 3D model(s) are saved in the footprint. Any number of 3D models can be added to each footprint. 3D model filenames, along with model scale, rotation, offset, and opacity, are set in the 3D Models tab of the Footprint Properties.

footprint 3D model properties

Both STEP (.step) and VRML (.wrl) 3D model formats are supported. STEP files are useful where dimensional accuracy is needed, while VRML files can be used for more visually attractive renders. Many footprints in KiCad’s library have associated 3D models; these models are provided in both VRML and STEP formats. Only one of the two models needs to be listed in the footprint (typically the VRML filename is given). KiCad can automatically substitute the STEP version when exporting a 3D model of the board for mechanical CAD purposes.

Not all footprints in KiCad’s library are provided with 3D models, but all footprints list a 3D model filename even if the 3D model does not exist. This is so 3D models can be added at a later date without needing to edit the footprint.

FreeCAD together with the StepUp Workbench are useful for creating component 3D models; they are used for many of the models in KiCad’s library. StepUp is used to generate STEP and VRML files with correct placement, scaling, and rotation.