Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Building a NOT Gate in Simulation

Recommended resources

Hello! In our previous lessons, we established that a transistor can behave like an electronic switch and explored the fundamental laws of electricity—voltage, current, and resistance. This laid the groundwork for translating abstract binary logic into physical, functioning circuits.

Today, we'll take a significant step forward by combining these concepts to achieve our first concrete milestone in digital logic design. Our goal is to construct a basic logic inverter (NOT gate) using transistors in simulation. You're familiar with the logical NOT operator (!) from your experience with C programming; this lesson will show you how that operator is physically realized at the most fundamental hardware level. We will analyze the circuit, understand how it inverts a signal, and then interact with a simulation to see it in action.

The NOT Gate: Logic and Symbol

The NOT gate, or inverter, is the simplest logic gate. Its function is to output the opposite of its input.

  • If the input is HIGH (logic 1), the output is LOW (logic 0).
  • If the input is LOW (logic 0), the output is HIGH (logic 1).

This behavior is represented by a simple truth table and a standard symbol:

A common circuit for a NOT gate using an NPN transistor, along with its truth table. Input 'A' determines the state of the output 'OUT'.

The circuit shown in the image is a classic implementation of a NOT gate using a single NPN transistor. Let's break down how it achieves this inversion.


How the Transistor Inverter Works

The key to this circuit's operation lies in using the transistor as a switch that, when turned ON, creates a path to ground. The output of the circuit is measured at the transistor's collector. The resistor R2 is known as a pull-up resistor. Its job is to "pull" the output voltage up to a HIGH state when nothing else is pulling it down.

Let's analyze the two possible states for the input A.

Case 1: Input A is HIGH (Logic 1)

  1. A HIGH voltage is applied to input A.
  2. This voltage creates a small current that flows through resistor R to the base of the transistor T1.
  3. As we learned, this base current turns the NPN transistor ON.
  4. When the transistor is ON, it acts like a closed switch, creating a low-resistance path between its collector and emitter.
  5. Since the emitter is connected directly to ground (0V), the collector is now also effectively connected to ground.
  6. This "pulls down" the voltage at the OUT terminal to nearly 0V. Therefore, the output is LOW (Logic 0).

Case 2: Input A is LOW (Logic 0)

  1. A LOW voltage (or 0V) is applied to input A.
  2. There is no significant current flowing to the base of the transistor.
  3. The transistor remains OFF.
  4. When the transistor is OFF, it acts like an open switch; there is no connection between the collector and the emitter.
  5. The path to ground through the transistor is blocked. The only thing connected to the OUT terminal is the pull-up resistor R2, which is connected to the high voltage supply (+Vcc).
  6. Since no current is being diverted to ground, the OUT terminal's voltage is "pulled up" by R2 to +Vcc. Therefore, the output is HIGH (Logic 1).

In essence, the transistor doesn't produce the HIGH output; it simply "gets out of the way" and lets the pull-up resistor do its job. When the transistor turns ON, it actively overpowers the pull-up resistor and forces the output LOW.

The following video provides an excellent animated simulation of this exact process. Watching it will give you a dynamic, visual understanding of the signal inversion.

Bipolar Junction Transistors as Common-Emitter Switches - Circuit Simulation

This video by Kevin Patterson uses a circuit simulator with scope probes to clearly demonstrate the operation of a transistor inverter.

Please watch the section that specifically builds and explains the inverter circuit. Pay close attention to the scope plots at the bottom, which visualize how the output signal becomes the inverse of the input signal. The narrator also provides a great explanation of how the transistor pulls the output low and how the pull-up resistor brings it high, which you'll find in the subsequent analysis from this part of the video.


Simulating Your First Logic Gate

Now it's time to build and test this yourself. We'll use a web-based circuit simulator that lets you interact with the components directly in your browser. The following article provides a concise explanation and, most importantly, a link to a pre-built simulation.

Building &&, || and ! physically!

This article provides a clear, textual breakdown of how an inverter circuit works, complementing the video you just watched. We will use its embedded simulation to get hands-on experience.

First, read the section titled "Inverter" to review the truth table and symbol. Click on the "circuit simulation" link within that section to open the Falstad simulator with the NOT gate circuit already loaded. Now, experiment with the simulation: Observe the initial state: The switch on the left (the input) is open, representing a LOW input (Logic 0). Notice that the transistor shows no current flow, and the LED on the right (the output) is lit, representing a HIGH output (Logic 1). Toggle the input: Click the switch to close it. This provides a HIGH input (Logic 1) to the transistor's base. Observe the result: You will see current (yellow dots) flowing through the transistor to ground. The transistor has created a "short circuit" path that diverts current away from the LED, causing it to turn off. The output is now LOW (Logic 0). Toggle the switch back and forth to solidify the inverting behavior: Input LOW -> Output HIGH; Input HIGH -> Output LOW.

The circuit in this simulation uses an LED as a visual indicator for the output state. It perfectly demonstrates the principle: when the transistor turns ON, it creates a lower-resistance path to ground than the path through the LED, effectively starving the LED of current and turning it OFF.

This circuit diagram shows a practical implementation of a transistor inverter where a switch (SW) provides the input and an LED (D1) indicates the output state. Closing the switch turns the LED off.

Conclusion

Congratulations! You have now bridged the gap from discrete electronic components to a functional logic gate. By arranging a single transistor and a couple of resistors in a specific topology, you have physically (in simulation) implemented the Boolean NOT operation. This is a foundational skill for building every digital device that follows, including the CPU you've set out to create.

Here are the key takeaways from this lesson:

  • A NOT gate (inverter) outputs the logical opposite of its input.
  • It can be constructed from an NPN transistor, a base resistor, and a pull-up resistor.
  • A HIGH input turns the transistor ON, which actively pulls the output LOW by connecting it to ground.
  • A LOW input leaves the transistor OFF, allowing the pull-up resistor to passively pull the output HIGH.

You've taken a crucial step up the ladder of abstraction. We no longer have to think solely in terms of transistors, voltage, and current; we can now start thinking in terms of logic gates.

In the next lesson, we will build on this design to construct a NAND gate. The NAND gate is particularly special because it is a "universal gate," meaning we can construct any other logic gate (AND, OR, XOR, etc.) using only NAND gates. This will be our next major step toward building complex computational machinery.