Digital Electronics and Microcontrollers
Logic gates, counters and timing, and the hardware around a microcontroller.
Digital electronics works with two voltage levels, high and low, which makes it easy to design and very reliable. This guide covers the logic that sits behind every microcontroller (gates, flip-flops, counters, registers, logic families and timing) and then the hardware you build around a microcontroller: a clean supply, a reset circuit, a clock, GPIO limits, level shifting, the ADC input, I2C pull-ups and programming headers. It follows on from Electronics Fundamentals, and for the software side see Embedded Systems.
Start here: what do you need?
| I need to… | Go to |
|---|---|
| understand gates, truth tables and Boolean expressions | Digital Logic |
| count pulses, divide a clock, or store bits with flip-flops, counters and shift registers | Digital Logic |
| connect 5 V and 3.3 V logic together, or choose a logic family | Digital Logic |
| work out setup and hold times, propagation delay or maximum clock speed | Digital Logic |
| wire up a microcontroller: power, reset, crystal and decoupling | Microcontroller Electronics |
| drive an LED or read a button from a GPIO pin, with debounce and pull-ups | Microcontroller Electronics |
| choose I2C pull-up values, or add a level shifter to a bus | Microcontroller Electronics |
| connect an analog input to the ADC, or estimate battery life | Microcontroller Electronics |
A suggested order
Read the logic page first, then the microcontroller page, which applies it to a real board.
- Digital Logic: Gates and truth tables, logic families and levels, adders, multiplexers, flip-flops, registers and counters, timing, and interfacing logic chips to a microcontroller.
- Microcontroller Electronics: The hardware around a microcontroller: power and reset, crystals, GPIO limits, level shifting, pull-ups and debounce, the ADC, I2C pull-ups, programming headers and battery life.
Quick reference: formulas
| Topic | Formula | Page |
|---|---|---|
| Values of an N-bit number | 0 to 2N − 1 (8 bit: 255; 10 bit: 1023) | Digital Logic |
| Clock period | T = 1 ÷ f (16 MHz: 62.5 ns) | Digital Logic |
| Divide by 2N | an N-stage binary counter divides the clock by 2N | Digital Logic |
| Logic compatibility | VOH(min) > VIH(min) and VOL(max) < VIL(max) | Digital Logic |
| 5 V to 3.3 V divider | R1 = 1 kΩ, R2 = 2 kΩ gives 3.33 V | Microcontroller Electronics |
| Debounce time constant | τ = R × C (10 kΩ, 100 nF: 1 ms) | Microcontroller Electronics |
| I2C pull-up limit | Rmax = tr ÷ (0.8473 × Cbus) (100 kHz, 100 pF: 11.8 kΩ) | Microcontroller Electronics |
| Serial throughput (8N1) | bytes per second = baud ÷ 10 (115 200 baud: 11.5 kB/s) | Microcontroller Electronics |
| GPIO LED current | I = (VDD − Vf) ÷ R | Microcontroller Electronics |
Calculators
- 555 Timer Calculator: Frequency, duty cycle and pulse length of a 555 circuit.
- Voltage Divider and LED Resistor Calculator: Output of a divider with and without a load, and the resistor for an LED.
- RC Time Constant and Filter Calculator: Time constant, cutoff frequency, filter gain and charging times.
The other Electronics guides
- Electronics Fundamentals: The circuit basics every maker needs: Ohm’s law, resistors, capacitors, inductors, diodes, transistors and switches, with worked examples.
- Analog Circuits and Sensing: Op-amps, comparators and timers, and how to read, amplify and filter sensor signals: thermistors, RTDs, load cells and 4-20 mA loops.
- Power and Motor Electronics: Batteries and supplies, switching converters and thermal design, and driving DC motors, steppers, servos and solenoids.
- Design, Testing and Troubleshooting: Reading datasheets, keeping a design quiet, measuring a circuit, finding faults with flowcharts, and complete worked projects.
- PCB Design and Layout: schematic to layout, stack-up, routing, return paths and design checks.
FAQ
Can I connect a 5 V output to a 3.3 V input?
Not always. Many 3.3 V inputs are not 5 V tolerant, so use a divider, a level shifter or a tolerant part. See Microcontroller Electronics for the options and when each one is right.
Why does my input read random values?
A floating input picks up noise. Add a pull-up or pull-down resistor, or set the internal one in software.
Do I need a crystal?
Not for most projects: the internal oscillator is accurate to a percent or so. Use a crystal for USB, precise timing or fast serial links.
References
- Texas Instruments, Logic Guide and Logic Families application notes (SDYU001).
- NXP, I2C-bus specification and user manual (UM10204).
- Horowitz, P. and Hill, W., The Art of Electronics, 3rd ed., Cambridge University Press.
- Manufacturer datasheets and application notes for the parts you use: they give the limits, pinouts and example circuits.
Last reviewed: October 2026. Values are typical: check the datasheets of the parts you use, follow the electrical code for mains work, and do not work on live mains equipment unless you are qualified.
