Where to find optical switches?

I have (had) extra keyboard and mouse buttons for my computer.
The switches turned bad after a few years. The membrane-click-push-buttons make bad contact and can not handle the mechanical stress. Micro-switches (with and without lever) bounce too much.

I want to use a ATmega32U4 and I want to start with good buttons that can deal with dust and mechanical stress for many years. It needs some travel distance, perhaps a few millimeters. I need about 10 of them.

Do they have a specific name ? When I search for it, then I can only find the IR slotted optocoupler.

At amazon, there is a a single optical keyboard switch for 26 euros at Amazon.nl. That is very expensive and I don't know if it is any good.

To be honest, I don't even know how they work. How can a optical switch be used with an Arduino ?

I would like to read your hints and tips.

30PCS for $11
[https://www.aliexpress.com/item/1005003011120575.html?

http://xahlee.info/kbd/keyboard_optical_switch.html

You may find more offers on Hall Effect Keyboard Switches or keyboards. Both optical and magnetic keys are expensive due to lack of continued demand.

And 10 pieces for 6 euros. That is better. But I can not just add a surface/cap that I can slam. I still needs some kind of mechanical thing, like a keyboard cap that is mechanically stopped. And I want to know how much current it needs. I'm still very far from knowing how to use them with an Arduino.

That is also a good option.
However, when I search for it, then I can only find these large buttons, I need a small depth, depending on how I will make it, I'm thinking of 10 mm depth maximum.

Just like other digital inputs.

[https://www.aliexpress.com/item/1005002715531208.html?

Wire them like this. They will work fine.

For good measure add debounce in the code too.

That is a low pass filter of 159 Hz. The main problem is the switch or button itself. The ones that I used are no longer reliable after many years.

I bought a used Razer Huntsman keyboard, it should arrive in two days. Then I will have enough optical switches to test. For example how strong a single switch is.

Today I got the Razer Huntsman keyboard. The "key" is just the mechanical part. The "switch" is the opto-coupler part, and that is soldered to the pcb and not attached to the mechanical part. If I want to use it, then I would have to cut out the pcb around the key and then find the copper traces to solder wires to. That is not possible.

I will continue the look for a good switch :sob:

By the way, the Razer Huntsman keyboard is an impressive piece of engineering, but they failed at a few points. The mechanical "click" is too strong and very loud and the keycap with the keyboard acts as a amplifier for the sound instead of dampening the sound.

These people have switches with IP 65/IP 67 options.

https://www.marquardt-switches.com/pushbutton-switches.html?&no_cache=1&tx_produktkatalog2_pi1[mode]=overview&tx_produktkatalog2_pi1[modifier]=0&tx_produktkatalog2_pi1[value]=1683&tx_produktkatalog2_pi1[pointer]=0&cHash=ec8e225efb4aa766d1101ae6e2e2e133

The industrial switches are too big.

I have decided to buy Cherry mechanical keyboard switches. They are good quality and easy to buy : https://www.reichelt.com/nl/en/keyboard-accessories-c8099.html