Intelligence and Consciousness is made of simple switches, let’s make logic with relays!
AND Get your first month of KiwiCo FREE at
Thanks for your support @
Checkout my merch:
Post your submissions to:
My Facebook:
My Twitter:
My other articles:
Thanks to and for proving my essential lab tools and giveaways.
Checkout my Amazon picks (my affiliate link):
Below are my Super Patrons with support to the extreme!
Nicholas Moller at
Sam Lutfi
EIM Technology:
Peter Membrey
Enter your school for tools:
My sponsors and top patrons:
By: Mehdi Sadaghdar

Hi, did you know the entire basis of logic and intelligence? Is the humble switch clickity clack from our brains, where the neurons turn on and off to our computers and artificial intelligence respect the switch? Let me give you a quick refresher on logic and then i'll make logic using my relay switches. Speaking of making, let me introduce you to my sponsor kiwico, because starting to build at any age, especially a young age, will inspire creativity and builds experience, especially with cuico products that come with a ton of knowledge. You can also get your first crate for free from my link, electroboom. Generally speaking, our entire logic is based on three operations or operands and or and invert or not, and these three operands are made from the humble switch see.

We make basic statements that can be true or false, and these three operations affect and combine statements into a new, bigger statement that can be true or false, and the result can go on to further affect decision making, for example, nothing a statement inverts it which i'm Showing here as a variable that can be true or false, nothing changes the statement to the opposite of whatever it is shown with a line on top, and so let me introduce you to the truth table which shows you what outputs you get through your logic, based On different inputs, which for the inverter, the output is inverted of the input, the basic and combines two statements into a new, bigger statement. That can only be true if both original statements are true. For example, i will find you and i will kill you so if i don't find you and naturally won't kill you, then it was a false promise. Also, if i don't find you but kill you like accidentally, run you over without knowing it was you still false.

Also, if i find you but for some reason we become best buddies and i don't kill you that makes a false. The and statement is only true if i find you and i kill you the basic or also combines two statements into a new bigger statement. That is only false if both original statements are false, like you, listen to me or i'll beat the sh out of you. If you don't listen to me and i don't beat you that was just an empty threat, the statement is true.

If you don't listen to me and i beat you or if you listen to me and i don't beat you, but it is also true, if you listen to me and i still beat you hey, i didn't say what will happen. If you listen to me, you should be more careful with the terms of contract and in both end and or you can end an or multiple statements in, and all statements must be true for the result to be true and in or all statements must be false For the result to be false, when you're, using both and and or you must use parentheses to indicate if you're, ending, first or oring first, nothing always comes first, unless you not all over a bigger statement, in which case you have to process that sub statement. First, now to switch to digital logic, we replace true and false with one and zero and call our basic operations gates, which are shown with these symbols that take 0 and 1 as input and output 0 and 1.. Now, to make it easy and confusing in the inverter, the true inverter is this circle.
If we remove it, this is just a simple buffer that sends the same state to the output, and sometimes we put the circle behind the triangle, and this is still an inverter. We can place that circle at the output of an and gate and invert its output, and they call it a nand gate, which is the same as an and gate feeding its output through an inverter, and similarly here is a nor gate. So, basically, looking at the truth table the outputs of the nand and nor are inverted of the and and or and we can write our logic in the form of algebra called boolean algebra, where we show and with a dot like multiplying or with a plus and Not with a bar or a prime or whatever floats your boat, i use bar, for example, there is another useful gate, called exclusive or or xor where the output is true or one only if one of the inputs is one and the other is zero, it is Still made of the basic logic gates, if we look at the truth table, we see that the output of the xor is one only if the inverse of a and b are true or a and inverse of b are true, so we have two and gates a Naught goes to one and a goes to the other. One b not goes to one and b goes to the other one and the outputs of the and gates are or like this, and that's it.

And, of course, if you invert the output of the xor, you get x nor you're, not all over the x or equation, and you get the x nor equation according to the truth table. Now, let's make these with relays see in circuits. We deal with voltage and current. We can assign a 0 volt to logic 0 and a non-zero voltage like 5 volts to logic 1, and we can switch it around using switches which, in computer components, are made of transistors, but to make it easy relays.

Basically, do the same thing i talked about relays in my previous video, which nobody watched here. I have a single pole, dual throw relay when the coil is not energized. The common terminal connects to normally closed terminal and when the coil is powered, it connects to the normally open to make an inverter. We simply connect the coil to ground on one side and to the input signal on the other side, if the input is low, the coil is off, and so because we want the output to be high, we connect the normally closed to the 5 volts and when The input is high and the coil turns on it switches to normally open that is ground.

Here is the inverter i made on my abused breadboard with my tiny spdt relay, and this is just a portable adjustable power supply and the output of the relay can switch 120 volt to turn on a lamp when i, let's use leds as indicators, see when the Input is 5 volt or high, the output is 0 volt or low and vice versa, so it inverts the cool thing about the relay is that if i need to invert the input, i don't need to add another inverter. I simply connect the coil to power, and now the coil is on when the signal is low, or i could flip the power and ground connection on the switch side. This is also an inverter now to make an and gate. I arrange two relays like this: the output can only be high if both switches switch or both inputs are high.
Like this, the output is high only when both inputs are high and to make a nand gate. All you need to do is to invert the output by flipping the power connection to the switch like this. So now the output is only low when both inputs are high now to make a nor gate. Let's look at its truth table.

The output is only high when both inputs are low. Now, if we take those inputs and invert them into a naught and b naught. This truth table is for an and gate only high when both inputs are high. This means a nor gate is the same as an and gate with both inputs inverted as a side note, a nand gate is also equal to an or gate with both inputs inverted so to make a nor gate.

We just take the same circuit as the and gate and invert the input by connecting the coils to the positive power, and so here the north's output is high. Only when both inputs are low and all you need to do to create an or gate is to invert the outputs by flipping the power lines, and so in the or gate the output is low when both inputs are low and our extra gate xor has this Schematic that we can easily put together, but we can get even smarter with our and gate and make it from a single relay see. This is also an and gate because the output is high only if both inputs are high for the xor circuit. We need and gates with one input inverted which we can easily get by inverting the input connecting the coil to the power line so to make the xor we throw in two of those ends and connect the inputs to them and their outputs go to an or Gate and we are done and here's the xor - the output is only high when the inputs are different and, of course, xnor has its output inverted to have an or xnor the output is high when the inputs are.

The same logic is easy: let's make it more complicated, you see these two nand gates see if we have these nor gates and feed their outputs to their inputs. We get the basic memory register, similar to what we get with the nand gates. We call the input set and reset and that's why the circuit is called sr latch and we have one output and the inverse of that output as a bonus. Let's make it with this circuit.

If we change the set input high, we change the output high and, of course, the inverted output low, and if we go back to zero zero, it latches and holds the previous state like a memory and changing the reset high. The output, resets and two input. Zeros again latches the previous state set latch reset latch for this circuit. We consider both ones an illegal state, because the outputs change to zero and coming back to 0 0 from that state.
We end up with a random output and we avoid the randomness. There is a problem with my relay circuit, that is, if i remove the load and switch the input, see the relays start oscillating, which can happen with any feedback circuit, even with transistors. The reason here is that in my relays, if the output is connected to one of the terminals, then we have a definite state, but switching from one to the other, the output will be floating and in a feedback system it can create oscillation in this circuit. Connecting a load from the output to ground eliminates that uncertainty, they call this circuit a latch because it latches and holds the previous state.

But let's get smarter with this circuit. What, if i added and gates to the inputs of this circuit, tie the inputs together and call it enable with this? If the enable line is zero, the output of the and gates are zero, no matter how the other inputs change. The other inputs can only affect the latch if the enable line is high because with enable high, it is up to the other input to change the output so here and works as a real gate, with enable as the gatekeeper next step as we saw set and Reset lines are inverse of each other unless we want to latch the data, so we send a signal to the bottom one and invert it and send it to the top one and call it d or data here is a data or d latch. If the enable line is low, the output holds the previous state, no matter how the input changes, but if the enable line is high, then the data line can change the output and then enable goes low again.

It holds the previous state. So, basically, with the enable you can sample the data in a moment of time and hold it safe from future changes, d-latch is a very useful circuit. The inputs make more sense, it holds your data and we eliminate that illegal 1-1 state. Do you see that blinking at the output, that's a real challenge with digital circuits called a glitch which is due to the propagation delay of the signal running through the gates, be very afraid of the glitch, because it can really hurt having unwanted, zero and ones like This can really screw up the downstream logic and decision making.

All of a sudden, you find yourself as a member of isis riding the shuttle field with chickens going into a soccer game on the moon, orange digital circuits, beautiful you throw a bunch more switches together and you create adders subtractors multiplexers address and data latches and memories. Coders decoders shift registers, sequential circuits and more and you put all those together to create microprocessors stack, a bunch of them on top of each other, to get super computers all from the humble switch and run complex codes on them and create artificial intelligence so powerful. It can take over the world and wipe us out. Let me introduce, kill, switch and introduce you to my sponsor kirikou, because hands-on, creating and building smaller projects today will provide knowledge and experience and lead into greater achievements.
Tomorrow, my daughter has been having a ton of fun putting a few of these together. Let's see what she's, up to now, these projects expose kids to concepts of steam, making the playtime a fun engaging and enriching experience. Cubicle crates also make a fantastic holiday gift. I'm pretty sure i would have loved to receive one of these as a kid who am, i kidding, i still love to put these kits together.

Following my link, electroboom, you can try your first month for free and discover kiwiko's assortment of subscriptions catered to different age groups, and now they ship to more than 40 countries. Every month, your child will get a crate of a project with all the needed parts and a kid-friendly instruction book to put it together and learn a ton while having fun so make sure to check them out. And thanks for watching.

14 thoughts on “Making Intelligence with Basic Switch”
  1. Avataaar/Circle Created with python_avatars Lakshya Jain says:

    I have a few ideas as a viewer which we would like and would also help your channel:
    1) how do lightning rods work(the grounding logic is very confusing) and can lightning rods in minecraft be applied in real life?
    2) A video that includes all the electrical devices like diodes, capacitors etc.
    3) Why does almost every reaction release electromagnetic waves and how do solar panels work

  2. Avataaar/Circle Created with python_avatars Noitanis says:

    An anectote a calculus teacher gave our class was he was on exam grading duty. And in one particular exam, there was a question: "Is function [some function f(x)] convergent or divergent?" A student just answered "yes" and given the phrasing of the question he gave the student max points on that question.

  3. Avataaar/Circle Created with python_avatars Pukkeh says:

    AND, OR and NOT are operations, not operands. The operands would be the input(s) to these operations.

    It is also possible to express these logical operations (and hence all logical operations) in terms of only the NAND or the NOR operations.

  4. Avataaar/Circle Created with python_avatars SPACE DRIFTER says:

    I had logic gates explained by an idiot who actually tried to convinced us he was a spy in Russian ubot and he was successful in his sabotage work…. This makes sense, your explanation I mean. Thanks you.

  5. Avataaar/Circle Created with python_avatars Varun Vidyadharan says:

    Its just like the meme..
    One minute we are talking about basic 0 & 1 with examples..
    Look away for a second.. Baam!!!
    We are making inverter 😫😫😫

  6. Avataaar/Circle Created with python_avatars Greg Goodenough says:

    neuron works not like a transistor at all. it's more like memristor, but still different. logic applied to transistor by no means may be applied to neuron.

  7. Avataaar/Circle Created with python_avatars LabCoatz says:

    This is one of the best descriptions of computer logic I've seen, well done Mehdi! Now you just need to make something with your switch logic…like ARTIFICIAL INTELLIGENCE!!!

    …or maybe just a simple calculator for now…

  8. Avataaar/Circle Created with python_avatars HACKERISTIC 499 says:

    These videos won't get a lot of views or retention.
    But if you sticked till end, you're the future of this world.

    Well who didn't still are but not the good one.

  9. Avataaar/Circle Created with python_avatars Brasilian Guy says:

    Funny how in a 15 minutes of this video, Mehdi is able to provide equivalent to hours of classes of Digital Electronics. Too bad it comes 32 years later for me… Lol.

    Thank you, master !

  10. Avataaar/Circle Created with python_avatars Tiago Pesce says:

    factorio players needed to learn that all from wikipedia.. in a ball of anguish and suffering… this video is the best factorio tutorial ever >.<

  11. Avataaar/Circle Created with python_avatars Taha Sadeghi Golshan says:

    Honestly this video wasn't really interesting for me but big tnx to you Mehdi.
    I'm watching you from Iran and I plan to become you neighbor in next 9 months.
    Cya later dude.
    Also I have a question.
    How can I have a direct access to you in order to ask you some useful questions?
    Tnx a lot, Regards

  12. Avataaar/Circle Created with python_avatars Emiddio Esposito says:

    This set of topics (which in uni I studied during two courses, the first focused on logic theory and computer architecture and the second on CMOS logic and digital circuit design), is basically what made computer science real and tangible to me. great explanations, great demonstrations, great video.

  13. Avataaar/Circle Created with python_avatars Perpetually_Biased says:

    "be more careful with your terms of contract" damn is there anything you DON'T learn from this guy? hahaha

  14. Avataaar/Circle Created with python_avatars Abhilash Pandey says:

    came to know about u during my jee prep now watching ur every ved . love ur content man . never seen (or maybe will see) anyone like u . my first ever comment on ur ved though XD

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.