YTread Logo
YTread Logo

Using Basic Logic Gates - With & Without Arduino

May 31, 2021
Today in the workshop we will work with

basic

logic

gates

we will see how these devices work how to select them and how to use them alone or with an Arduino we will even build a simple intrusion alarm it is the

logic

al thing to do, welcome to the workshop. Hello and welcome to the workshop. Today we are going to work with

basic

logic chips. You might be wondering why we're covering basic logic chips after all, some of these chips are over half a century old. What possible reason could we have in the era of microcontrollers and microcomputers to work with basic logic chips?
using basic logic gates   with without arduino
Well, there are several reasons, actually, the first reason may simply be academic, you may want to know more about the fundamental components of logic because these are the basic components that create every digital device we have, but there are reasons beyond academics to learn about basic logic chips. You might want to use them in a completely new design now, which isn't a crazy idea if you continue. If you visit a large site like Mouser or Digikey or another large electronics distributor, you will notice that they have a lot of basic 7 400 and 4 000 series logic chips, which are stocked in large quantities and most of them are surface mounts, so that these are not chips that are just used to repair old Apple Twos, they are chips that are used for new designs and there are many good reasons to do so, if you have a very simple design a microcontroller can be an overkill, the most obvious example is the first sketch we learned with the

arduino

, the blinking sketch, if you want to blink an LED there are better and cheaper ways to do it than

using

a microcontroller, obviously the cheapest way is to just buy. a blinking LED, but you can also blink a regular LED with basic logic chips or something like a 555 timer and the circuit you end up with will not only be less expensive than the one based on the microcontroller, but it won't require any programming .
using basic logic gates   with without arduino

More Interesting Facts About,

using basic logic gates with without arduino...

It will be easier to repair in the future because you can simply replace the components without programming, and in many ways it will be more reliable because you won't encounter software glitches or microcontrollers that will crash once they are installed. rebuilt, they just work and a third reason to learn about basic logic chips is to improve our microcontroller and microcomputer based designs. We've already done it here in the workshop a few episodes ago, we use shift registers to improve input and output. capabilities of an

arduino

and you can use all kinds of logic tips to improve your microcontroller based designs and we'll do that a little later in today's episode.
using basic logic gates   with without arduino
Now basic logic chips are a huge topic and to cover everything in one video or article would be absolutely ridiculous and probably impossible, so what we are going to cover today are the fundamentals, the fundamental logic blocks that comprise everything we have that is digital these days, we'll cover all of that, we'll also cover logic families specifically the 7400 ttl series of logic families which is what we're going to use. Of course we will do a couple of designs wiring these chips and we will also include an arduino in the picture. We'll show you how. An arduino can be used to emulate the logic chips and also how we can add a chip to an arduino to build a project.
using basic logic gates   with without arduino
In this case, it is an intruder alarm that adds a basic logic chip to the arduino to enhance its capabilities, so as usual, we have a lot to go on, so let's start by learning about basic logic chips. Basic logic

gates

are the fundamental components of all digital circuits. The basic door is defined as a device that has one output and one or more inputs. We use something called truth. table to define the logic of the gate a truth table is a graph that shows all the possible states of the inputs and the resulting output the basic logic gates use the rules of boolean algebra for their operation there are seven basic logic gates that we will examine today three of them are the most fundamental of all the gates today we will look at seven basic logic gates starting with the three most fundamental gates we will start by looking at the gate not the or gate and the gate and the not gate is the simplest of all the basic logic gates, this gate It is sometimes called an inverter and for good reason because the output is the inverse of the input.
If you look at the formula written below the logic gate symbol, you will see that the output y is the inverse of the input to the overlined line in the letter a indicates that it is inverted now next to this we have the truth table and you will see that for the input a we have two possible conditions, a zero or a one, the output y will be the opposite in both cases now the next basic gate that we will examine is the o gate now if we look at the gate formula o it seems to say and is equal to a plus b but the plus symbol is actually used as or in boolean algebra now to define an or the easiest way is to look at the truth table.
If you look at the truth table and look at the inputs for a and b, you will see that the output y is set to 1 whenever a or b is set to 1. It is also set to 1 if a and b are set to 1. the only condition in which the output y is a 0 if a and b are both values ​​of 0. the y gate is the third fundamental gate and you will see its formula below its symbol the truth table for the gate y shows you that the output y is set to one only if a and b are set to one, any other condition will result in an output of zero The other four basic logic gates are the nand gate, the nora gate, the exclusive or gate and the exclusive nor gate, a nand gate is simply an and gate with a output inverted and you can see that in the formula below the symbol, if you look at the truth table, you will see that the output y is set to 1 in all conditions except when a and b are equal in a similar way.
A ni gate is just a gate or with an inverter at the output of the truth table. You can see that the output will only be set to a one-to-one condition when a and b are equal to zero, any other condition will result in an output of zero. The exclusive or gate formula is shown below its symbol and you can better see how it works by looking at the truth table. exclusive or gate has an output of 1 if a is equal to 1 but b is equal to 0 or a is equal to zero and b is equal to one In other words, if the two inputs are different, the output is set to one when the inputs are equal the output is set to zero and finally the exclusive gate is neither an exclusive gate nor with an inverted output in this case the output will be set to 1 if the two inputs are set to the same value if the two inputs differ the output will be will be set to zero.
You can combine basic logic gates to create other basic logic gates. A simple example is combining an and gate and a not gate to create an nand gate in a similar way. You can link both inputs of a nand gate. In fact, the nand gate is known as a universal gate because by

using

combinations of nand gates any of the seven basic gates can be created, one nand gate combined with a second nand gate that is connected as an inverter will create one gate and this configuration with three nand gates will create an o gate and of course adding an inverted output to that with a fourth nand gate creates an nor gate.
You can use this technique to create all basic gates with nand. gates and in some cases designers only use nand gates in their circuits and simply create the others themselves, so now let's learn a little more about these basic gates. One way to get familiar with logic gates without having to take out a solderless board is to use an online logic gate simulator and there are a few of them, this one is from a site called academo and it's a pretty nice little program. You'll also want to keep in mind that the program itself is open source and available on github, so if you're familiar with JavaScript and might want to improve it.
You can go ahead and fork it on github. Now this simulator is very simple, as you can see. I have an input device here that's like a switch and I can click the mouse and turn it on and off, it's on when it turns yellow. There's also an output device here, so what I'm going to do is connect my input to my output device by dragging a line between them and then when I turn it on. The output is activated and deactivated in the same way. I can get rid of this line by simply right clicking on it.
Now what I'm going to do is add some nodes here. I'm going to add, let's say. a door and over here and I'll add the node and then I'll give it to me over here and I can drag it down and put it, let's say over here somewhere and I'll need another input as well because it's two inputs and door, so I'll add another node for one input , it's a little difficult to drag the input, sometimes I've found that okay, here we go, I have my input here and just turn it off, we'll connect it to the gate inputs and and the output of that will go to the output now, as you can see both of my inputs are off and the output is off.
If I turn on one there is no effect on the output, if I turn on the other there is no effect but if I turn on both the output continues and that of course is the function of a gate and now this can also help you see what can happen when you connect a pair of doors, let's say we want one door and three entrances. but I only had a couple of two inputs, well we could combine them and make our three inputs and doors, let's add another one and door and drag it somewhere here, I guess it'll be fine and we'll break this connection, we'll move it over a little bit, give me some space to draw, I'll put you here, I'll take you here and I'll need another input device too because it's a three-input door, now eat, here we go, okay, let's turn these off, okay?
And now that? I have my three inputs here, two of them connected to one and a door, a third connected to an input of a door and the output of this door connected to that one as well and what I'm trying to do. is to create a three input gate and let's see if it works if I just turn this on, nothing happens, I just turn this one on, nothing happens, nothing happens, both are on, but nothing happens if all three continue, I get an output and that It is in fact the nature of the three inputs and the gate, the output will only be high if all the inputs are high, so as you can see a logic simulator can be a very interesting way to learn a bit about logic circuits without having to connect a lot of chips.
So now that we have seen the seven basic logic gates we are ready to start experimenting with them, but before we begin there is another consideration we need to make and this is more of an electrical consideration, there are some components that are used to stick. together, for lack of a better word, all the logic gates in your circuit, so I want to take a quick look at those components right now, we're going to look at the buffer, the Schmidt trigger, and the three-state buffer. These three devices can provide the glue to hold your digital logic circuits together.
At first glance, the buffer may seem like the most useless digital logic gate you can imagine. The output of the buffer is equal to the input of the buffer, as you can see from both the formula and the truth. table, so why would we need such a component? There is a buffer to provide electrical isolation between one section of a digital logic section and another. The buffer can increase the output capacity of a digital logic section, allowing it to control more than one gate. The number of gates that the buffer can drive is known as its fan.
The Schmidt trigger I'm showing here acts as an inverter, as you can see from both the formula and the truth table, but you can get other forms of Schmitt triggers as well as a Schmidt trigger. It is a device that can clean a data signal. Actually, it is a form of comparator. In fact, it has two comparators that determine when a signal is below the low threshold or above the high threshold and provides a clean output, although I have shown a Schmitt trigger. Here as an inverter you can also get non-inverting Schmitt triggers as well as gates or gates, nand gates and nor gates that have built-in Schmidt triggers.
A tri-state buffer is a special form of buffer that has an additional control or enable. line Now, if you look at the truth table, it may look a little strange because you'll notice that when the enable line is set to zero, the output y is set to h instead of zero or one. Now what the heck is h? The state buffer can be enabled or disabled when the buffer is enabled, it simply acts as a buffer where y is equal to a, but when disabled it has a high impedance output which was the h you saw in the truth table, a buffer from three states.
It is used on data buses where many different devices need to communicate with the same bus but only one can talk at any given time. You can also get tri-state buffers that have internal Schmidt triggers. Here is a digital logic circuit that is currently incomplete. Itwould do. I would like to connect the output of this nand gate to the three unused inputs on the other gates on the right side. Now if I do this directly, the nand gate may not have the fan-out capability to drive three gates, in this case I can insert a buffer. into the circuit and let it drive the three gates for me without changing the logic.
Now here is a circuit that uses two three-state buffers, as well as some logic circuitry on the left side. You will notice that both outputs of the tri-state buffers are linked to the input of the buffer that goes to the output. Currently nothing goes to the output because neither of the tri-state buffers are enabled. If I enable the top buffer, then the logic is passed. the top section, the one with the nand gate through the tri-state buffer and through the buffer to the output, the next logic is still ignored if you enable the other buffer, then the exclusive nor gate logic on the other side will pass to the output and the nand gate logic at the top will be ignored.
You need to ensure that you never enable both tri-gates simultaneously. state buffers now, here is a circuit where we have a nand gate that controls a buffer, but there is a very long line between the two. If I put an oscilloscope at the output of my nand gate, I can see that I get a nice clean digital image. signal, but if I place my scope on the buffer input at the end of the long line you will see that the signal has been severely degraded, the scope and buffer output show that the signal I am outputting is not the required signal if for On the other hand, I replaced my buffer with a Schmidt trigger, so as you can see the signal at the output represents the same as a signal at the input, the Schmitt trigger is able to clean up the dirty signal and now that we have learned about gates basics and the chips that can put them together, let's get started and work with them, so now it's time to take a look at logic families.
What I mean by families are series of logic chips, all the basic gates combined. in a standard series and there are a couple of predominant logic families, including two very predominant ones, these families are based on the technology used to create the gates and circuits in their chips, so let's take a quick look at that right now, the logic families They are defined by the different technologies used to build logic chips These technologies are based on the components used and the layout of their circuits The choice of logic family affects the voltage and current requirements of your circuit The choice of logic family can also affect the speed and logic voltage levels used in their design, we can divide the logic families into two sections: those based on bipolar transistors and those based on mosfets or metal oxide semiconductors on the bipolar side.
A very early form of logic family was diode logic. Resistor transistor logic replaced diode logic. It had improved. reduced speeds and voltage requirements, but unfortunately I couldn't make a knot or inverter type gate diode transistor logic or dtl replaced rtl and was able to create all types of gates; However, dtl consumes a large amount of transistor current. Transistor logic or TTL has become the dominant form of bipolar logic can create all gates has a very fast speed and has reduced current requirements compared to DTL on the moth side we have several technologies that are still very much in use pmos or positive metal oxide semiconductor nmos or negative metal oxide semiconductors and cmos or complementary metal oxide semiconductor circuits there is also a form of logic family called moss.
This is a fusion of bipolar and mosfet devices on the same chip. Nowadays we no longer use dl rtl and dtl ttl logic has become the dominant way. of bipolar logic on the moth side all the different logic families are used; However, today in our examples we will only talk about CMOS or complementary metal oxide semiconductors TTL is a logic family of transistors and transistors. This logic family was originally designed using bipolar transistor TTL logic. It was invented in 1961 by TRW Industries. The first TTL chips were produced by Sylvania in 1963. The TTL logic family is by far the most popular logic family.
There are several variations of these chips, most of them are based on 5 volt logic and some power supplies. Newer variations of the TTL logic family use CMOS and Biomos technologies instead of just bipolar transistors. This is how you read the part number on a ttl logic chip. The first two characters are the manufacturer prefix and this will be unique for each manufacturer different from the next two. The characters determine whether the logic kip is a mil-spec chip, in which case there will be a 5-4 chip or a commercial chip that is type 7. For most of our designs we will use type 74 bits;
However, keep in mind that military-spec ships are sometimes used for designs that need to operate outdoors as they are capable of operating at much lower and much higher temperatures than commercial chips. The next two characters in the part number define the technology used to build the chip. I'll talk about that more in a few seconds. The next two or three digits are the part number of the chip in the ttl logic family catalog. Note that some chips also have two digits preceding this indicating the gate count, although this is not very common. Finally, the last letter in the part number determines the type of package the chip is built in.
Now here is a table that describes some of the 7400 TTL logic series chips and some of the different technologies used to build them. This is just a subset of the full list, the 7400 chips at the top. they are no longer used they were the originals now the part numbers remain the same regardless of what series you use so for example if you have a 7402 door the pin will be the same as a 74 and o2 o a 74 hco2. Now many of these use standard TTL or bipolar technology and have a voltage requirement of about 5 volts; However, you will notice that there are also a couple of CMOS designs that can use different supply voltages these days, the most common chips you will see are the 74 LS series and the 74HC series, if you are doing a new design the 74 hc series, as it can adapt to different supply voltages.
Another good series for new designs is the 74 hct series, which will maintain compatibility with older ttl chips but offer the benefits of reduced current draw that cmos offers. Standard ttl gates have what is known as a totem output. It uses two transistors that are alternately turned on or off to send a zero or one to the output. This design provides low power consumption. it is also very fast to switch the same design can be used for three state logic chips in this case both transistors are off to put the chip in a high impedance state some ttl chips use open collector outputs in this case the load needs to connect between the output and vcc which is usually 5 volts this design allows for a high current output allowing you to drive things like LEDs for example when using an open collector output chip with other logic chips you will need a pull-up resistor.
A disadvantage of open collector output is that it is slower than the totem pole design. Now here are the pins for a typical ttl logic chip. In this case, it is a 2-input quad 7400 nand gate. It is called quad because there are four nand gates in the package. The package indicates that this will be the same pin used for the 74 ls 0 0 and 74 hc 0 0 and all other 7400 series. Also note that vcc, which in most cases is 5 volts, is applied to pin 14 and ground. applies to pin 7. These two pins are diagonal to each other and you will see this pattern with most but not all 7400 chips, this makes it very easy when you have them on a circuit board to find the power and ground, Another popular series of logic chips is the 4000 series which was developed by RCA in 1968.
These chips use a CMOS design for low power consumption. They can operate over a wide range of supply voltages. The CMOS design provides greater fanout capability than the TTL design. Fewer buffers are required and more chips can be connected. The high impedance inputs used in this design make the interface much easier. The 4000 series chips, however, are slower than the 7400 series TTL chips, so they are not suitable for all applications despite their age. They are still very common in new designs, so now that you know more about logic families, let's start working with some of these chips, theory pretty good, now it's time to plug in some of these logic chips and I'll be using the series 74 ls of ttl chips because they are probably the most popular and easiest to get chips out there right now.
I'll also take advantage of the fact that several of these chips have compatible pins, not just that. They have power and ground on the same pin but contain logic gates that have their inputs and outputs connected to the same pins. We're going to use that to check several different gates with the same circuit and then I'll also show you another circuit that demonstrates three state logic, so let's start with the four TTL logic chips that I'll be working with today are all packaged in a dip package of 14 pin or in a dual inline package, all of these chips, like most 14 pin ttl chips, have their power or vcc on pin 14 and ground on pin 7.
These tips are all quad gates with two entrances and an exit. The first gate has its input a on pin 1. Input b will be activated. pin 2 and the o y output connection will be on pin 3. This pattern repeats for the other three logic gates, the 74 ls00 is a quad nand gate. You will notice that gate 1 has input a on pin 1, input b on pin 2. and output y on pin 3. the 74 ls08 is a quad and a gate with the same pins, the 74 ls 32 is a quad o a gate and the 74 ls 86 is a dedicated quad or a gate again with the same pins, we can test all these chips with the following circuit, you can substitute any chip you want for the 14 pin dip shown here on inputs a and b which are on pins 1 and 2.
We have arranged a push button with a 2.2k pull down resistor. This way when the button is pressed it will send 5 volts to these pins, so pressing the button will create a 1 and releasing the button will lower it to 0. I have the output on pin 3 going through 330 ohms. resistor to one LED, note that I am driving the LED directly from the chip and this is fine, as long as you are only driving one LED, you cannot drive the LEDs of all four outputs at the same time as this would probably exceed the maximum capacities of current. of the chip for that application you would use open collector outputs.
This is a very simple circuit to plug into a board without soldering, so let's do it and check out our logic chips. Here is our little digital demonstrator circuit that we will use with four. different chips and I already have one connected and you can see an LED glowing indicating the output of the chip is high now the two buttons for the input are buried down here not sure how well you can see it in the video and the chip I have here is a 74 ls00 and that is a quad 2 input nand gate so the output of a nand gate will be high unless both inputs are high so now both inputs are low. because I haven't pressed any of the buttons and the output is really high if I press one of the buttons to bring the input down to bring the input down sorry it has no effect and the other button to bring an input high also has no effect but pressing both simultaneously sends the output low and that's actually the function of a nand gate, it's the inverse of a gate and so I'm going to remove the power, remove that chip and replace it with another one that has a compatible pin output and what I'm going to put here now is a 74 ls 0 8 and the 74 ls08 has the same pin output but this is a quad 2 input and gate so when I apply power I have no output because the output is currently low because both of my inputs are low and if I push one of the inputs high it has no effect, the other input has no effect on both inputs, however I turn the output on and send it to high because one gate and it is only high on the output if both inputs are high okay let's swap that and by the way I'm wearing my antistatic strap but ttl chips are pretty rugged and you don't need to observe as strict static requirements as you do with other chips now this is a 74 ls32 and what a 74 ls32 is is a quad or gate so we're going to plug it back in and right now I have no output here and both of my inputs are zero but if I press one of the inputs and it sends it high the output goes high if I press the another input high, the output goes high and they both also send it high and that of course is the nature of a gate or if one or the other or both the inputs are high, the output is high and nowlet's put another and last chip here and this is a 74 ls 86 and the 74 ls 86 is a dedicated quad or gate, so I applied power again, I have no output. is low and both inputs are low, that is what would be expected and if I push one of the inputs and send it high the output goes high.
If I push the other input and send it high, the output also goes high, but if I push. put them both at the same time and send them high, the output is low because an exclusive gate or only goes high when one or the other, but not both inputs, are set high, and there you have it, you can easily demonstrate the operation of several popular digital logics. chips thanks to the fact that they have the same pins now for this next demonstration I want to show you how three state logic works. Now you will remember that we talked about three-state logic.
This is a type of logic that in addition to having an output that can be high or low, it can also have a high impedance output and this can be used when you want to join two logic circuits on a common bus, as you can see I have a demonstrator here with has a lot of wires, so instead of showing you the individual connection, I'll explain what I have here and show you in block diagram form how this actually works now. If you look here, you'll see that I have a couple sets of DIP switches, two four position DIP switches and I have some LEDs here, four LEDs, I also have a switch here that you may or may not be able to see, it's connected to the board and this It is a unipolar. double throw switch with one side connected to ground, one side connected to five volts and that way when you flip this switch the output will go to ground or five volts.
Now what this demonstrates, like I said, is three state logic, so the heart of this is these two chips here and these are 74 ls 125 and what are 74 ls 125 are quad buffer tips, they have four buffer but these are three state buffers so each buffer has an enable line and what I have done is take the output of these switches here these switches use pull down resistors so when they are on they are high when they are off they are low and they are feeding to the four different ports on a 74 ls 125. That's why I have two of these chips.
There is one for each of these DIP switches. Here now are the enable lines for the 74 ls 125. They are all linked in common on each chip, so all the 74 ls 125 enabled on this chip are in common and all of the ones on this chip are also in common now those lines enable lines are being sent back here now this circuit uses my switch which switches between ground and 5 volts and feeds it to the input of an inverter this is 74 ls04 the output of that inverter is fed to the enable line of one of these ics here now these enable lines activate the buffers when they go low they are an active low enable so if it is set high it goes to the inverter it goes low and enables that particular set of buffers and that chip then it goes through another inverter to go to the other chip, so when the enable line of this one is low, this one will be high and vice versa, so by flipping the switch I can change the enable lines and the outputs of these are sent to another chip and this is a 74 ls07 and it is just a quad buffer chip but this chip also has an open collector output so i can use it to drive the LEDs so that's basically what is happening - i have two banks of switches DIP, each of which feeds its own set of quad buffers and since the buffers are tri-state, I can enable or disable the buffers. and the output of the DIP switch that is selected was going to appear on these LEDs, so now the switch is in this position here and it looks like I have the output of this particular DIP switch here, so if I change some values ​​on it We will see that those values ​​change on these LEDs here now if I flip the switch here.
Now I am using the values ​​from this DIP switch because all three status gates are enabled for this switch but not for the other one and there. you're going to do a pretty simple demonstration of how three state logic works now for our next experiment we're going to incorporate an arduino into the picture, you know we couldn't go that long without incorporating an arduino and what are we going to do with the arduino are we going to emulate six of the seven basic logic gates, the only one we will not emulate will be the not gate because it is quite simple, what goes in is the opposite of what comes out.
It can be used to build a sort of little logic gate trainer that shows you how gates work, but you can also use it as a programming exercise because it will show you which statements we can use in our programs that are equivalent to all of them. the basic logic gates so let's go and take a look at the wiring for that and for our logic emulator code for a logic emulator you will need an arduino uno a couple of push button switches two LEDs to represent the inputs you can use any color that you like use two red LEDs you will need six LEDs to represent the outputs I use green LEDs but here I show the yellow ones as it is easier to see on the blue background you can use any color you want or you can even use different colors for each LED, you will need two two-point K pull-down resistors for the buttons.
You will also need eight 220 ohm pull-down resistors for the LED. Now any value from 150 to 470 ohms of work we will start connecting. the exclusive nor led anode to pin 6 of the arduino through one of the 220 ohm drop resistors we will make the same connection for the exclusive or led to pin 7 of the arduino through its drop resistor the nor led will connect pin 8 from the arduino through a drop resistor, the LED anode will connect pin 9 of the arduino through its drop resistor, the LED nand anode connects to pin 10 of the arduino through a drop resistor and finally the anode LED connects to pin 11 of the arduino through a 220 ohm drop resistor, the anode of led a also passes through a 220 ohm drop resistor and connects to pin 12 of the arduino and led b connects to pin 13 with its drop resistance, all the cathodes of the LEDs are connected to the ground of the arduino.
We will connect one side of each of the buttons to the positive 5 volts of the arduino. The other side of each of the buttons will go to ground through a 2.2k drop resistor we will take that same connection on the a button and connect it to pin 4 of the arduino and finally we will connect the drop resistor side of the b button to pin 5 of the arduino and this completes the wiring of our logical emulator. Now here's a sketch that we're going to use. For our logic emulator and it's a very basic sketch, we start by defining a number of boolean values ​​as inputs and outputs because of course we are going to work with boolean logic and then we define the devices like the buttons and the LEDs. that we are using to represent the different logic outputs, as well as the LEDs that we are using to represent the logic inputs, we enter this configuration, we are going to configure the serial monitor because we are going to show our results.
There, as well as in the LEDs, we will define our two buttons as inputs and we will define all our LEDs as outputs, so everything is very basic, until then we enter the loop and we are going to read the buttons. and assign them values ​​so that a and b are the values ​​of buttons a and b respectively and remember that when they are pressed, they will go to 1 and then we will write those values ​​to their respective LEDs here. and then we go and calculate the logic outputs and this is actually this part of the code that you're going to want to look at because it's going to show you the symbols that you can use for all the different boolean operations.
Let's go to the bottom after here and out and it's the output y, so it's in a and in b, so this is the symbol that we use for an and now the output nand is the inverse of that, so we do n a and in b and then we use this exclamation. mark to reverse everything now this is the symbol that we use for an o and this of course will be what we will use for a nora we will simply reverse the o statement here and this symbol is used for exclusive minerals and therefore an exclusive nor It's going to be the same here with an inversion on the front, so there you have a and an or an exclusive or and an inversion of the four basic logic functions represented in the arduino code.
Now we will simply show the results. to the serial monitor and then we will write to the respective LEDs to show if the output is high or low, we will apply a short delay and run the loop again, so it's a very simple sketch, let's see it in action now and so on, here there is my logic emulator and as you can see I have labeled all my LEDs so these are my six outputs and these are my two inputs a and b and you will also notice that the serial monitor is showing the values ​​of the LED outputs also now they are configured with a and b equal to zero and you will see that some of my outputs are high as indicated by the illuminated LED and others are low and let's check the logic in that. because that's right, this is an and gate and with two low inputs, its output should be low, in fact it is a nand gate and it is the inverse of an and gate, so its output is high and/or the gate too is low at the output when both inputs are low.
The a ni gate is its inverse, so it has a high output and an exclusive o gate is also low if both inputs are low, so an exclusive ni gate has a high output. , so let's press one of the switches, my switches are buried. Come back here and I'll hit the switch a and as you can see we've had a couple of changes here the gate or now has gone high because one of the inputs has gone high and that's the correct logic the gate and is still low because it's just one of the inputs is high at the time the exclusive gate or has gone up because one of the inputs is high but the other is not and of course the other gates are just the opposite of these gates now that We will press switch b and notice pretty much the same thing: the o door and the exclusive o door are now high and the y door is low and if we press both switches and bring them to both highs, the y door has gone up as expected, the o door is also high, the exclusive o gate is low and that is correct because the exclusive o gate will only be high if only a or only b is high, but if both are high the output is low and of course these other gates are just the opposite of that , and there you have it the logical emulator.
Now one thing it would be good for would be for training purposes and an interesting exercise would be to build this and not label them and just have someone go through the four different possibilities of a and b and try to determine which door is which and that will show you if you really have a proper understanding of how these logic gates work, so it probably now has a practical purpose for our In today's final project we are going to combine an arduino and a basic logic gate to create a rudimentary intruder alarm and this is a circuit that You can expand to create a really practical intruder alarm, as is.
It's a breadboard experiment and you can't run the sensor wires very far, but if you were to use this in a practical application you'd probably want to add relays or opto-isolators, but the way our alarm will work is to have two connections or two what I call loops, an open loop and a closed loop in a closed loop circuit, you have a wire that is connected from one end to the other and if this wire breaks in any way the alarm will sound and you can use it with sensors like aluminum tape that you put on windows that would break if the window breaks or something like a magnetic reed switch that you can put on a door or window frame that would open when the door or window is open and A closed loop circuit is actually the safest because anyone who tries to thwart the alarm by cutting the wire will actually set off the alarm.
There is also the open circuit where voltage needs to be applied for the alarm to work and this is good for sensors like doormat switches or for things like emergency buttons so you can have an emergency switch for your alarm. Our alarm will have both and both will trigger interrupts on the arduino, now just the arduino uno. It has two interrupt inputs, but we'll use four inputs, two closed loop and two open loop, and we'll use a tto logic chip to combine all those signals and send them to our interrupts, so let's take a look at the connection of our alarm and then I'll show you the code and then we'll demonstrate it.
Our intruder alarm will be based on an arduino and a 74 ls 132, which is now a quad door with Schmidt triggers. If you don't have a 74 ls 132 you could use a 74 ls00 which is a quad gate with the same pins, you wouldn't get the benefit of the Schmidt trigger. Now for our alarm, we will have a condition where we are going to look for a high interrupt, therefore in normal operation the interrupt must be kept low for the open loop circuit. The circuit that needs to activate an alarm when it reaches 5 volts. Cansatisfy this requirement with a door or.
We will use three of the nand gates to create a gate or to do that on the closed loop side we need one nand gate because in closed loop the inputs will always stay at 5 volts if one of them goes down to 0 the alarm will go off and A nand gate meets this requirement because its output will be low as long as both inputs are high, but if one of those low inputs will be high, remember that a high input to the interrupt pin now triggers the alarm. let's take a look at the circuit we will use with the 74 ls 132 in addition to the 74 ls 132 you will need an arduino uno an led that we will use for the alarm output a 220 ohm drop resistor for that led actually any value from 150 to 470 ohms would work fine.
You will need two buttons for reset and emergency, one 10k pull down resistor for the arduino and four 2.2k pull down resistors for the ttl gate. The alarm will also have three sets of inputs. connections will have two closed circuit inputs and one open circuit input. We will begin our connection by connecting the 5 volts of the arduino to pin 14 of the 74ls 132. The ground of the arduino will be connected to pin 7 of the 74ls 132. the anode of the led goes to pin 13 of the arduino through its 220 ohm drop resistance the cathode of the led is connected to ground pin 12 of the arduino is connected to one side of the alarm reset switch from that same connection we will go to ground through a 10k resistor drop down the other side of the alarm reset switch is connected at 5 volts one side of our kill switch is connected to 5 volts the other side of the kill switch is connected to pins 9 and 10 of the 74 ls 132 that same side of the switch is connected to ground through a pull down resistor of 2.2k.
Pins 12 and 13 of the 74 ls-132 are connected to the ol1 input, which is the open loop input pin 1 of the 74 ls 132, it is connected to the cl2 input pin 2 of the chip. is connected to the cl1 input, all the alarm inputs are connected to ground through a 2.2k pull down resistor and the other side of all the inputs is a connection to the 5 volt line on the 74 ls 132, we will need connect pins 11 and 5 together, we will also need to connect pins 8 and 4 together, connect the gate output on pin 6 to interrupt 0 on the arduino, which is pin 2. The gate output on pin 4 is connected to interrupt 1, which is pin 3 of the arduino.
Now you will need to close connections c01 and cl2. Breaking these connections will activate the alarm. The ol1 connections must remain open. Connecting these pins together will also activate the alarm, so now that we have connected our alarm, let's go and take a look at the code we will use to make it work. Here is the code we will use. For our intrusion alarm we now start by defining an integer that represents the alarm state and our alarm can have three different states. A status of zero means no alarm. A status of one or two means there is an open circuit or closed circuit alarm.
Now you'll notice that we made this integer volatile and the reason is that the alarm state is manipulated in our interrupt handlers and we need to inform our compiler by telling it that this is a volatile integer. Now the next integer we define is the Button State and this represents the state of the reset button that we have connected to the arduino to reset our alarm. Remember that our emergency button is not connected to the arduino directly, but is part of our logic circuit. So we have some values ​​for the alarm loop pins. the open loop and closed loop respectively that are connected to our interrupt pins, we then define where we have our devices connected, our alarm LED on pin 13, our alarm reset on pin 12 and the open loop connection on the pin 2 and the closed loop connection on Pin 3 and pin 2 are also interrupt 0.
Pin 3 is interrupt number 1. Now in the configuration we are going to initialize the serial port because we are also going to print our alarm status on the serial port and we will define our inputs. and outputs, so the LED is an output and the reset switch is an input and then we connect our interrupt handlers. Our interrupt handler for interrupt zero on pin two will go to this interrupt service routine and on interrupt pin number one, excuse me, which one? goes to pin number three, we will get this interrupt service routine and they will be called upon a change of values ​​on the interrupt pin.
Now here are the two interrupt service routines, so the detected open loop intrusion will set the alarm state. value of 1 and turns on the alarm LED and it is almost the same when the closed loop intrusion is detected, except it changes the alarm state to 2, so these are the two interrupt handlers we have here. We also have another function called delete. alarm and that clears the alarm LED, turns it off and resets the state to zero and also prints on the serial monitor that the alarm has been reset. Note that we don't print the serial monitor in our interrupt handlers because we really can't. use the serial port within an interrupt handling routine.
Now we enter the loop and in the loop we start by looking at the alarm status value. Remember that the alarm state will be changed by the interrupt handlers, so if it is a 0 everything is fine, we simply print ok on our serial monitor, if it is at number one, we print that we have an alarm condition of open circuit and if it is number two, we print that we have a closed circuit alarm condition, the other thing What we need to check to see is if we have a reset button pressed to measure the state of the button, we assign the value of the state of the button, excuse me, to a digital readout of the alarm reset and if the button state is low, then the button was pressed and So, first of all we have to see if this is a legitimate reset, because if the alarm condition still exists, we don't want to reset, so we will take the value from both the open loop and the closed loop.
Now these under normal circumstances will be low but we check them if the value is high for open loop then we print that we cannot reset because there is still an open loop alarm and we do the same with a closed loop value if it is high we cannot reset there is a closed loop alarm and we Exit, but if none of these conditions are true, then we can do a reset and we call that clear alarm function that we just saw to reset everything at the end of the loop, we add a slight time delay and we do it all again. and remember that the alarm LED is activated in the interrupt handlers, not in the loop, it is only reset when we call the clear alarm function here, so this is the code for our intruder alarm.
Let's demonstrate it now, so here is my alarm circuit. on a solderless board you can also see the serial monitor screen which is displaying fine at the moment because we are not in an alarm condition. Now I'll point out what some of the components are here, the LED is my output LED, so that will illuminate if we are in alarm condition. The red push button switch here is my reset switch, which is the one connected directly to the arduino buried here. I'm not sure how well it can be seen. It is a black push button switch. and that is connected to the logic chip and will trigger an open circuit alarm, so if it activates it will close that open circuit and cause an alarm.
It's an emergency button, so to speak, and these long orange wires here are my closed-circuit alarm. They are connected to five volts and if one of them becomes disconnected or broken then the alarm should sound, so now let's try my emergency button. I'll press the button and as you can see I'm displaying an open circuit alarm. and my alarm is illuminated and I can press my reset switch and it says alarm reset and the alarm is back and it's armed and it's fine, so now let's break the closed circuit, let's pull one of these orange wires here and again.
I have a closed circuit. alarm, the alarm is lit, let's try to reset this right now, if I do it, it can't reset, it says the closed circuit alarm condition still exists, so I'm going to put this back to 5 volts here. Note that the alarm is still on until I leave and it resets and that turns it off, and that's the function of our basic alarm with an arduino and a ttl logic chip. An interesting story from the days of early digital electronics is the story of Gordon Moore Gordon Moore was a very accomplished gentleman, he was both the co-founder of Fairchild Semiconductor and of Intel and he was also the CEO of Intel and in 1965 he was showing the Intel's last achievement was to put 60 transistors on a silicon chip, a great achievement in 1965 and Mr.
Moore predicted that every two years the number of transistors they could put on a chip would double, while the cost would be cut in half. . Now this prediction seems to have held up pretty well since then, Mr. Moore's own company released the world's first commercial microprocessor in 1974, the Intel 4004, and that chip had 2600. Transistors advance rapidly to this day and we have many transistors that are all mosfets in our chips now and you have a microprocessor that has a whopping 38.54 billion mosfets. Nvidia has a graphics processor that has 58 billion mosfets, but even these numbers are nothing when compared to memory chips.
Now Samsung has developed a technology with their vnand chips that uses one mosfet to store four bits of data, which means you need two mosfets per byte and they have a one terabyte memory chip, which means that chip has more than two billions of mosfets, a little curiosity is that if you take a look at all the mosfets that we have put in all the silicon chips over time, the mosfet is the most manufactured device on earth and I say that I would like to thank you for taking all the mosfets on your device and point them to youtube so you can watch this video.
I really appreciate it. If you want to see more of my videos, the best way to find out is. to subscribe to the youtube channel and you can do it by clicking on the subscribe button just below this video and after doing that also remember to click on the little notification bell and that way you will get a notification every time I make a new video If you want more information on the things we talked about today about digital logic, you can go to the dronebotworkshop.com website and you'll find an article to go along with this video; there is a link to that article in the video description while you are on the website, consider subscribing to the newsletter, it's my way of staying in touch with you and letting you know what's happening in the workshop and of course if you want to talk about electronics, whether basic digital electronics or very advanced microcontrollers, the best place.
What remains is the dronebot workshop forums and there is also information on how to join the forum just below this video, so until we see each other next time, take care, stay safe in these difficult times and I will see you again very soon here in the workshop goodbye for now you

If you have any copyright issue, please Contact