⚡ MAGNETIC CLICKER / v0.7
RP2040-Zero • Three magnetic keys • Beginner-friendly

Let's build the clicker.

Follow the steps in order. Start with one key on the breadboard. Only solder the final device after the tests work.

1 Gather these parts

Illustration of RP2040-Zero
RP2040-Zero
1 board · USB keyboard brain
Illustration of Magnetic switches
Magnetic switches
3 keys · no electrical contacts wired
Illustration of 49E Hall sensors
49E Hall sensors
3 + spares · analog magnetic readings
Illustration of Breadboard
Breadboard
1 · temporary connections
Illustration of Jumper wires
Jumper wires
Male/female as your headers require
Illustration of 0.1 µF capacitors
0.1 µF capacitors
3 · optional local decoupling
Illustration of USB-C data cable
USB-C data cable
To a MacBook or other computer
Illustration of Multimeter
Multimeter
Check 3.3V and shorts
See optional parts (RGB, OLED, case and soldering tools)
Illustration of RGB LED ring
RGB LED ring
Optional 7-pixel experiment
Later / optional
Illustration of OLED screen
OLED screen
Optional click counter/animation
Later / optional
Illustration of 3D-printed case
3D-printed case
Later, after the breadboard works
Later / optional
Illustration of Soldering iron
Soldering iron
Teacher only, for permanent wiring
Later / optional
Before you plug anything in: The 49E sensor's three pins must be verified on your exact batch. The illustrations here help identify parts; the connection diagram is the wiring reference. Soldering and first power checks are teacher-supervised.

2 Program the RP2040

Use a MacBook Air, a USB-C data cable, and the Waveshare RP2040-Zero.

  1. On the Mac, open Apple menu → About This Mac. Note whether it says Intel or Apple M1.
  2. Install Thonny (the correct macOS version for the Mac).
  3. Download the Waveshare RP2040-Zero CircuitPython .uf2 file from circuitpython.org.
  4. Hold the RP2040's BOOT button while plugging in USB. Release BOOT. Finder should show RPI-RP2.
  5. Drag the downloaded .uf2 onto RPI-RP2. After reboot, Finder should show CIRCUITPY.
  6. In Thonny, choose the CircuitPython (generic) interpreter if needed. Create the program below and save it to CIRCUITPY/code.py.
import time
print("Hello from the clicker!")
while True:
    print("Still running...")
    time.sleep(1)
Check: The message appears in Thonny's Shell/serial console about once per second. If CIRCUITPY doesn't appear, check the cable is a data cable and try BOOT again.

3 Wire ONE magnetic sensor

Unplug USB first. This poster shows the actual RP2040-Zero pad order, a recognizable switch with its sensor underneath, and the three sensor wires.

Illustrated wiring poster with RP2040-Zero, one large magnetic switch and Hall sensor example, plus keys 2 and 3
49E sensor leadConnect to RP2040Meaning
1 — VCC3V3 (red rail)Sensor power, 3.3 volts
2 — GNDGND (ground rail)Return / ground
3 — VOUTGP26Analog reading for Key 1
  1. With USB unplugged, connect RP2040 3V3 and GND to separate breadboard rails.
  2. Place the sensor so its three leads occupy separate, unconnected rows. Identify pins with the flat front facing you, only after the teacher confirms your sensor's marking and datasheet.
  3. Connect VCC → 3V3, GND → GND, VOUT → GP26. Optionally place a 0.1 µF capacitor between VCC and GND, near the sensor.
  4. Teacher checks for a short between 3V3 and GND with the multimeter before reconnecting USB.
Important: The magnetic switch itself needs no electrical wire. Keep its magnet directly above the sensor while testing, but do not assume the correct distance or sensor orientation until the readings confirm it. Never connect the Hall sensor or ADC pins to 5V.

4 Watch the magnet move

Save this program over CIRCUITPY/code.py, then open the serial output in Thonny.

import time
import board
import analogio
sensor = analogio.AnalogIn(board.GP26)

while True:
    print("Key 1 reading:", sensor.value)
    time.sleep(0.1)
  1. With the switch sitting securely above the sensor, write down the reading when it is not pressed.
  2. Press fully and write down the new reading. It may go up or down depending on magnet polarity and sensor orientation.
  3. Repeat a few times. If the values hardly change, reposition the sensor and switch; disconnect USB before changing wiring.
Write down your readings:

Key 1 — released __________ · pressed __________ · sensor marking __________

If the sensor output stays pinned close to 0 or maximum, stop and inspect wiring and orientation.

5 Add Keys 2 and 3

Unplug USB. Add two more Hall sensors. All three share the 3V3 and GND rails, but each sensor gets its own analog signal wire.

KeyVCCGNDVOUT
13V3GNDGP26
23V3GNDGP27
33V3GNDGP28
import time, board, analogio
sensors = [analogio.AnalogIn(p) for p in
           (board.GP26, board.GP27, board.GP28)]
while True:
    print([s.value for s in sensors])
    time.sleep(0.1)
Check: Press Key 1, 2, or 3 and watch only the matching reading change. Record the released and fully pressed values for each key.
ReleasedFully pressed
Key 1____________________
Key 2____________________
Key 3____________________

6 Turn it into a USB keyboard

Download the CircuitPython library bundle matching your installed CircuitPython major version. Copy the adafruit_hid folder into CIRCUITPY/lib/ (create lib if missing).

Enter your six measured values into the RELEASED and PRESSED lists below. This code works whether your sensor readings increase or decrease when pressed.

import time, board, analogio, usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

sensors = [analogio.AnalogIn(p) for p in
           (board.GP26, board.GP27, board.GP28)]
keys = [Keycode.Z, Keycode.X, Keycode.C]
keyboard = Keyboard(usb_hid.devices)

# REPLACE these examples with YOUR six readings.
RELEASED = [30000, 30000, 30000]
PRESSED  = [45000, 45000, 45000]
held = [False, False, False]

while True:
    for i, sensor in enumerate(sensors):
        span = PRESSED[i] - RELEASED[i]
        if abs(span) < 1000:
            continue  # Reposition/calibrate this sensor.
        travel = (sensor.value - RELEASED[i]) / span
        if not held[i] and travel >= 0.55:
            keyboard.press(keys[i])
            held[i] = True
        elif held[i] and travel <= 0.35:
            keyboard.release(keys[i])
            held[i] = False
    time.sleep(0.005)

Save as CIRCUITPY/code.py. Open a blank text editor and test one key at a time. Expected keys: Z, X, C. If a key appears held down, unplug USB and check your calibration values.

Prototype test only: This code uses two fixed actuation thresholds, not true Rapid Trigger; the 5 ms sleep also means it does not prove 1,000 Hz performance. Fast gaming firmware is a later optimization once the wiring works reliably.

7 Build the printed case

No custom PCB is required. The final enclosure must hold the Hall sensors still relative to the switches, and it should leave enough space for protected solder joints.

Optional: lights and display

Complete the three-key test first. These are short experiments using parts you already bought.

Built-in RGB LED · easiest

No extra wires. The board already has one programmable LED on GP16. Copy the matching neopixel.mpy library to CIRCUITPY/lib/.

import board, neopixel
light = neopixel.NeoPixel(board.GP16, 1,
                         brightness=0.10)
light[0] = (0, 90, 255)

0.96" OLED display

Once the module's labeling is checked, connect VCC→3V3, GND→GND, SDA→GP4, SCL→GP5. Then run an SSD1306 CircuitPython example. Use it for a click counter or animated face.

WS2812B seven-pixel ring

Power and logic levels must be verified before connecting. For a 5V-powered ring, use a suitable 3.3V-to-5V LED data shifter; the purchased TXS0108E/TXB0108 boards are not automatically validated for WS2812B signals. See NeoPixel wiring guidance.

Future knob

Possible later, using an encoder module and spare GPIO pins. We are not adding this to the first breadboard test.

Help & teacher checks

My Mac does not show CIRCUITPY.

Use a USB cable that supports data; enter BOOT mode again; check Finder; flash the correct Waveshare RP2040-Zero .uf2.

The sensor reading does not change.

Unplug USB and check pinout, 3.3V and ground, each lead on an independent row, switch magnet position, and sensor orientation. A 49E output normally sits near the middle of the 3.3V supply away from magnets, but it is not guaranteed to travel the whole 0–65535 scale.

The keyboard types continuously.

Unplug USB. Check that RELEASED and PRESSED are not reversed accidentally and that all three keys return near their released readings. Recalibrate. Do not test keyboard HID code inside sensitive forms.

What must the teacher prepare?

If the RP2040-Zero boards arrive without headers, solder a suitable header/wire adapter so the board can connect to the breadboard. Confirm the exact sensor marking/datasheet and pin order. Check for shorts with a multimeter. Have the correct CircuitPython and library bundle ready on the Macs before class.