In the first installment of "A computer from scratch", I've built a NAND gate. I've also introduced the my "scaling" rule: if I build something, I can buy it pre-made, because I only have one lifetime to spend on this :-)

Therefore. I've bought a bunch of 4011 CMOS NAND gates, here they are:

4011

And here's what they do:

4011 Pinout by Inductiveload

With this in mind, and with the diagrams in my second installment, I proceeded with building NOT, AND and OR gates. Of course this wasn't without confusion and questions, but fortunately I could count on the help of the Electronics Stack Exchange community when I got stuck.

The results

Here's what I built. Honestly, after getting stuck on where to put my resistors, all the builds were super easy.

NOT gate

A NOT gate is built by short-circuiting the inputs of a NAND. The circuit is very simple, it connects a button to pins A3 and B3, and connects the output Q3 to a LED.

NOT plan

The build looks like this

NOT result

AND gate

An AND gate is built by taking the result of a NAND and inverting it through a NOT. The circuit is also simple, it connects a button to pins A2 and another to B2, and connects the output Q2 to the previous NOT gate at A3/B3.

AND plan

The build looks like this

AND result

OR gate

An OR gate is built by negating both inputs and passing them throug a NAND. The circuit thus requires three NANDS. It connects a button to pins A2/B2 creating a NOT gate, and another button to A1/B1, creating another NOT. It then connects the two outputs Q1 and Q2 to A3 and B3 respectively. Q3 is connected to the LED as before

OR plan

The build looks like this

OR result

Next Steps

In the next steps I'd like to try and build XORs, half adders and full adders. I'd also like to build some testing script via Arduino, although I'm not sure I can pull it off.


A software engineer & Stack Overflow alumnus in London. I write about software development, coding, architecture and team leadership. I also speak at conferences worldwide.

About me

Follow me on Twitter

Gleanings

And the Most Realistic Developer in Fiction is...
Julia Silge • Mar 28, 2017

We can say that Mr. Robot is having a moment. The main character was one of the top choices and thus is perhaps the most/least realistic/annoying/inspiring portrayal of what it’s like to be a computer programmer today.

Read more…