Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
You can read 32 independent slide-switch inputs with an Arduino Uno by cascading four 74HC165 parallel-in, serial-out shift registers. The Uno uses only three signal lines: D9 for parallel load (latch), D13 for the shared clock, and D12 for serial data. The switches remain mechanical inputs—the circuit detects their states; it does not actuate them.
This implementation follows the 2022 Hackster project and its Wokwi simulation. Open the simulation at https://wokwi.com/projects/306024460940476993. The original project was published March 7, 2022, with code revisions dated August 2021: Hackster project page.
Why use four 74HC165 registers?
An Uno does not conveniently provide 32 spare GPIO inputs. A 74HC165 solves that by sampling eight parallel inputs, then shifting the captured bits out serially. Four devices provide 32 inputs while the Arduino handles one latch signal, one clock, and one data signal.
Free tools Windows power users keep installed
One-click scans. No signup required.
| Approach | Arduino lines | Main trade-off |
|---|---|---|
| One GPIO per switch | 32 inputs | Simple logic, but poor pin efficiency |
| Four 74HC165s | 3 signals | Low cost and transparent, with extra wiring and bit mapping |
| I²C GPIO expander | 2 bus lines | Cleaner bus interface, but different hardware and API |
| Matrix scanning | Fewer lines | More software complexity and possible ghosting |
| Multiplexer arrangement | Several lines | Usually selects channels rather than capturing 32 states at once |
The 74HC165 is an input device. Do not confuse it with the 74HC595, which is normally used for serial-in, parallel-out outputs.
#1 Best Overall
- START CODING WITH THE ELEGOO UNO R3: Connect the included USB cable, upload your first sketch, and build sensor, motor, display, and automation projects, making it a practical controller for maker desks, classrooms, coding clubs, and robotics labs
- ATMEGA328P CORE FOR EVERYDAY PROJECTS: A 16 MHz clock, 32 KB flash, 14 digital I/O pins with 6 PWM outputs and 6 analog inputs provide a versatile foundation for LEDs, buttons, relays, servos, displays and sensors
- RELIABLE USB PROGRAMMING AND CLEAR WIRING: The ATmega16U2 USB interface supports sketch uploads and serial communication, while clearly labeled headers help simplify connections to jumper wires, shields and modules
- POWER AND EXPAND YOUR WAY: Run the board from USB or a recommended 7-12 V external supply, then add compatible shields and modules for data logging, automation, robotics, test fixtures and custom electronics projects
- BOARD AND USB CABLE INCLUDED: Comes with 1 ELEGOO UNO R3 development board and 1 USB-A to USB-B data cable; breadboard, sensors, shields and power adapter are not included, and younger learners should work with an experienced adult
Parts and preparation
- Arduino Uno and USB cable
- Four matching 74HC165 shift registers (DIP packages are easiest on a breadboard)
- Thirty-two compatible slide switches
- One pull-up or pull-down resistor for every input
- Breadboard and jumper wires
- One 0.1 µF ceramic bypass capacitor close to each IC for a physical build
The original project lists a 74HC125, but its visible sketch does not use it. Treat that buffer as optional until the project schematic confirms an electrical role; it is not part of the minimum three-line software interface.
How the cascade works
Each 74HC165 captures eight logic levels when its parallel-load input is asserted. After the load pulse, clock edges move those bits toward the serial output. Connect the serial output of register 1 to the serial input of register 2, register 2 to register 3, and register 3 to register 4. Connect the final register’s serial output to Uno D12.
| Uno connection | Function | Connection on all four 74HC165s |
|---|---|---|
| D9 | Parallel load/latch | PL (often named parallel load) |
| D13 | Clock | Shared clock input |
| D12 | Serial data | Serial output of the final device |
| 5 V | Supply | VCC |
| GND | Reference | Common ground |
Each chip’s eight parallel inputs connect to one group of eight switches. Verify the exact pin numbers against the datasheet for your package before drawing or building a physical wiring diagram; the project page establishes the logical connections but does not provide a complete pin-number table.
Rank #2
- ATmega328P Microcontroller: Powered by the reliable ATmega328P, running at 16 MHz with 32KB of flash memory, 2KB SRAM, and 1KB EEPROM, offering ample resources for a wide range of basic to advanced electronics projects.
- 14 Digital I/O Pins & 6 Analog Inputs: Features 14 digital I/O pins (6 of which support PWM output) and 6 analog inputs (10-bit resolution), providing flexible options for sensors, motors, and other external components.
- USB Connectivity for Easy Programming: The built-in USB port allows for direct programming and serial communication, enabling a simple connection to your computer for sketch uploading and debugging through the Arduino IDE.
- Compatible with Arduino IDE: Full compatibility with the Arduino IDE ensures easy access to a vast array of libraries, code examples, and community-driven projects, making the Uno a great choice for both beginners and experienced makers.
- Widely Used in Education & Prototyping: The Arduino Uno is a standard in educational environments, widely used for learning and teaching electronics and programming. It's perfect for prototyping, robotics, IoT projects, and more.
Give every input a defined level
Use one polarity consistently. A straightforward arrangement connects one switch terminal to 5 V, the other to a 74HC165 input, and a resistor from that input to ground. An open switch therefore reads LOW and a closed switch reads HIGH. The opposite arrangement—switch to ground with a pull-up to 5 V—also works, but reverses the logic.
“Up” and “down” are mechanical labels, not electrical truths. In the original sketch, bit 0 is printed as down when it is zero and up when it is one; your switch orientation and resistor polarity may require the opposite interpretation.
Reproduce the Wokwi simulation
- Open the supplied Wokwi project.
- Confirm the Uno, four 74HC165 devices, switches, bias resistors, shared clock, and shared latch wiring.
- Start the simulation and open the serial monitor.
- Select 115200 baud.
- Move one switch at a time and verify that a single reported switch changes.
Simulation is useful for checking the cascade and code, but it cannot reveal every physical problem, such as a broken breadboard rail, missing bypass capacitor, incorrect IC orientation, or noisy long cable.
Rank #3
- Unlock your creativity with the versatile UNO R3 Board ATmega328P! Explore endless possibilities in electronics projects with its user-friendly Arduino development environment, extensive digital and analog I/O pins, and compatibility with various sensors and modules. Let your imagination soar!
- Experience the power of UNO R3 Board ATmega328P! This feature-packed development board boasts a high-performance ATmega328P microcontroller, 32KB of flash memory, and 2KB of SRAM. It's perfect for both beginners and advanced users seeking to build innovative applications in robotics, home automation, and more.
- Ignite your passion for electronics with the UNO R3 Board ATmega328P! Its open-source design allows for customization, while its 14 digital I/O pins and 6 analog input pins provide ample connectivity options. Get ready to bring your ideas to life and create interactive projects like never before.
- Elevate your DIY projects with the UNO R3 Board ATmega328P! This highly versatile development board offers seamless integration with the Arduino ecosystem, providing access to a vast library of code and resources. With its reliable performance and broad compatibility, you can easily prototype and realize your electronic dreams.
- Discover the endless potential of the UNO R3 Board ATmega328P! With its robust communication interfaces, including UART, SPI, and I2C, you can connect and communicate with a wide range of devices. Whether you're a hobbyist or a professional, this powerful development board is a must-have for creating innovative and interactive electronic systems.
Arduino code
The original implementation uses D9, D13, and D12, a 10-microsecond pulse width, and a 25-millisecond pause between scans. Those are practical example values, not universal timing requirements for every 74HC165 circuit.
const byte latchPin = 9;
const byte clockPin = 13;
const byte dataPin = 12;
const int pulseWidth = 10;
uint32_t oldOptionSwitch = 0;
byte readOne165() {
byte value = 0;
// Read the current bit, then clock to advance the register.
for (int bit = 7; bit >= 0; --bit) {
if (digitalRead(dataPin) == HIGH) {
bitSet(value, bit);
}
digitalWrite(clockPin, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(clockPin, LOW);
}
return value;
}
uint32_t readAll165() {
digitalWrite(latchPin, LOW);
delayMicroseconds(pulseWidth);
digitalWrite(latchPin, HIGH);
uint32_t value = 0;
for (int shift = 24; shift >= 0; shift -= 8) {
value |= ((uint32_t)readOne165()) << shift;
}
return value;
}
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
digitalWrite(latchPin, HIGH);
digitalWrite(clockPin, LOW);
Serial.begin(115200);
Serial.println("32-switch monitor");
}
void loop() {
uint32_t optionSwitch = readAll165();
for (int i = 0; i < 32; ++i) {
if (bitRead(optionSwitch, i) != bitRead(oldOptionSwitch, i)) {
Serial.print("Switch ");
if (i < 10) Serial.print(' ');
Serial.print(i);
Serial.print(" is now ");
Serial.println(bitRead(optionSwitch, i) ? "up" : "down");
}
}
oldOptionSwitch = optionSwitch;
delay(25);
}
The malformed i nt sometimes shown in a rendered copy of the original page must be corrected to int, as above.
What the read sequence does
- D9 goes LOW briefly, transferring all 32 input levels into the four registers.
- D9 returns HIGH, preserving that snapshot while it is shifted out.
readOne165()reads the current data pin first, then pulses D13 HIGH and LOW to advance one bit.- Four bytes are assembled into a
uint32_t, placed at bit offsets 24, 16, 8, and 0. - The new snapshot is compared with the previous one, so the monitor reports transitions instead of printing all 32 states continuously.
The manual reader is intentional. In this timing convention the data bit must be sampled before the clock transition. Arduino’s shiftIn() is not inherently incompatible with every 74HC165 design, but its selected clock mode and sampling order must match your circuit; the original implementation avoids that mismatch by controlling both operations explicitly.
Rank #4
- START CODING WITH A FLEXIBLE UNO R3 BOARD: Connect the included USB cable, upload sketches with Arduino IDE and build sensor, motor, display and automation projects for maker desks, classrooms, coding labs and electronics prototyping
- ATMEGA328P CORE FOR EVERYDAY PROJECTS: A 16 MHz clock, 32 KB flash, 2 KB SRAM, 1 KB EEPROM, 14 digital I/O pins with 6 PWM outputs and 6 analog inputs support LEDs, buttons, relays, servos, displays and sensors
- CH340C USB-TO-SERIAL INTERFACE: The onboard CH340C handles USB communication for sketch uploads and serial monitoring, while clearly labeled digital, analog and power headers help simplify wiring to modules and shields
- USB OR EXTERNAL POWER: Run the board from the included USB cable or a recommended 7-12 V external DC supply, then expand with compatible shields and modules for robotics, data logging, automation and custom embedded projects
- BOARD AND USB CABLE INCLUDED: Comes with 1 ELEGOO UNO R3 controller board and 1 USB-A to USB-B data cable; breadboard, jumper wires, sensors, shields and power adapter are not included
Bit order and switch numbering
The first byte received is assigned to the highest byte of the 32-bit value. The displayed number therefore depends on chain direction and wiring. It is not a universal physical map.
| Displayed range | Visual/register group | Bit positions |
|---|---|---|
| 0–7 | One eight-switch group | Depends on chain orientation |
| 8–15 | Second group | Depends on chain orientation |
| 16–23 | Third group | Depends on chain orientation |
| 24–31 | Fourth group | Depends on chain orientation |
To calibrate a new layout, print the raw value in hexadecimal, move exactly one switch, note the changed bit, and create a physical-to-logical table. If the circuit is correct but labels are reversed, change the software mapping or display text rather than rewiring everything.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteDebouncing and physical reliability
The 25 ms delay reduces repeated reports and gives contacts time to settle, but it is not a complete debounce strategy for every switch. For critical controls, require the same sampled state for several consecutive scans before accepting a transition.
Best Value
- TURN CODE INTO REAL-WORLD RESULTS — Follow 22+ guided lessons to make LEDs blink, read temperature and distance, move servo and stepper motors, control an LCD and respond to joystick or IR input; ideal for a family weekend build, homeschool unit, coding club or STEM classroom
- MORE PROJECT VARIETY IN ONE ORGANIZED KIT — Includes the UNO R3 controller, LCD1602 with pre-soldered header, breadboard power module, ultrasonic and DHT11 sensors, joystick, IR receiver and remote, SG90 servo, stepper motor, relay, DC motor, fan blade, displays, LEDs, buttons, resistors and jumper wires
- START WITHOUT SOLDERING — Plug-in modules, a solderless breadboard and the pre-soldered LCD help beginners focus on wiring, code and testing; the illustrated component list makes it easier to find each part and move from one lesson to the next
- LEARN THE LOGIC, THEN CREATE YOUR OWN — Use Arduino IDE and the included example code to understand digital input and output, analog sensing, timing, motor control and display functions, then change thresholds, speeds and sequences for alarms, environmental monitors, reaction games and motion projects
- CLEAR SETUP SUPPORT FOR FIRST-TIME BUILDERS — Download the latest tutorial and code, select the UNO board and correct computer port, check component polarity and breadboard rows, and keep power-module input at 9V or below; younger learners should work with an experienced adult
- Use pull-up or pull-down resistors so no input floats.
- Keep clock and latch wires short and orderly.
- Place a 0.1 µF bypass capacitor near each 74HC165.
- Use a common, low-impedance ground.
- Add hardware filtering or software state qualification for noisy or long-distance wiring.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No serial output | Wrong baud rate, power, ground, or sketch | Select 115200; verify USB, 5 V, GND, and upload. |
| Only eight switches respond | Broken serial cascade or an unpowered IC | Test one register, then add devices one at a time; verify every serial link. |
| All states appear reversed | Opposite switch polarity or orientation | Check the bias arrangement and invert only the displayed interpretation if wiring is correct. |
| Random changes | Floating inputs, bounce, noise, poor contacts | Add bias resistors, bypass capacitors, shorter wiring, and debounce filtering. |
| Every input is stuck HIGH or LOW | Missing common ground, wrong supply, or incorrect switch wiring | Check VCC/GND at every IC and trace one input with a meter. |
| Unexpected changes on the first scan | oldOptionSwitch starts at zero |
Expected behavior; optionally use the first reading to initialize the baseline. |
shiftIn() gives wrong bits |
Clock edge or sampling order does not match | Use the manual reader or select a mode verified for your exact timing. |
| Wokwi works, breadboard fails | Physical wiring, orientation, rails, decoupling, or signal integrity | Verify package orientation and power pins; add local capacitors and shorten connections. |
When to choose another architecture
Four 74HC165s are a good fit when human-speed digital inputs, low cost, and a transparent serial snapshot are more important than integrated configuration. Consider an I²C or SPI GPIO expander when you want register-based configuration, built-in input features, or a tidier bus. A matrix can reduce chip count but needs scanning logic and careful ghosting control. Direct GPIO on an Arduino Mega is electrically simpler when pin count is no longer constrained. A 74HC595 is for expanding outputs, not for replacing these input registers.
Project references
The original implementation, component notes, and source code are documented at Hackster.io. The associated simulation is Wokwi project 306024460940476993.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

