Building &&, || and ! physically!
Back in high school I found out about Raspberry Pi while browsing the internet. I was amazed that a computer could fit in such a small form factor. The appeal of the size and the fascination that I could have another computer made me beg my parents to buy one for me.
Raspberry Pi was in some way my introduction to Electronics and Linux. I made several projects with it like Drum Machine using push buttons, Timelapse Camera, Radio Transmitter etc. as well learned stuff about like command line, bash and linux.
Over time I stopped experimenting with electronics and my interest in it faded. Recently, I came across this video about creating Logic Gates using Transistors and I just wanted to try to build these myself!
I decided to build some of these circuits on perfboard - NOT, AND and OR Gate. Here’s the result -
Another reason I wanted to build this was that I wanted to hold something that I use almost everyday as a programmer physically!
Before talking about these circuit, let’s talk about the component that makes all of this possible, the transistor.
What is a Transistor ?
A transistor is an electronic component that is used as switch to control electronic circuits or amplify electric signals. There are various types of transistors, the one we are using for these circuits are called BJT (Bipolar Junction Transistors)
BJT are of two types - NPN and PNP. Here is an image of NPN transistor -
BJT transistors have a outer shell with 3 metal legs, reading from left to right while facing the flat surface towards our face they are called -
Emitter
Base
Collector
Here’s how we represent a BJT in an electric circuit -
Each transistor has a serial number printed on it that can be used to find its - datasheet - which tells you things like the voltage range it can handle and how to use it correctly. The one used here is the 2N2222A.
Let’s see how this transistor works as a switch in an electric circuit. In a circuit we connect the negative end of the power supply to the Emitter and the positive end to the Collector. Initially, no current flows between them but when we apply a positive voltage to the Base above a certain threshold, current starts flowing from Collector to Emitter. This way by applying a positive voltage to the base we can control the flow of the current in a circuit.
Here’s a circuit simulation, notice how there is no flow of current between Collector and Emitter when the voltage below 0.7V is applied to Base and how it increases as we raise it above 0.7V -
We have glossed over a lot about transistors like what kind of material they are made of, what is inside NPN transistors, how does applying a voltage to Base allows current to flow from Collector to Emitter etc, to find out answers to these questions I would recommend to watch the following video -
Let’s now connect a LED to this transistor on a perfboard!
Buffer
Buffer is a circuit in which when the input is ON the output is ON and when the input is OFF the output is OFF.
Here’s the Symbol and Truth Table for the buffer circuit -
Let’s look at the circuit simulation for this circuit
In the above circuit, we have connected the Collector to the positive end of the battery and Emitter to the positive end of the LED with a resistor. The Base connects to the positive end of the battery with a 1M Resistor and a switch. When we toggle the switch, a small current flows into the Base, which turn on the transistor and allows the current to flow from the Collector to Emitter lighting the LED.
Notice that the Base current alone isn't what lights the LED. It's just the trigger. The actual current powering the LED flows from Collector to Emitter once the transistor is switched on.
Here’s the circuit on the perfboard -
Inverter
Inverter or NOT Gate is a circuit in which when the Input is OFF the Output is ON and when the Input is ON the Output is OFF.
Here’s the Symbol and Truth Table for the NOT Gate -
Let’s look at the circuit simulation for this circuit -
In the above circuit, we have connected the Emitter to the negative end of the Battery and the Collector at a junction between the positive end of the battery and the positive end of the LED. The Base is connected to the positive end of the battery with a resistor and a switch.
Initially the LED is ON because the current flows from Battery Positive → LED → Battery Negative. When we turn the Transistor ON by toggling the switch connected to the Base the current now also flows through Battery Positive → Collector → Emitter → Battery Negative.
As there is less resistance across the Collector → Emitter path most of the current now flows through it, this decreases the the voltage across the LED below the minimum voltage required to light it up and the LED is turned OFF.
Here’s the circuit on the perfboard -
AND Gate
AND Gate is a circuit in which when both the Inputs are ON then only is the Output is ON.
Here’s the Symbol and Truth Table for the AND Gate -
Let’s look at the circuit simulation for this circuit
In the above circuit, we have used two transistors connected in series to control the LED. We have the first Transistor’s Collector connected to the LED’s negative end and it’s Emitter is connected to the Second Transistor’s Collector. The second Transistor’s Emitter is connected to the negative end of the Battery. Both the transistor’s Base is connected to the Battery’s positive end with a switch and a resistor.
When only one of the transistor is ON, the circuit is incomplete and LED does not light up - only when both transistors are ON the current can flow through the full path - Battery Positive → LED → 1st Collector → 1st Emitter → 2nd Collector → 2nd Emitter → Battery Negative - completing the circuit and lighting the LED.
Here’s the circuit on the perfboard -
OR Gate
OR Gate is a circuit in which when either one or both of the Inputs are ON then the Output is ON.
Here’s the Symbol and Truth Table for the OR Gate -
Let’s look at the circuit simulation for this circuit
In the above circuit, we have used two Transistor connected in parallel to control the LED. We have the both the transistor’s Collector connected to the LED’s negative end and the Emitter connected to the Battery’s negative end. Both the transistor’s Base is connected to the Battery’s positive end with a switch and a resistor.
When either one or both of the transistors is ON, the circuit completes and LED lights up because it can flow through either of the following paths -
Battery Positive → LED → 1st Collector → 1st Emitter → Battery Negative
Battery Positive → LED → 2nd Collector → 2nd Emitter → Battery Negative
The LED does not light up when both the transistors are OFF.
Here’s the circuit on the perfboard -
Putting It All Together
Finally, I now have 4 perfboard circuits - a Buffer, NOT, AND, and OR gate - that I can display on my desk. I had a lot of fun putting this all together - learning to read circuit diagrams, prototyping on breadboard and soldering it all onto perfboard.
I hope you enjoyed reading through this post!








