Using Basic Logic Gates - With & Without Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] today in the workshop we'll be working with basic logic gates we'll see how these devices work how to select them and how to use them by themselves or with an arduino we'll even build a simple intruder alarm it's the logical thing to do so welcome to the workshop [Music] well hello and welcome to the workshop and today we are going to be working with basic logic chips now you may be wondering why on earth are we covering basic logic chips after all some of these chips are over half a century old what possible reason in the age of microcontrollers and microcomputers could we have for working with basic logic chips well there are a number of reasons actually the first reason may just be academic you may just want to know more about the fundamental building blocks of logic because these are the building blocks that create every digital device that we have but there are reasons beyond the academic for learning about basic logic chips you may indeed want to use them in a brand new design now that isn't a crazy thought if you go on to a big site like mouser or digikey or another large electronic distributor you will notice that they have lots and lots of basic logic chips of 7 400 and 4 000 series logic chips and that these are stocked in great quantities and that the majority of them are surface mounts so these aren't chips that are just being used to repair old apple twos these are chips that are being used for brand new designs and there's a lot of good reasons for doing that if you have a very simple design well a microcontroller can be an overkill the most obvious example is the very first sketch that we learned with the arduino the blink sketch if you want to blink an led there are better ways and cheaper ways of doing it than using a microcontroller obviously the cheapest way is just to buy a flashing led but you can also flash a regular led with basic logic chips or with something like a 555 timer and the circuit that you wind up with will not only be less expensive than the one based around the microcontroller it won't require any programming it'll be easier to repair down the road because you can just simply replace components without needing to program them and in many ways it'll be more reliable because you're not going to run into software glitches or microcontrollers locking up once they're built they just work and a third reason for learning about basic logic chips is to enhance our designs based around microcontrollers and microcomputers now we've already done that here in the workshop a few episodes back we used shift registers to enhance the input and output capabilities of an arduino and you can use all sorts of logic tips to enhance and improve your microcontroller based designs and we're going to be doing that a little later on in today's episode now basic logic chips is a huge subject and to cover everything in one video or one article would be absolutely ridiculous and probably impossible so what we're going to cover today are the fundamentals the fundamental logic blocks that comprise everything that we have that is digital these days we will 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 be using we'll of course do a couple of designs by wiring these chips up and we will also bring an arduino into the picture we will 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 in this case it's an intruder alarm that adds one basic logic chip to the arduino to enhance its capabilities so as usual we have a lot to get going on so let's start by learning about basic logic chips the basic logic gates are the fundamental building blocks of all digital circuits basic gate is defined as a device that has one output and one or more inputs we use something called a truth table to define the gate logic a truth table is a chart that shows all the possible states of the inputs and the resulting output 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'll look at seven basic logic gates starting with the three most fundamental gates we'll begin by looking at the not gate the or gate and the and gate the not gate is the simplest of all the basic logic gates this gate is sometimes referred to as an inverter and for good reason because the output is the inverse of the input if you look at the formula that is written below the symbol of the logic gate you will see that the output y is the inverse of input a the over scored line on the letter a indicates that it is inverted now beside 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 these cases now the next basic gate we will examine is the or gate now if you look at the formula for the or gate it looks like it says y equals a plus b but the plus symbol is actually used as an 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 as long as either 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 is if a and b are both values of 0. the and gate is the third fundamental gate and you will see its formula below its symbol the truth table for the and gate 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 four other 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 an inverted output and you can see that from the formula below the symbol if you look at the truth table you will see that the output y is set to 1 in every condition except when a and b are equal in a similar fashion a nor gate is just an or gate with an inverter on the output from the truth table you can see the output will only be set to one on one condition when a and b are equal to zero any other condition will result in an output of zero the exclusive or gates formula is shown below its symbol and you can see the operation of it best by looking at the truth table the 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 the same the output is set to zero and finally the exclusive nor gate is an exclusive or gate 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 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 in order to create a nand gate in a similar fashion you can tie both inputs of a nand gate together and use it as an inverter or not gate in fact the nand gate is referred to as the universal gate because using combinations of nand gates you can create any of the seven basic gates a nand gate combined with a second nand gate which is wired as an inverter will create an and gate this configuration with three nand gates will create an or gate and of course adding an inverted output to that with a fourth nand gate creates a nor gate you can use this technique to create all of the basic gates with nand gates and in some cases designers only use nand gates in their circuits and simply create the other ones themselves so now let's learn a little bit more about these basic gates now one way to get familiar with logic gates without having to get a solderless breadboard out 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 quite a nice little program you might also want to note that the program itself is open source and is available on github so if you're familiar with javascript and you want to perhaps improve upon it you can go ahead and fork that on github now this simulator is very simple as you can see i've got an input device over here which is like a toggle switch and i can click my mouse and toggle it on and off it's on when it turns yellow here's an output device as well and 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 and off the output goes in the same fashion i can get rid of this line by just right clicking on it now what i'm going to do is i'm going to add some nodes over here i'm going to add let's say an and gate over here and i'll add the node and then give it to me up 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 a two input and gate so i'll add another node for an input it's a little hard to drag the input sometimes i've noticed that okay there we go i've got my input here and just turn that off we'll connect this to the inputs of the and gate and the output of that will go to the output now as you can see both of my inputs are off and the output's off if i turn one on there's no effect on the output if i turn the other one on there's no effect but if i turn both of them on the output goes on and that of course is the function of an and gate now this can also help you see what can happen when you connect a couple of gates up let's say that we wanted a three input and gate but only had a couple of two input ones well we could combine them and make our three input and gate let's add another and gate and let's drag it somewhere over here i guess it'll be fine and we will break this connection move you over a bit give me some room to draw i'm going to put you up to here run you into here and i'll need another input device as well because it's a three input gate now comma there we go okay let's turn these off okay now what i have is i've got my three inputs over here two of them connected to one and gate a third one connected to one input of an and gate and the output of this gate connected to that as well and what i'm attempting to do is create a three input and gate let's see if it works if i just turn this on nothing happens i just turn this one on nothing happens nothing happens these both on still nothing happens if all three go on i get an output and that indeed is the nature of the three input and 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 neat way of learning a little bit about logic circuits without having to hook a bunch of chips up so now that we've seen the seven basic logic gates we're ready to begin experimenting with them but before we get started there is one other consideration that we need to make and this is more of an electrical consideration there are some components that are used to glue together for lack of a better word all of the logic gates in your circuit and 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 tri-state buffer these three devices can provide the glue to hold your digital logic circuits together at first glance the buffer may seem to be the most useless digital logic gate you could imagine the buffer's output equals the buffer's input as you can see from both the formula and the truth table so why on earth would we need such a component a buffer is there to provide electrical isolation between one section of a digital logic section and another the buffer can increase the output capability of a digital logic section allowing you to drive more than one gate the number of gates the buffer can drive is referred to as its fan out the schmidt trigger i am showing here acts as an inverter as you can see from both the formula and truth table but you can get other forms of schmitt triggers as well a schmidt trigger is a device that can clean a data signal this is actually a form of comparator in fact it has two comparators that determines when a signal is below the low threshold or above the high threshold and provide a clean output although i've shown a schmitt trigger here as an inverter you could also get non-inverting schmitt triggers as well as and gates or gates nand gates and nor gates that have schmidt triggers built into them 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 seem a little bit odd because you'll notice when the enable line is set to zero the output y is set to h instead of zero or one now what in the world is h a tri-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 it is disabled it has a high impedance output that was the h you saw on the truth table a tri-state buffer is used on data buses where many different devices need to communicate to the same bus but only one can talk at a given moment you can also get tri-state buffers that have internal schmidt triggers now here's a digital logic circuit that is currently incomplete 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 did 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 allow it to drive the three gates for me without changing the logic now here's a circuit that uses two tri-state buffers as well as some logic circuitry on the left side you'll note both the outputs of the tristate buffers are tied to the input of the buffer that goes to the output currently nothing is going to the output because neither of the tri-state buffers are enabled if i enable the top buffer then the logic from the top section the one with the nand gate is passed through the tri-state buffer and through the buffer to the output the logic below is still ignored if i enable the other buffer then the logic from the exclusive nor gate on the other side will be passed through to the output and the logic from the nand gate at the top will be ignored one needs to ensure that you never simultaneously enable both of the tri-state buffers now here is a circuit in which we have a nand gate driving a buffer but there is a very long line between the two of them if i place an oscilloscope at the output of my nand gate i can see i get a nice clean digital signal but if i place my scope at the input of the buffer at the end of the long line you will see that the signal has been severely degraded the scope and the output of the buffer shows that the signal that i'm getting out is not the required signal if on the other hand i replaced my buffer with a schmidt trigger then as you can see the signal on the output represents the same thing as a signal on the input the schmitt trigger is capable of cleaning up the dirty signal and so now that we've learned about basic gates and the chips that can glue them together let's start and work with them so now it's time to take a look at logic families now what i mean by families are series of logic chips all of 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 upon the technology used to create the gates and circuits on their chips so let's take a quick peek at that right now logic families are defined by the different technologies used to construct logic chips these technologies are based upon the components used and their circuit arrangement 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 the logic voltage levels used in your design we can break the logic families down into two sections those based upon bipolar transistors and those based upon 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 speeds and reduced voltage requirements but unfortunately could not make a knot or an inverter type gate diode transistor logic or dtl replaced rtl and was capable of creating all types of gates however dtl consumes a great deal of current transistor transistor logic or ttl has become the dominant form of bipolar logic it can create all of the gates has very fast speed and has reduced current requirements as 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 semiconductor and cmos or complementary metal oxide semiconductor circuits there is also a form of logic family called moss this is a fusion of both bipolar and mosfet devices on the same chip these days we no longer use dl rtl and dtl ttl logic has become the dominant form of bipolar logic on the moth side all of the different logic families are used however today in our examples we will only be talking about cmos or complementary metal oxide semiconductors ttl is a transistor transistor logic family this logic family was originally designed using bipolar transistors ttl logic 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 upon 5 volt logic and power supplies some newer variations of the ttl logic family use cmos and biomos technologies instead of just bipolar transistors here is how you read the part number on a ttl logic chip the first two characters are the manufacturer's prefix and this will be unique for every different manufacturer the next two characters determine whether the logic kip is a military spec chip in which case there will be a 5-4 or a commercial chip which is a type 7 for most of our designs will use 74 type tips however note that military spec ships are sometimes used for designs that need to work 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 construct 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 that precede this that indicate 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 constructed in now here's a chart that describes some of the chips in the 7400 ttl logic series and some of the different technologies used to construct them this is only a subset of the complete list the 7400 chips at the very top are no longer used they were the original ones now the part numbers remain the same regardless of which series you use so for example if you have a 7402 gate then the pin out of that will be the same as a 74 als o2 or a 74 hco2 now many of these use standard ttl or bipolar technology and have a voltage requirement of about 5 volts however you'll notice there are a couple of cmos designs as well 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 is recommended as it can accommodate different supply voltages another good series for new designs is a 74 hct series which will maintain compatibility with the older ttl chips but offer the advantages of reduced current consumption that cmos offers standard ttl gates have what is referred to as a totem pole output this uses two transistors which are turned on or off alternatively to send either a zero or one to the output this design provides low power consumption and it is also very fast at switching the same design can be used for tri-state logic chips in this case both of the transistors are turned off to put the chip into a high impedance state some ttl chips use open collector outputs in this case the load needs to be connected between the output and the vcc which is generally 5 volts this design allows for a high current output letting you drive items like leds for example when using an open collector output chip with other logic chips you'll require a pull-up resistor a disadvantage of the open collector output is that it is slower than the totem pole design now here's the pin outs for a typical ttl logic chip in this case it's a 7400 quad 2 input nand gate it's called a quad because there are four nand gates in the package notice that this will be the same pin out used for the 74 ls 0 0 and 74 hc 0 0 and all of the other 7400 series note also that the vcc which in most cases is 5 volts is applied to pin 14 and the ground is applied to pin 7. these two pins are diagonal to each other and you'll 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 the ground another popular series of logic chips are the 4000 series which were developed by rca in 1968. these chips use a cmos design for low power consumption they can operate on a wide range of supply voltages the cmos design provides an increased fan out capability over the ttl design so less buffers are required and you can connect more chips together the high impedance inputs used in this design make interfacing much easier the 4000 series chips however are slower than the 7400 series ttl chips so they're not suitable for all applications despite their age these chips are still very common in new designs so now that you know more about logic families let's go and start working with some of these chips all right well enough theory now it's time to actually wire up a few of these logic chips and i'm going to be using the 74 ls series of ttl chips because they're probably the most popular and most easily obtained chips that there are now i'm also going to be taking advantage of the fact that several of these chips have compatible pin outs not only that they have power and ground on the same pin but they contain logic gates that have their inputs and outputs tied to the same pins as well we're going to use that to check a number of different gates with the same circuit and then i'll show you another circuit as well that demonstrates three-state logic so let's get going on that the four-ttl logic chips that i'll be working with today are all packaged in a 14-pin dip or dual in-line 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 inputs and one output the first gate has its input a on pin 1. input b will be on pin 2 and the output or y connection will be on pin 3. this pattern is repeated for the other three logic gates the 74 ls00 is a quad nand gate you'll notice the 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 gate with the same pin outs the 74 ls 32 is a quad or gate and the 74 ls 86 is a quad exclusive or gate again with the same pinups we can test all of these chips with the following circuit you can just substitute whatever chip you want for the 14 pin dip that is shown here on inputs a and b which are on pins 1 and 2 we've arranged a push button with a 2.2 k pull down resistor this way when the button is pressed it'll send 5 volts to these pins so a pressing of the button will create a 1 and releasing the button will pull it down to 0. i've got the output on pin 3 going through a 330 ohm resistor to an led notice that i'm driving the led directly from the chip and this is fine as long as you are only driving one led you cannot drive leds from all four outputs at the same time as this would likely exceed the maximum current capabilities of the chip for that application you would use open collector outputs this is a very simple circuit to wire up on a solderless breadboard so let's do that and check our logic chips now here's our little digital demonstrator circuit that we're going to use with four different chips and i've got one plugged into it already and you can see an led glowing indicating that the chip's output is high now the two push buttons for the input are buried down here i'm not sure how well you can see that on the video and the chip that i've got in here is a 74 ls00 and that is a quad 2 input nand gate and so a nand gate's output will be high unless both of the inputs are high so right now both of the inputs are low because i haven't pressed any of the buttons and the output is indeed high if i press one of the buttons to bring it input low to bring an input high excuse me it doesn't have any effect and the other button to bring an input high also has no effect but pressing the both simultaneously sends the output low and that is indeed the function of a nand gate it is the inverse of an and gate and so i'm going to remove the power and remove that chip and replace it with another one that has a compatible pin out and what i'm going to put in here now is a 74 ls 0 8 and the 74 ls08 has the same pin outs but this is a quad 2 input and gate so when i apply power i have no output because the output currently is low because both my inputs are low and if i press one of the inputs high it's no effect the other input no effect both of the inputs however light the output and send it high because an and gate is only high on the output if both of the inputs are high okay let's swap that over and by the way i'm wearing my anti-static strap but ttl chips are pretty rugged and you don't have 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 and so we'll put the hook it back up and right now i have no output over here and both of my inputs are zero but if i press one of the inputs and send it high the output goes high if i press the other input high the output goes high and both of them also send it high and that of course is the nature of an or gate if one or the other or both of the inputs are high the output goes high and now let's place another and final chip in here and this is a 74 ls 86 and the 74 ls 86 is a quad exclusive or gate and so i've applied power again i have no output the output is low and both of the inputs are low that's what you'd expect and if i press one of the inputs and send it high the output goes high if i press the other input and send it high the output also goes high but if i press them both at the same time and send them high the output is low because an exclusive or gate only goes high when one or the other but not both inputs are set high and so there you go you can easily demonstrate the operation of several popular digital logic chips thanks to the fact that they happen to have the same pin outs now for this next demonstration i want to show you the operation of three-state logic now you recall that we talked about three-state logic this is a type of logic which in addition to having an output that can either be high or low can also have a high impedance output and this can be used when you want to join two logic circuits together onto a common bus now as you can see i've got a demonstrator here with a lot of wires on it so rather than showing you the individual hookup i will explain instead what i have over here and show you in more of a block diagram form of how this is actually working now if you look over here you'll see i have a couple of sets of dip switches two four position dip switches and over here i have some leds four leds i also have a switch over here that you may or may not be able to see it's wired to the board and this is a single pole double throw switch with one side connected to ground one side connected to five volts and so that way by throwing this switch the output will either go to ground or five volts now what this is demonstrating as i said is three state logic so the heart of this are these two chips over here and these are 74 ls 125s and what 74 ls 125s are are they are quad buffer tips they have four buffers in them but these are three state buffers so each buffer has an enable line on them and so what i've done is i've taken the output of these switches over here these switches use pull down resistors so that when they're switched on they're high when they're switched off they're low and they are being fed into the four different gates in a 74 ls 125 that's why i have two of these chips there's one for each one of these dip switches here now the enable lines for the 74 ls 125s are all tied in common on each chip so all of the 74 ls 125 enables on this chip are in common and all of the ones in this chip are in common as well now those enable lines are being sent back over here now this circuit uses my switch that switches between ground and 5 volts and feeds that into the input of an inverter this is 74 ls04 the output of that inverter is fed into the enable line of one of these ics over here now these enable lines activate the buffers when they go low they're an active low enable so if this is set to high it goes to the inverter becomes 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 this one's enable line 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 being sent to another chip and this is a 74 ls07 and that's just a quad buffer chip but this chip also has an open collector output and so i can use it to drive leds so that's basically what's happening is i've got two banks of dip switches each feeding their own set of quad buffers and since the buffers are three state buffers 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 right now the switch is in this position over here and i appear to have the output of this particular dip switch over here so if i change some values on it we'll see those values changing up on this leds over here now if i flip the switch over here i'm now using the values from this dip switch because the three state gates are enabled for this switch but not for the other one and there you go a fairly simple demonstration of how three state logic works now for our next experiment we're going to bring an arduino into the picture you know we couldn't go this long without bringing arduino in right and what we're going to do with the arduino is we're going to emulate six of the seven basic logic gates the only one we won't emulate will be the not gate because that's a pretty simple one what goes in is the opposite of what goes out this is going to be used to build sort of a little logic gate trainer that shows you the operation of the gates but you can also use this as an exercise in programming because this will show you what statements we can use in our programs that are the equivalent of all of the basic logic gates so let's go and take a look at the hookup for that and for the code of our logic emulator for a logic emulator you will require an arduino uno a couple of push button switches two leds to represent the inputs you can use any color you like i use two red leds you'll need six leds to represent the outputs i use green leds but i'm showing yellow ones here as it's easier to see on the blue background you can use any color you like or you can even use different colors for each led you'll need two two point k drop down resistors for the push buttons you'll also need eight 220 ohm dropping resistors for the led now any value from 150 to 470 ohms of work we'll start by connecting the exclusive nor led anode to pin 6 of the arduino through one of the 220 ohm dropping resistors we'll make the same connection for the exclusive or led to pin 7 of the arduino through its dropping resistor the nor led will connect the pin 8 of the arduino through a dropping resistor the or led anode will connect the pin 9 of the arduino through its dropping resistor the nand led anode connects to pin 10 of the arduino through a dropping resistor and finally the and led anode connects to pin 11 of the arduino through a 220 ohm dropping resistor the a led anode also goes through a 220 ohm dropping resistor and connects to pin 12 of the arduino and the b led connects through to pin 13 with its dropping resistor all of the cathodes of the leds are connected to the arduino's ground we'll connect one side of each of the push buttons to the positive 5 volts from the arduino the other side of each of the push buttons will go to ground through a 2.2 k dropping resistor we'll take that same connection on the a push button and connect it to arduino pin 4 and finally we'll connect the dropping resistor side of the b push button to arduino pin 5 and this completes the wiring of our logic emulator now here's a sketch that we're going to be using for our logic emulator and it's a very basic sketch we start off by defining a number of booleans as being inputs and outputs because of course we're going to be working with boolean logic and then we define the devices like the push buttons and the leds that we're using to represent the different logical outputs as well as the leds that we're using to represent the logical inputs we go into this setup we're going to set up the serial monitor because we're going to display our results there as well as on the leds we'll define our two push buttons as inputs and we'll define all of our leds as outputs so it's all very basic up to there we go into the loop and we're going to read the buttons and assign values to them so in a and in b will be the values of push buttons a and b respectively and remember when these are pushed they're going to go to a 1 and then we will write those values to their respective leds over here and then we go and compute the logic outputs and this is really this part of the code that you're going to want to look at because it'll show you the symbols that you can use for all the different boolean operations let's go at the bottom after here and out and is the and output so it's in a and in b so this is the symbol we use for an and now the out nand is the inverse of that so we do n a and in b and then we use this the exclamation mark to invert everything now this is the symbol that we use for an or and this of course will be what we use for a nora we'll just invert the or statement over here and this symbol is used for exclusive ores and so an exclusive nor is going to be the same thing up over here with an inversion on the front so there you have an and an or an exclusive or and an inversion the four basic logic functions represented in arduino code now we'll just go and display the results up to the serial monitor and then we will write to the respective leds to show whether the output is high or low we'll apply a short delay and run the loop over again so it's a very simple sketch let's go and take a look at it in action now and so here's my logic emulator and as you can see i've labeled all of my leds so these are my six outputs and these are my two inputs the a and the b and you'll also notice that the serial monitor is displaying the values of the led outputs as well now right now it is set with a and b equal to zero and you'll see that some of my outputs are high as indicated by the illuminated led and some are low and let's check the logic on that because it is correct this is an and gate and with two inputs low its output should be low indeed it is a nand gate is the inverse of an and gate so its output is high and or gate is also low on the output when both inputs are low a nor gate is its inverse so it has got a high output and an exclusive or gate is also low if both of the inputs are low and so an exclusive nor gate has a high output so let's press one of the switches my switches are buried back over here and i'll press down the a switch and as you can see we've had a couple of changes over here the or gate has now gone high because one of the inputs has gone high and that is correct logic the and gate is still low because only one of the inputs is high at the moment the exclusive or gate has gone high because one of the inputs is high but the other one isn't and of course the other gates are just the inverse of these gates now we'll hit the b switch and we'll notice pretty well the identical thing that the or gate and the exclusive or gate are now high and the and gate is low and if we hit both of the switches and bring them both high the and gate has gone high as you would expect the or gate is also high the exclusive or gate is low and that's correct because the exclusive or gate will only be high if only a or only b is high but if they're both high the output is low and of course these other gates are just the inverse of that and so there you have it the logic emulator now one thing this would be good for would be for training purposes and an interesting exercise would be to build this and to not label these and just have someone cycle through the four different possibilities of a and b and try to determine which gate is which and that will show you if you really have a proper understanding of how these logic gates work so it actually probably does have a practical purpose now for our final project today we're going to combine an arduino and a basic logic gate in order to create a rudimentary intruder alarm and this is a circuit that you can expand on in order to create a real practical intruder alarm now as it is this is just 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 onto it but the way our alarm is going to work is it's going to have two connections or two what i call loops an open loop and a closed loop on a closed loop circuit you have a wire that is connected one end and the other and if this wire is broken in any way the alarm will go off and you can use that with sensors such as the foil tape that you place onto windows that would be broken if the window is smashed or something like a magnetic reed switch that you can place into a door or a window frame that would open when the door or window is opened and a closed loop circuit is actually the most secure because anybody trying to thwart the alarm by cutting the wire is actually going to set the alarm off there's also the open loop in which you need to apply voltage to make the alarm work and this is good for sensors such as doormat switches or for things such as emergency push buttons so you can have an emergency switch for your alarm our alarm is going to have both and both of these are going to trigger interrupts on the arduino now the arduino uno only has two interrupt inputs but we're going to be using four inputs two closed loop and two open loop ones and we'll be using a tto logic chip in order to combine all those signals and send them to our interrupts so let's go and take a look at the hookup of our alarm and then i'll show you the code and then we'll demonstrate it our intruder alarm is going to be based upon an arduino and a 74 ls 132 which is a quad nand gate with schmidt triggers now if you don't have a 74 ls 132 you could use a 74 ls00 which is a quad nand gate with the same pin outs you would not get the benefit of the schmidt trigger then now for our alarm we are going to have a condition where we are going to be looking for an interrupt going high so therefore in normal operation the interrupt should be held low for the open loop circuit the circuit that needs to activate an alarm when it goes to 5 volts we can satisfy this requirement with an or gate we'll use three of the nand gates in order to create an or gate to do that on the closed loop side we need a nand gate because in the closed loop the inputs will always be held at 5 volts if one of them goes down to 0 the alarm will be activated and a nand gate fits this requirement because its output will be low as long as both inputs are high but if one of those inputs goes low it will be high remember a high input to the interrupt pin activates the alarm now let's take a look at the circuit we'll use with the 74 ls 132 in addition to the 74 ls 132 you're going to need an arduino uno an led that we will use for the alarm output a 220 ohm dropping resistor for that led actually any value from 150 to 470 ohms would work fine you'll need two push buttons for reset and emergency a 10k pull down resistor for the arduino and four 2.2 k pull down resistors for the ttl gate the alarm will also have three sets of input connections it'll have two closed loop inputs and one open loop input we'll begin our hookup by connecting the 5 volts from the arduino to pin 14 of the 74ls 132 the ground from the arduino will be connected to pin 7 of the 74ls 132 the led anode goes to pin 13 of the arduino through its 220 ohm dropping resistor the led cathode is connected to ground arduino pin 12 is connected to one side of the alarm reset switch from that same connection we will go to ground through a 10k drop down resistor the other side of the alarm reset switch is connected to 5 volts one side of our emergency switch is connected to 5 volts the other side of the emergency 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 2.2 k drop down resistor pins 12 and 13 of the 74 ls-132 are connected to the ol1 input that's the open loop input pin 1 of the 74 ls 132 is connected to the cl2 input pin 2 of the chip is connected to the cl1 input all of the alarm inputs are grounded through a 2.2 k drop down resistor and the other side of all the inputs is a connection to the 5 volt line on the 74 ls 132 we'll need to connect pins 11 and 5 together we'll also need to connect pins 8 and 4 together connect the gate output on pin 6 to the interrupt 0 interrupt on the arduino which is pin 2. the gate output on pin 4 is connected to interrupt 1 which is arduino pin 3. now you'll need to close both the c01 and cl2 connections 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've wired our alarm let's go and take a look at the code we'll use in order to make it work now here is the code that we're going to be using for our intruder alarm now we start off by defining an integer that represents the alarm state and our alarm can have three different states a state of zero means there is no alarm a state of one or two means there's an open loop or a closed loop alarm now you'll notice we made this integer volatile and the reason is that alarm state is manipulated in our interrupt handlers and we need to let our compiler know that by telling it that this is a volatile integer now the next integer that 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 our emergency button is not connected to the arduino directly but it's part of our logic circuitry then we have some values for the alarm loop pins the open loop and the closed loop respectively that are connected to our interrupt pins then we 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 pin 2 and the closed loop connection on pin 3 and pin 2 is also interrupt 0 pin 3 is interrupt number 1. now in the setup we're going to initialize the serial port because we're going to also print our alarm status to the serial port we'll define our inputs and outputs so the led is an output and the reset switch is an input and then we attach our interrupt handlers our interrupt handler for interrupt zero on pin two is going to go to this interrupt service routine and on pin on interrupt number one excuse me which goes to pin number three we will get this interrupt service routine and these are going to be called on a change of values on the interrupt pin now here's the two interrupt service routines themselves so the open loop intrusion detected is going to set the alarm state the value of 1 and turn the alarm led on and it's almost the same thing when the closed loop intrusion is detected except it changes the alarm state to a 2 so these are the two interrupt handlers that we have over here we also have another function called clear alarm and that clears the alarm led turns it off and resets the state down to zero and also prints to the serial monitor that the alarm has been reset note that we don't print the serial monitor in our interrupt handlers because we can't really use the serial port within an interrupt handler routine now we go into the loop and in the loop we start off by looking at the value of the alarm status remember the alarm state is going to be changed by the interrupt handlers and so if it is a 0 everything is ok we just print ok out to our serial monitor if it is at number one though then we print that we have an open loop alarm condition and if it's number two we print that we have a closed loop alarm condition the other thing we need to check to see is do we have a reset push button being pressed so we measure the button state we assign button state value excuse me to a digital read of the alarm reset and if the button state is low then the button has been pressed and so we first of all have to see is this a legitimate reset because if the alarm condition still exists we don't want to reset so we'll take the value of 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's still an open loop alarm and we do the same thing with a closed loop value if it's high we cannot reset there's a closed loop alarm and we exit but if none of these conditions are true then we can indeed do a reset and we call that clear alarm function that we just saw in order to reset everything at the end of loop we add a slight time delay and do it all over again and remember that the alarm led is being driven in the interrupt handlers not in the loop it's only being reset when we call the clear alarm function over here and so this is the code for our intruder alarm let's go demonstrate it now so here's my alarm circuit on a solderless breadboard also you can see the serial monitor display which is displaying okay right now because we're 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'll be illuminated if we're in alarm condition the red push button switch over here is my reset switch that's the one that's connected directly to the arduino buried back in here i'm not sure how well you can see it is a black push button switch and that's connected to the logic chip and that will trigger an open loop alarm so if that is triggered it'll close that open loop and cause an alarm it's an emergency push button so to speak and these long orange wires here are my closed loop alarm they're connected to five volts and if one of them becomes disconnected or broken then the alarm should go off so right now let's try my emergency push button i'll hit the push button and as you can see i'm displaying open loop alarm and my alarm is illuminated and i can hit my reset switch and it says alarm reset and the alarm is back and armed and okay so now let's break the closed loop let's pull one of these orange wires here and again i've got a closed loop alarm the alarm is illuminated let's try to reset this right now if i do it's can't reset it says closed loop alarm condition still exists and so i will put this back to 5 volts over here note the alarm is still on until i go and reset and that turns it off and so that's the function of our basic alarm with an arduino and a ttl logic chip one interesting story of 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 ceo of intel and in 1965 he was showing off intel's latest accomplishment which was to put 60 transistors onto one silicon chip a great achievement in 1965 and mr moore predicted that every two years the number of transistors that they could put onto a chip would double while the cost would be halved now this prediction seems to have pretty well held up since then mr moore's own company in 1974 released the world's first commercial microprocessor the intel 4004 and that chip had 2600 transistors on it fast forward to today and we have a lot of transistors which are all mosfets on our chips now amd has a microprocessor that has a whopping 38.54 billion mosfets on it nvidia has a graphics processor that has 58 billion mosfets on it but even these numbers are nothing when we compare them to memory chips now samsung has developed a technology with their vnand chips of using one mosfet to store four bits of data which means you need two mosfets per byte and they have a one terabyte memory chip meaning that that chip has over two trillion mosfets on it one little trivia thing is that if you take a look at all the mosfets that we've placed on all of the silicon chips throughout time it makes the mosfet the most manufactured device on earth and with saying that i would like to thank you for taking all of the mosfets in your device and aiming them at youtube so that you can watch this video i really appreciate it if you'd like to see more videos from me the best way to find out about them is to subscribe to the youtube channel and you can do that by clicking the subscribe button just below this video and after you do that also remember to click the little bell notification and that way you'll be notified every time i make a new video if you want some more information about the stuff we talked about today about digital logic you can go to the dronebotworkshop.com website and you will find an article that accompanies this video there's a link to that article in the description of the video while you're on the website please consider signing up for the newsletter it's my way of staying in touch with you and letting you know what is going on in the workshop and of course if you want to discuss electronics be it basic digital electronics or very advanced microcontrollers the best place to go is the dronebot workshop forums and there's information about joining the forum right below this video as well so until we meet the next time please take care of yourself please stay safe in these trying times and i will see you again very soon here in the workshop goodbye for now [Music] you
Info
Channel: DroneBot Workshop
Views: 215,624
Rating: 4.9472718 out of 5
Keywords: logic gates, boolean algebra, logic gate, arduino, arduino intruder alarm, arduino with ttl, ttl logic, arduino logic, arduino logic gates, digital electronics, not gate, and gate
Id: 7Mkl_TruAcc
Channel Id: undefined
Length: 63min 51sec (3831 seconds)
Published: Mon Sep 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.