Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
Tubular key switch with metal mounting body and supplied keys

Adding Key-Controlled Setup Mode to an Electronics Project

A key switch can make an electronics project easier to manage in a shared workshop. Everyday users can operate the project, while someone with the key can enter setup and change its calibration or operating preferences. The useful feature is a deliberate physical action with a clear meaning.

The PMD Way 12 mm tubular key switch is one example in the key switch collection. The listing identifies a 12 mm mounting hole and includes two keys. Before designing around it, verify the supplied switch’s contact arrangement and the positions in which its key can be removed.

This guide uses a low-voltage classroom display as the example. The key permits editing a display setting; it does not isolate hazardous power or authenticate an individual person.

Separate permission from the action itself

Turning the key should have one clearly defined meaning. For the display example, it enables access to a setup menu. A separate save action commits a new setting. This avoids changing a stored value merely because the key was turned during cleaning or demonstration.

Write the intended interaction in plain language: “Turn the key to setup, choose a value, then press save.” Also define cancellation: “Turning the key back before saving discards the pending edit.” These statements become testable requirements.

A mechanical key is a physical access control, not proof of who used it. Keys can be shared, duplicated or left in the switch. If a project needs individual accountability, a simple key input does not provide that information by itself.

Check key removal and contact positions

Key removal behaviour is part of the switch specification. Some mechanisms allow removal in multiple positions; others retain the key in a selected position. The NKK CK-series keylock documentation illustrates how circuit arrangements and key-removable positions are specified separately. It is a reference for those distinctions, not the datasheet for the PMD Way example.

With the switch unpowered and disconnected, identify its terminals from the correct documentation. Measure continuity in each stable position and record the result. Check whether any position is momentary and returns when released.

Try key insertion and removal gently in the permitted positions. Do not force a key or assume that removal automatically means “disabled”. If the key can be removed while the contacts remain in setup, the software cannot infer key presence from those contacts alone.

Read a suitable contact as a logic input

For a verified dry-contact circuit suitable for the required small signal, a pull-up input with the switch closing to the controller’s ground is a common arrangement. Arduino’s official InputPullupSerial example shows that an open contact reads HIGH and a closed contact reads LOW in that arrangement.

Confirm the host’s input voltage, pull-up behaviour and any shared-ground requirements. Do not put the switch’s advertised load voltage onto a microcontroller pin. A contact’s maximum rating is not the voltage required to read it.

Check minimum-load suitability as well as maximum ratings. Omron’s switch guidance explains that contacts intended for larger loads can be unreliable at very small currents. A successful continuity check does not establish long-term microload performance. Obtain appropriate contact information before choosing the final switch and interface.

Turn contact readings into a stable permission

Mechanical contacts can change several times during an operation. Use debouncing to distinguish the intended stable position from transitional readings. Arduino’s debounce example demonstrates checking stability over time.

For this display project, keep three ideas separate: the raw electrical reading, the accepted switch position and the permission to edit. That separation makes troubleshooting easier. A diagnostic page can show the raw reading while the user interface follows the accepted state.

Choose the stability interval from the actual switch and desired response. Do not apply a long delay that prevents the application from responding to other controls. The appropriate treatment of a hazardous enable function would need a separate safety design.

Define the setup states before writing the menu

Example permission rules for a classroom display
State Allowed behaviour Exit condition
Normal operation Show the saved setting; editing unavailable Stable setup request and deliberate menu entry
Editing Change a temporary candidate value Save, cancel or withdrawal of permission
Saving Validate and commit the candidate Confirmed success or visible error
Setup ready Show saved result without repeating the write New edit or return to normal operation

Check permission again when processing save, rather than only when opening the menu. This matters if the key changes position while someone is editing. Reject values outside the permitted range and keep the previous valid setting if the save cannot be completed.

Show a clear confirmation only after the operation succeeds. “Saved” should mean the setting has actually been committed, not merely that the save button was pressed.

Choose reset behaviour deliberately

Decide what happens if the controller restarts while the switch remains in setup. For the example, startup can show normal operation and require a fresh deliberate menu entry before editing. The retained switch position can make setup available without automatically starting an edit or rewriting storage.

Do not store a temporary permission flag as though it were a permanent user preference. Restore the saved display value, then evaluate the present input and the startup policy. A power interruption should not resurrect an unfinished edit.

If settings are stored in non-volatile memory, write when a confirmed change is committed, not on every pass through the program. Keep storage integrity and input permission as separate parts of the design.

Test the awkward sequences

Check ordinary entry, cancellation, save and key removal. Then test turning the key during editing, restarting in each position, holding another button during startup and disconnecting the input lead with power removed before restarting.

A pulled-up input may interpret an open wire as the open-contact state, but a short to ground can imitate a closed contact. This illustrates why a single hobby input should not be described as tamper-proof or a safety interlock.

Mount the switch so it cannot rotate in the panel, provide clearance for the key and label the positions from the operator’s viewpoint. Keep the contact map and permission rules with the project. The result is a configuration interface whose behaviour remains understandable even when a session is interrupted.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat