Inputs from people
- Pushbuttons and toggle switches
- Numeric and matrix keypads
- Rotary encoders and knobs
- Touchscreens and touch sensors
- Microphones and other interactive sensors
Turn electronic states into information people can read, and turn human actions into reliable digital inputs. Explore displays, keypad scanning and interface design.
A human-machine interface (HMI) lets a person observe a system, provide commands and understand its response. A simple interface may use two LEDs and a pushbutton. A more capable one may combine a keypad, display, rotary encoder, touch panel, buzzer and status indicators.
Good interface design: the user should know what the system is doing, what input is expected, whether an action succeeded and how to recover from an error.
A seven-segment display contains seven LED bars, labelled a to g, arranged to form decimal digits. Many parts also include a decimal-point LED. Each segment is an LED and needs current limiting unless the display module already includes suitable resistors and drivers.
To display 8, all seven segments are ON. Different combinations form the other digits.
Common cathode: shared cathodes connect to ground; a segment lights when its anode is driven HIGH through a resistor.
Common anode: shared anodes connect to the positive supply; a segment lights when its cathode is pulled LOW through a suitable driver/resistor path.
Always identify the exact display pinout and common connection from its datasheet. Physical pin order is not universal.
| Digit | Segments ON | Hex pattern (gfedcba) |
|---|---|---|
| 0 | a b c d e f | 0x3F |
| 1 | b c | 0x06 |
| 2 | a b d e g | 0x5B |
| 3 | a b c d g | 0x4F |
| 4 | b c f g | 0x66 |
| 5 | a c d f g | 0x6D |
| 6 | a c d e f g | 0x7D |
| 7 | a b c | 0x07 |
| 8 | a b c d e f g | 0x7F |
| 9 | a b c d f g | 0x6F |
Bit order here is g-f-e-d-c-b-a, with bit 0 representing segment a. Drivers and libraries may use a different bit order or inverted logic.
A multi-digit display can share the a–g and decimal-point lines across digits. The controller enables one digit at a time, presents that digit's segment pattern, then rapidly moves to the next digit. Persistence of vision makes the sequence appear continuous when refresh is fast enough.
At each scan step, turn the previous digit OFF, update the segment bus, then enable the next digit. This avoids ghosting caused by changing segment data while a digit is still active.
Do not connect a bare display directly to GPIO pins without appropriate current limiting. A microcontroller pin is not a power driver. Use transistor stages or a driver IC when display current exceeds the controller's permitted limits.
This teaching model shows the segment pattern for each decimal digit. Select a digit and switch between common-cathode and common-anode conventions. It is a logical display model, not an electrical simulation of a particular display module.
A 4×4 matrix keypad contains 16 switches arranged at row/column intersections. Instead of wiring every switch to its own input, the controller drives or scans rows and reads columns (or vice versa). A pressed key electrically connects one row to one column.
Scanning one row at a time lets the controller identify the column connected by a pressed switch. A keypad library handles much of this scan process.
Keypad layouts and ribbon-cable pin order vary. Identify row and column connections with the module documentation or a continuity test before wiring.
A common 16×2 LCD can show 32 character positions. An I²C backpack reduces wiring to power, ground, SDA and SCL, but its address and pin mapping must be confirmed.
OLEDs can draw icons, graphs and custom layouts. Check controller type, resolution, interface, voltage and library support. Small displays may use I²C or SPI.
| Display | Good for | Considerations |
|---|---|---|
| LED indicators | Simple state and warnings | Limited information; use resistors and suitable drivers. |
| Seven-segment | Digits, timers, counters | Segment wiring, current, common type and multiplex refresh. |
| Character LCD | Text, menus, measurements | Character layout, contrast, backlight current and interface. |
| OLED / graphical LCD | Icons, graphs and richer menus | Resolution, controller, memory use, interface and update rate. |
Use the simulated keypad to enter a short message. The LCD view updates as you type. This demonstrates input events and display feedback; it does not emulate electrical scanning, bounce or a physical LCD controller.
Ready. Select keys to enter up to 16 characters.
Build a small local user interface: a 4×4 keypad accepts a four-digit demonstration code and a 16×2 I²C LCD provides prompts and feedback. This is a learning exercise in input handling, validation and display output, not a secure access-control product.
| Module | Pin | Arduino Uno |
|---|---|---|
| Keypad rows | R1, R2, R3, R4 | D9, D8, D7, D6 |
| Keypad columns | C1, C2, C3, C4 | D5, D4, D3, D2 |
| I²C LCD | VCC / GND | 5 V / GND (verify backpack rating) |
| I²C LCD | SDA / SCL | A4 / A5 on classic Uno R3 |
Uno R3 uses A4/A5 for I²C. Other boards may use different pins or logic voltages. Check your board and LCD backpack before connecting.
Install a compatible Keypad library and LiquidCrystal_I2C library. Many LCD backpacks use address 0x27 or 0x3F, but scan or verify the actual address. Library APIs differ; adjust the LCD initialisation calls if your chosen library uses a different interface.
#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char demoCode[] = "2580";
char entered[5] = "";
byte enteredLength = 0;
void showPrompt() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ENTER DEMO CODE");
lcd.setCursor(0, 1);
for (byte i = 0; i < enteredLength; i++) lcd.print('*');
for (byte i = enteredLength; i < 4; i++) lcd.print('_');
}
void clearEntry() {
enteredLength = 0;
entered[0] = '\0';
showPrompt();
}
void checkEntry() {
entered[enteredLength] = '\0';
lcd.clear();
lcd.setCursor(0, 0);
if (strcmp(entered, demoCode) == 0) {
lcd.print("DEMO ACCEPTED");
lcd.setCursor(0, 1);
lcd.print("Welcome!");
} else {
lcd.print("NOT A MATCH");
lcd.setCursor(0, 1);
lcd.print("Try again");
}
delay(1200);
clearEntry();
}
void setup() {
lcd.init(); // Some library versions use lcd.begin(16, 2)
lcd.backlight();
showPrompt();
}
void loop() {
char key = keypad.getKey();
if (!key) return;
if (key == '*') {
clearEntry();
} else if (key == '#') {
if (enteredLength == 4) checkEntry();
else {
lcd.setCursor(0, 1);
lcd.print("Need 4 digits ");
}
} else if (key >= '0' && key <= '9') {
if (enteredLength < 4) {
entered[enteredLength++] = key;
entered[enteredLength] = '\0';
showPrompt();
}
}
}The fixed code is visible in the example firmware for learning only. Do not use this sketch or a hard-coded PIN for a real lock, alarm, payment terminal or security system. Real systems need secure credential handling, rate limiting, tamper resistance and an appropriate threat model.
Extension challenges: add a menu with A/B navigation, show a sensor reading, add a buzzer confirmation, replace the LCD with an OLED, or use a rotary encoder. Keep input handling responsive and avoid long blocking delays in more advanced interfaces.
Explore these open lessons at your own pace. For personalised explanations, project-specific troubleshooting, guided practical training or masterclasses, EazyLife offers paid support tailored to your learning goals.
Free or sponsored lesson referrals may be available through active programmes; they are not guaranteed.