Security

Digital Electronics from the Ground Up: Building MOSFET Transistor Circuits

Electronics and circuit design are fascinating fields. With ICs, transistors, and other digital-logic components, you can design and build all kinds of electronic devices right at home. After all, as the saying goes, every man should plant a tree, build a house, and… learn to build digital circuits with MOSFETs!

I’m sure you can handle the first two projects on your own, but we’ll work through the last one together in this article. You’ll also learn (or refresh your memory) about signal types, the basics of Boolean algebra, and electronic components.

Today, anyone looking to build an electronic device can choose from a vast array of microcontrollers—from the ubiquitous Arduino platform, used for everything from pocket weather stations to small rockets, to industrial SIMATIC controllers.

What’s inside these controllers? For a programmer, it can be a complete mystery. If you’ve ever taken apart an electronic device and wondered, “How and why does it work? What do all these electronic components and chips actually do?” then this article is for you.

Theory

No technical discipline can do without theory. Circuit design is no exception, so before we dive into building digital circuits, let’s review the fundamentals.

Ones and Zeros

You’ve probably heard of binary code and seen the iconic “digital rain” from the equally iconic “Matrix.” In reality, computers and other computing devices don’t process streams of characters—they work with ones and zeros. That’s the essence of the binary system.

So why does microelectronics rely on these, at first glance, clunky and inconvenient numbers instead of the decimal system we’re all used to? Wouldn’t that be much easier for humans to work with?

What’s convenient for humans isn’t always convenient for computers. The reason lies in the very nature of zeros and ones. A binary system needs only two base states: logical one and zero—true and false, respectively. These states are easy to implement in hardware; for example, you can define a high voltage (HIGH) as 1 and a low voltage (LOW) as 0.

Another consequence of using binary is that computers perform logical operations using Boolean algebra—also called the algebra of logic. I’ll cover that a bit later.

Digital Wins!

There are two main types of signals: analog and digital. An analog signal varies continuously between a minimum and a maximum level, depending on the voltage supplied by the power source. A good example of an analog signal is the music coming out of your computer speakers. Speakers and other audio devices produce sound by vibrating a diaphragm (the moving element in a speaker). While music is playing, the electrical signal driving the diaphragm changes continuously. If you measured that signal with an oscilloscope, you’d see a waveform like this.

Analog signal waveform
Analog signal waveform

A digital signal is pulsed: its values switch abruptly between predefined levels. Using the binary system, we can represent a zero as the lowest possible voltage—0 V—and a one as the supply voltage, for example from a 9-volt battery. Thus, to transmit a binary number, you simply send the appropriate sequence of electrical pulses. For instance, the number 10101 (which is 21 in decimal) can be depicted as the following pulse sequence.

A number represented in a digital signal
A number represented in a digital signal

It’s much harder to transmit and process data using analog signals than digital ones. The difference between 0 and 1 is easy to detect, and digital signals are also more resistant to noise. These are the main reasons digital signaling has largely displaced analog in electronics.

Boolean Algebra

As promised, let’s break down some of the core operations of Boolean algebra—after all, the logic of electronic devices runs on them.

info

To illustrate how logic functions work in theory, truth tables are used; they clearly show the mapping between the original inputs and the resulting logical outputs.

NOT

The NOT gate is also known as inversion. If you’re familiar with the term, you’ve probably guessed that this operation “flips” the signal’s value. In Boolean algebra, an inverted signal is denoted with a bar over it. The truth table for this gate is very simple:

In logic circuits, the NOT operation is represented by this kind of gate.

NOT
NOT

AND

This logical AND block in computer science is called a conjunction and is denoted by & (sometimes by the multiplication sign *). For this gate, the output is 1 only when all its inputs are true. The gate symbol and its truth table are as follows.

AND
AND

Compared to inversion (NOT), the number of inputs has increased, which in turn increases the number of possible outcomes. The more input variables a logical operation has, the larger its truth table.

OR

In computer science, the OR operation (disjunction) is denoted by ∨ (sometimes + or ||). The output is 1 if at least one input is true.

OR
OR

NOR

A NOR gate is, as you might guess, an inverted OR. Its output is the result of an OR passed through a NOT gate. It produces a 1 only when all of its inputs are 0. In truth tables and Boolean algebra, NOR is denoted by a bar over the OR operation.

NOR
NOR

NAND

The NAND gate, like the previous one, is simply an inverted AND. It outputs 1 whenever at least one of its inputs is at logic 0. In formulas, NAND is written by placing a bar over the conjunction (AND) operator.

NAND
NAND

A few essential electronic components

Before we get to the transistors themselves, let’s talk about two essential components of any digital circuit: the resistor and the diode.

Resistor

The most commonly used component in electrical circuits is the resistor. You can think of a resistor as pure resistance. What is it used for? For example, if a circuit needs a specific current at a given voltage, you can use Ohm’s law to calculate the required resistance and place a fixed resistor in the appropriate spot. You can see the schematic symbol and the physical appearance of a fixed resistor in the photo below.

Resistor: circuit symbol and physical appearance
Resistor: circuit symbol and physical appearance

info

Ohm’s law is one of the fundamental principles of electricity. In circuit design and electronics, it’s commonly used to calculate the appropriate resistance for components in electrical circuits. The law is expressed as: R = U/I, where R is resistance, U is voltage, and I is current.

There are various types of resistors whose resistance changes under different conditions. A rheostat varies its resistance from zero up to a set maximum, a photoresistor changes with the level of illumination, and a thermistor— as you might guess— with temperature. But the one we’re interested in is the most common type: the fixed resistor.

A fixed resistor has no polarity, so its leads are interchangeable—there’s no difference in orientation or order when you wire it into a circuit. In the photo you may have noticed the colored bands on its body; they’re used to determine the resistor’s nominal resistance value.

If a resistor has four bands, the first two are the significant digits; if it has five bands, the first three are. The next band is the multiplier (a power of ten). The resistance can be in ohms (multiplier 10^0), kiloohms (10^3), megaohms (10^6), and so on. The last band indicates the tolerance in percent. The photo shows a table that decodes the values for each color.

Determining a resistor’s value by its color bands
Determining a resistor’s value by its color bands

You don’t need to determine the resistance value yourself by scanning a table for the right colors. There are ready-made calculators for that. Just select the number of bands and enter the colors.

Diode

A diode is essentially the electrical equivalent of a one‑way valve. Unlike a resistor, it has polarity, which matters. Its terminals (electrodes) are called the anode (+) and cathode (−). Current flows through a diode only from anode to cathode. If you connect it the wrong way around, no current will pass. The cathode is usually marked with a stripe on the diode’s body.

Diode: circuit symbol and physical appearance
Diode: circuit symbol and physical appearance

Speaking of diodes, we should also mention LEDs. This reliable, long‑lasting “bulb” works like a regular diode, conducting current only from anode to cathode, but it also emits light. One of the LED’s leads is longer—that’s the positive (anode). There’s also a notch/flat on the lens marking the cathode.

LED circuit symbol and physical appearance
LED circuit symbol and physical appearance

warning

Don’t rush to connect a diode or LED directly to a battery. If too much current flows through these components—more than they’re rated for—you can effectively create a short and risk a fire. To prevent that, add a resistor in series with the LED. For common discrete LEDs, the maximum allowable current is around 30 mA, and they’ll start glowing at just a few milliamps. In practice, if you’re using a 20 mA LED powered from 5 V, use a series resistor in the 150–360 Ω range.

So what is this “MOSFET,” anyway?

As you’ve probably gathered, the key component in our circuits is the MOSFET, also called a MOS transistor. There are many types of transistors, but this is the one that matters for us today. MOSFET stands for metal–oxide–semiconductor field‑effect transistor; the first three words make up the “MOS” part. These acronyms describe the device’s structure and the materials it’s made from.

The transistor is the basic building block of electronic circuits at every imaginable scale. It’s a device made from semiconductor materials that conducts electric current under certain conditions. Depending on those conditions, the current flowing through a transistor can increase or decrease—or shut off entirely.

MOSFETs come in two types—p-channel and n-channel.

Circuit diagrams of p‑channel and n‑channel MOSFETs
Circuit diagrams of p‑channel and n‑channel MOSFETs

If you look at the schematic symbol, you’ll see a field-effect transistor has three terminals: source, drain, and gate (in Russian: исток, сток, зат­вор). Put simply, a MOSFET works like an electronic switch: current flows between the source and drain not when you press a button, but when you apply the right voltage to the gate to turn the transistor on. When the gate voltage shuts the MOSFET off, the current stops flowing.

The letters n and p in transistor types indicate the semiconductor doping used to make them. The difference is this: an n‑channel transistor turns on with a voltage corresponding to a logic 1, while a p‑channel transistor turns on with a voltage corresponding to a logic 0.

Choosing the right transistor today is easy. A few decades ago, a hobbyist would have to sift through volumes of reference manuals just to identify a transistor type. Now you just read the part number off the package and plug it into a search engine. The first result will likely be the datasheet—a document with the technical specifications.

The main things we need from this document are a MOSFET or MOS marking (to confirm it’s the transistor we’re looking for) and the transistor’s pinout. Typically, the pins are labeled with their initials next to the leads in the device photo.

Finally—time to build some circuits!

You can build electrical circuits by soldering components onto a prototyping board, but that requires specialized tools and skills—without them, soldering can be hazardous. I may cover the finer points of soldering in a future article; today, we’ll assemble circuits on a solderless breadboard (also known simply as a breadboard).

Breadboards come in various shapes and sizes, but they all work on the same principle. Wires and component leads insert easily into the sockets and hold firmly. If you make a wrong connection, there’s no need to desolder anything—just move the lead to a different socket. Here’s what a typical small breadboard looks like, inside and out.

Exterior view and internal structure of a breadboard
Exterior view and internal structure of a breadboard

info

In English, breadboard literally means “bread-cutting board.” Long before modern prototyping and PCB tech, when components were much bulkier, early electronics hobbyists still wanted to build prototypes they could quickly assemble, reconfigure, and tear down. They came up with the idea of hammering nails into wooden cutting boards and wrapping component leads around the nails. Over time, breadboards stopped being actual bread boards, but the name stuck.

Building a MOSFET‑Based NOT Gate

We’ll start with the easiest circuit to build—the NOT gate. Since we’ve already covered the symbols for electronic components, it should be straightforward for you to assemble the circuit from its schematic, which clearly shows what connects where.

Here’s the list of components you’ll need for this circuit:

  • One P-channel MOSFET
  • One N-channel MOSFET
  • Two resistors, 150 to 360 ohms each
  • Two LEDs

Below you can see a basic inverter schematic that clearly shows how a NOT gate flips the signal.

Inverter schematic (NOT gate)
Inverter schematic (NOT gate)

An inverter uses both transistor types. The p-channel transistor is chosen to produce a logic “1” at the output because it can pull the node up with virtually no voltage drop, whereas the n-channel, in turn, pulls it down to a clean logic “0.”

If you add two LEDs to the circuit—one tied to the positive rail and the other to ground—you get an inverting setup: a low input yields a high output that lights the LED connected to ground, and vice versa.

Inverter 2
Inverter 2

When a logic high is applied, the upper p-channel transistor is off and the lower n-channel is on, so the output goes to 0 V. The circuit completes and the top LED lights up. When a logic low is applied, the p-channel MOSFET turns on, driving a solid logic high at the output.

The NOT gate built on a breadboard looks as shown in the photo.

Inverter probe on a breadboard
Inverter probe on a breadboard

MOSFET NOR Gate

The next simple circuit is OR-NOT (NOR). It will require twice as many transistors as the previous one:

  • Two P-channel MOSFETs
  • Two N-channel MOSFETs
  • A resistor in the 150–360 Ω range
  • An LED

The truth table is one of the key tools in circuit design. Looking again at the NOR truth table, we see that the output is high only when both inputs are logical zero. You can implement this condition by connecting two p-channel transistors in series, which, as we know, are excellent at pulling the output high. In this setup, if both transistor inputs are zero, current will flow through them. But if even one of them is off, current won’t be able to reach the circuit’s final output.

Series connection of p-channel MOSFETs
Series connection of p-channel MOSFETs

Looking at the truth table, we see that the output goes to logical zero whenever at least one input is at a high voltage level (HIGH). A device that turns on with a logic one and pulls the output to zero is naturally built with n-channel transistors. You can implement it by wiring two n-channel transistors in parallel, tying their drains together as the common output, and tying their sources together to ground (the negative supply). Thus, a logic one on any transistor gate turns it on, providing a path to ground and pulling the output low.

Parallel connection of n-channel MOSFETs
Parallel connection of n-channel MOSFETs

By combining the two previous circuits, we get a functional NOR gate implemented with MOSFETs.

NOR gate schematic
NOR gate schematic
NOR gate on a breadboard
NOR gate on a breadboard

NAND Gate Using Transistors

To assemble this circuit, we’ll need the same components as for the previous one.

Looking at the truth table, we see that the output goes high when at least one of the inputs is at logic 0. As we’ve already noted, the high output is driven by the p-channel transistors, and the “at least one” condition is implemented by connecting them in parallel.

A low logic level (LOW) appears at the output only when all of the gate’s inputs are HIGH. The low level is pulled down by n‑channel transistors, and the strict “only if all inputs are HIGH” condition is achieved by connecting those transistors in series.

In the end, by combining the two approaches, we get the following diagram.

NAND gate schematic
NAND gate schematic
NAND gate on a breadboard
NAND gate on a breadboard

OR and AND Gates with MOSFETs

If you compare the truth tables of NOR and OR, you’ll see their outputs are complements of each other. That means you can turn a NOR gate into an OR gate by adding a NOT gate to its output. The reverse also holds: you can just as easily get NOR from OR the same way.

By combining a NOR gate and an inverter, we get the following circuit.

OR gate schematic
OR gate schematic
OR gate on a breadboard
OR gate on a breadboard

Similarly, inverting a NAND turns it into a logical AND.

AND gate schematic
AND gate schematic
AND on a breadboard
AND on a breadboard

Conclusions

In this article, we walked through building the most basic building blocks of digital circuits. Of course, that’s only a small slice of the much broader field of electronics. The gates we covered can also have three, four, or even more inputs, which makes designing logic-element circuits by hand more complex. To wrap up, here are a few rules and tips for implementing digital logic gates with MOS transistors:

  • Using p-channel transistors, you build networks that drive the output high (logic 1) for the required combination of input signals.
  • Using n-channel transistors, you build networks that pull the output low for the required combination of input signals.
  • The strict condition “all inputs are at a specified voltage level” (AND) is implemented by connecting transistors in series.
  • The condition “at least one input is at the specified level” (OR) is implemented by connecting transistors in parallel.

By learning circuitry, you’ll be able to understand how modern electronics are built, get a better grasp of how your computer works, and demystify other things that seem complicated at first glance!

it? Share: