Rotary encoder
A KY-040 counted with an interrupt on CLK; press to reset.

The code
// KY-040 rotary encoder: an interrupt on CLK counts the detents; press it to reset.
const int CLK = 2;
const int DT = 3;
const int SW = 4;
volatile long count = 0;
void onClk() {
if (digitalRead(CLK) == LOW) count += digitalRead(DT) == HIGH ? 1 : -1;
}
void setup() {
pinMode(CLK, INPUT_PULLUP);
pinMode(DT, INPUT_PULLUP);
pinMode(SW, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CLK), onClk, FALLING);
Serial.begin(9600);
Serial.println("Turn the knob");
}
void loop() {
static long shown = 0;
if (digitalRead(SW) == LOW) count = 0;
if (count != shown) {
shown = count;
Serial.print("count:");
Serial.println(shown);
}
delay(5);
}
More like this

Keypad
A 4x4 keypad scanned with the Keypad library; each key on the serial port.
ArduinoArduino Uno

Rotary dial
An old phone’s dial: each digit counted from its pulses, a number built up on the serial monitor.
ArduinoArduino Uno

RFID door (RC522)
The MFRC522 library reads a card’s UID: the known card lights green, any other red. Click the reader to hold a card to it.
ArduinoArduino Uno