Rotary Dialer Reference
A vintage rotary telephone dial mechanism. Dialing a digit rotates the dial, then it springs back, generating a number of electrical pulses on PULSE equal to the dialed digit (1 pulse for "1", ..., 10 pulses for "0").
Pin names
| Name | Description |
|---|---|
| GND | Ground |
| DIAL | HIGH while the dial is off its rest position (being turned or returning) |
| PULSE | Pulses once per dialed unit as the dial returns to rest |
Attributes
This component has no configurable attributes.
Usage
Connect GND to GND, and both DIAL and PULSE to GPIOs configured with
INPUT_PULLUP. Count PULSE transitions while DIAL is HIGH (the dial is in motion);
when DIAL goes back LOW, the pulse count is the dialed digit.
const int DIAL_PIN = 2;
const int PULSE_PIN = 3;
int pulseCount = 0;
bool wasDialing = false;
void setup() {
pinMode(DIAL_PIN, INPUT_PULLUP);
pinMode(PULSE_PIN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool dialing = digitalRead(DIAL_PIN) == LOW;
if (dialing) {
static bool lastPulse = HIGH;
bool pulse = digitalRead(PULSE_PIN);
if (pulse == LOW && lastPulse == HIGH) pulseCount++;
lastPulse = pulse;
wasDialing = true;
} else if (wasDialing) {
int digit = (pulseCount == 10) ? 0 : pulseCount;
Serial.print("Dialed: ");
Serial.println(digit);
pulseCount = 0;
wasDialing = false;
}
}
Examples
| Description | Attrs |
|---|---|
| Default rotary dialer | {} |
See also
- Membrane Keypad — modern alternative for numeric input
- KY-040 Rotary Encoder — another mechanism reporting rotation via pulses