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 expressionsDigital Logic
count pulses, divide a clock, or store bits with flip-flops, counters and shift registersDigital Logic
connect 5 V and 3.3 V logic together, or choose a logic familyDigital Logic
work out setup and hold times, propagation delay or maximum clock speedDigital Logic
wire up a microcontroller: power, reset, crystal and decouplingMicrocontroller Electronics
drive an LED or read a button from a GPIO pin, with debounce and pull-upsMicrocontroller Electronics
choose I2C pull-up values, or add a level shifter to a busMicrocontroller Electronics
connect an analog input to the ADC, or estimate battery lifeMicrocontroller Electronics

A suggested order

Read the logic page first, then the microcontroller page, which applies it to a real board.

  1. 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.
  2. 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

TopicFormulaPage
Values of an N-bit number0 to 2N − 1 (8 bit: 255; 10 bit: 1023)Digital Logic
Clock periodT = 1 ÷ f (16 MHz: 62.5 ns)Digital Logic
Divide by 2Nan N-stage binary counter divides the clock by 2NDigital Logic
Logic compatibilityVOH(min) > VIH(min) and VOL(max) < VIL(max)Digital Logic
5 V to 3.3 V dividerR1 = 1 kΩ, R2 = 2 kΩ gives 3.33 VMicrocontroller Electronics
Debounce time constantτ = R × C (10 kΩ, 100 nF: 1 ms)Microcontroller Electronics
I2C pull-up limitRmax = 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 currentI = (VDD − Vf) ÷ RMicrocontroller Electronics

Calculators

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.