Help with the Simple Combination Lock

Thread Starter

derderppolo

Joined Nov 19, 2012
17
It's true that, with the switch not pressed, the LED on the output of the 74LS04 will be lit. That's probably not what you intended.
The circuit works just as intended now, but I have a question about the logic.

When the signal from the OR gates is high or low, how come only 1 of the LEDs light up when the button is pressed? How come both LEDs don't turn on, when in the schematic and breadboard, both LEDs are comng from the same "root".
 

Ron H

Joined Apr 14, 2005
7,014
The circuit works just as intended now, but I have a question about the logic.

When the signal from the OR gates is high or low, how come only 1 of the LEDs light up when the button is pressed? How come both LEDs don't turn on, when in the schematic and breadboard, both LEDs are comng from the same "root".
When the OR gate goes low, a current path exists from +5V, through the LED and the resistor, and the output of the OR gate to ground (the other side of the 5V supply is also tied to ground). The low input on the inverter makes its output high, so there is no current path from +5V to ground for the red LED.
When the OR gate output goes high, there is no current path from +5V through the green LED to ground. The high input on the inverter makes its output low, so there is a current path from +5V, through the red LED and the resistor, to ground.

Maybe the attachment will help.
 

Attachments

elec_mech

Joined Nov 12, 2008
1,500
The OP will probably learn a little from this if he understands it, namely that a data byte that is 2's complement to the code byte will make all XOR outputs high, which can be decoded by an AND or NAND gate.
Took me longer than I care to mention, but I finally got it. Nice.

Elec_mech, I believe you may have also gained some experience with TTL logic through this whole experience too. ;)
This is true. One of the many reasons I love this forum. :D

I am also a bit confused as to what 5VDC means; is it 5Vs of power or ground? Since the green LED is connected to 5VDC, should the cathode be connected to ground, or power? Also, by 5VDC, that means I should use a 9-to-5 converter, right?
TTL circuits require 5VDC to operate. I tried to distinguish + and - by referring to them as 5VDC and GND, respectively. Generally speaking, when referring to the positive side of power (+) you call out Vdd or Vcc. GND often refers to the negative side unless you're truly using a negative voltage such with op-amps. GND is always at 0VDC though.

It's true that, with the switch not pressed, the LED on the output of the 74LS04 will be lit. That's probably not what you intended.
Shucks, I missed that. If the 74LS04 has an internal pull-up, then that could well be the case. Normally the solution is to use a pull-down resistor, but that won't work due to TTLs preferring pull-ups and the green LED.

This would be solved if the switch was not present, but I was trying to follow the original circuit in operation.

It appears this has worked for the OP, but RonH, if I may, do you have any suggestions as to how to guarantee the red LED stays off when the switch is not pushed?

derderppolo, I'm a little confused. The red and green LEDs appear reversed on your board relative to the schematic I posted. Did you use NOR gates instead of OR gates or was a change necessary somewhere else? I'd love to see a schematic of how you ended up wiring it.
 

Thread Starter

derderppolo

Joined Nov 19, 2012
17
When the OR gate goes low, a current path exists from +5V, through the LED and the resistor, and the output of the OR gate to ground (the other side of the 5V supply is also tied to ground). The low input on the inverter makes its output high, so there is no current path from +5V to ground for the red LED.
When the OR gate output goes high, there is no current path from +5V through the green LED to ground. The high input on the inverter makes its output low, so there is a current path from +5V, through the red LED and the resistor, to ground.

Maybe the attachment will help.
Ah, I understand how it works now. When the OR gate output is high, meaning different combination, the current travels to the red LED, and the inverter gives the green LED a low signal. When the OR gate output is low, meaning the same combination, the red LED stays off because the signal is low, and and inverter gives the green LED a high signal.

Thanks! Makes much more sense now.

derderppolo, I'm a little confused. The red and green LEDs appear reversed on your board relative to the schematic I posted. Did you use NOR gates instead of OR gates or was a change necessary somewhere else? I'd love to see a schematic of how you ended up wiring it.
That's true, when I finishing building the schematic, I noticed when the correct combination is entered, the red LED turned on. When the incorrect combination is entered, the green RED turned on. To fix this, I simply switched the placement of the LEDs.

I did not use NOR gates, and stuck with the OR gates in the original circuit.

I have attached a schematic of how my circuit looks like.

Thanks again!
 

Attachments

Last edited:

Ron H

Joined Apr 14, 2005
7,014
Ah, I understand how it works now. When the OR gate output is high, meaning different combination, the current travels to the red LED, and the inverter gives the green LED a low signal. When the OR gate output is low, meaning the same combination, the red LED stays off because the signal is low, and and inverter gives the green LED a high signal.

Thanks! Makes much more sense now.
Your explanation doesn't make sense to me.

When the OR gate is low, meaning the same combination, current flows through the green LED. The inverter output will be high, turning off the red LED.
When the OR gate is high, meaning different combination, the green LED is off. The inverter output will be low, turning on the red LED.
 

elec_mech

Joined Nov 12, 2008
1,500
Your schematic shows both LEDs connected to GND, not 5VDC. I can't tell by your pictures - how are the LEDs connected? The anode should go to +5VDC, the cathode to the 220Ω resistor.

RonH has described how the circuit, as I originally laid it out, works. That is, the green LED is connected to the output of the last OR gate and the red LED is connected to the output of the NOT gate.
 

Thread Starter

derderppolo

Joined Nov 19, 2012
17
Your explanation doesn't make sense to me.

When the OR gate is low, meaning the same combination, current flows through the green LED. The inverter output will be high, turning off the red LED.
When the OR gate is high, meaning different combination, the green LED is off. The inverter output will be low, turning on the red LED.
Oh, that makes sense, but when I build the circuit, it was the other way around. The explanation I gave is how the circuit I built worked, as I had to switch the positions of the green & red LEDs.

Your schematic shows both LEDs connected to GND, not 5VDC. I can't tell by your pictures - how are the LEDs connected? The anode should go to +5VDC, the cathode to the 220Ω resistor.

RonH has described how the circuit, as I originally laid it out, works. That is, the green LED is connected to the output of the last OR gate and the red LED is connected to the output of the NOT gate.
The cathodes are in GND, and the anodes are connected to the 220Ω resistors.

Is that wrong? I mean, when I built it, the circuit works just fine, no errors, no reliability issues, just fine.
 

Ron H

Joined Apr 14, 2005
7,014
Oh, that makes sense, but when I build the circuit, it was the other way around. The explanation I gave is how the circuit I built worked, as I had to switch the positions of the green & red LEDs.



The cathodes are in GND, and the anodes are connected to the 220Ω resistors.

Is that wrong? I mean, when I built it, the circuit works just fine, no errors, no reliability issues, just fine.
That explains why you had the LEDs swapped. When you connect the cathode to ground, the IC has to go high to drive it. When you connect the anode to vcc (+5V), the IC has to go low to drive it.
It is always better to use anode to vcc. TTL can sink up to 16ma (output low). It can only source a few mA (output high). You will probably find that your LEDs are brighter (using the same resistors) if you use anode to vcc.
 

elec_mech

Joined Nov 12, 2008
1,500
The cathodes are in GND, and the anodes are connected to the 220Ω resistors.

Is that wrong? I mean, when I built it, the circuit works just fine, no errors, no reliability issues, just fine.
Yes, that is wrong. I'm not quite sure how it is working, but the TTL gates are designed to sink current, not source it. This means the load, the LEDs in this case, should be connected to +5VDC (anode) and the cathode gets connected to the TTL output through the resistor.

Look at the datasheet for the OR and NOT gates. Look specifically at the current rating when the output is high and when it is low. You'll see the current rating for the low output (when output is logic zero/low) is around 18mA or so. Most LEDs operate around 10-20mA, so that is okay. Now look at the current rating for the high output (when the output is logic one/high, in this case, 5VDC). This is something like 1mA.

This means when you have a LED (load), the output can safely supply supply ~18mA if the LED cathode is connected to the output of the IC and the anode is connected directly to Vcc (+5VDC). If you wire it like you did where the cathode is connected to GND and the anode is fed to the output of the IC, the IC can only supply 1mA. The LED requires more than that and will attempt to pull more current from the output of the IC. This can result in burning up the IC over time if not immediately.

Additionally, assuming the IC output can somehow safely supply enough current to the LED, the LEDs will come on in reverse (green is on when red is supposed to be on and vice versa). If you connect the LEDs according to the original circuit - where the anodes are tied to +5VDC and the cathodes, through the resistors, are fed to the output pins of the ICs - you'll see the circuit behaves as expected and you won't risk damage to the ICs.

Electronics is so much fun, ain't it? :) Be careful to follow schematics as they are shown in the future - if it doesn't look right or you don't think it will work as shown, ask before wiring it differently. Doesn't sound like you've done any major damage, but it is real easy to destory something by wiring it wrong. We all, including myself, have enough trouble wiring up something when we're trying to follow a schematic to a T sometimes. Putting an electrolytic capacitor in the wrong direction will destory it, or, like I've done, putting a cap rated for 10V into a circuit using 15V (my, that was not a pleasant popping sound at 12 inches away).
 

Thread Starter

derderppolo

Joined Nov 19, 2012
17
Yes, that is wrong. I'm not quite sure how it is working, but the TTL gates are designed to sink current, not source it. This means the load, the LEDs in this case, should be connected to +5VDC (anode) and the cathode gets connected to the TTL output through the resistor.

Look at the datasheet for the OR and NOT gates. Look specifically at the current rating when the output is high and when it is low. You'll see the current rating for the low output (when output is logic zero/low) is around 18mA or so. Most LEDs operate around 10-20mA, so that is okay. Now look at the current rating for the high output (when the output is logic one/high, in this case, 5VDC). This is something like 1mA.

This means when you have a LED (load), the output can safely supply supply ~18mA if the LED cathode is connected to the output of the IC and the anode is connected directly to Vcc (+5VDC). If you wire it like you did where the cathode is connected to GND and the anode is fed to the output of the IC, the IC can only supply 1mA. The LED requires more than that and will attempt to pull more current from the output of the IC. This can result in burning up the IC over time if not immediately.

Additionally, assuming the IC output can somehow safely supply enough current to the LED, the LEDs will come on in reverse (green is on when red is supposed to be on and vice versa). If you connect the LEDs according to the original circuit - where the anodes are tied to +5VDC and the cathodes, through the resistors, are fed to the output pins of the ICs - you'll see the circuit behaves as expected and you won't risk damage to the ICs.

Electronics is so much fun, ain't it? :) Be careful to follow schematics as they are shown in the future - if it doesn't look right or you don't think it will work as shown, ask before wiring it differently. Doesn't sound like you've done any major damage, but it is real easy to destory something by wiring it wrong. We all, including myself, have enough trouble wiring up something when we're trying to follow a schematic to a T sometimes. Putting an electrolytic capacitor in the wrong direction will destory it, or, like I've done, putting a cap rated for 10V into a circuit using 15V (my, that was not a pleasant popping sound at 12 inches away).
Whoa, sounds like I made a really serious mistake.

I've switched the LEDs back, and put the cathodes to the 220Ω resistor, and the anodes to power.

Now, the red LED is always on, except when the combination is correct and I push the button. When I am not pressing the button, regardless of the combinations, it is on. When I push the button and the combination is wrong, it stays lit. When I push the button and the combination is correct, it is the only time it turns off.

Also, if I connect the anodes to power and cathodes to the resistor, wouldn't that mean the current is drawn from the LED, to the button, and into the gates? When I had the anodes to the resistor and the cathode to GND, everything seemed to make sense as the power comes from the gates, to the button, and if it's pressed, the current goes to the LEDs. Now, it seems that the power goes from the LEDs, to the button, and into the gates. The way I had the circuit seemed to make more sense, but if I am damaging my circuit, I should fix it.

Electronics is indeed very fun. :D
 
Last edited:

Ron H

Joined Apr 14, 2005
7,014
You can't hurt a TTL gate by driving a 2V LED through 270Ω to GND, but, as elec_mech said, you won't get much light from the LED. The current output specs for logic gates are always qualified by the logic levels, i.e., IOL@VOL, IOH@VOH. They don't mean you can't get more current, but the logic level will not be guaranteed. If you are driving an LED in addition to another logic device, you have to observe the max output current limits, or your driven gate may not switch. Exceeding a TTL IOL can possibly cause damage, because the current level is higher, so power dissipation might be an issue.
 

Ron H

Joined Apr 14, 2005
7,014
Whoa, sounds like I made a really serious mistake.

I've switched the LEDs back, and put the cathodes to the 220Ω resistor, and the anodes to power.

Now, the red LED is always on, except when the combination is correct and I push the button. When I am not pressing the button, regardless of the combinations, it is on. When I push the button and the combination is wrong, it stays lit. When I push the button and the combination is correct, it is the only time it turns off.

Also, if I connect the anodes to power and cathodes to the resistor, wouldn't that mean the current is drawn from the LED, to the button, and into the gates? When I had the anodes to the resistor and the cathode to GND, everything seemed to make sense as the power comes from the gates, to the button, and if it's pressed, the current goes to the LEDs. Now, it seems that the power goes from the LEDs, to the button, and into the gates. The way I had the circuit seemed to make more sense, but if I am damaging my circuit, I should fix it.

Electronics is indeed very fun. :D
See post #24 to fix the LED problem.
If you go back to the way you had it, you will be learning some bad lessons that will come back to bite you in the future.
 
Last edited:

elec_mech

Joined Nov 12, 2008
1,500
Now, the red LED is always on, except when the combination is correct and I push the button. When I am not pressing the button, regardless of the combinations, it is on. When I push the button and the combination is wrong, it stays lit. When I push the button and the combination is correct, it is the only time it turns off.
As Ron pointed out, I made a boo-boo. Because the input to the NOT gate is effectively not connected when the switch is open and we cannot use a pull-down resistor, the NOT gate likely has an internal pull-up resistor causing the red LED to light when the switch is open.

Ron came up with a fix from post #24:

http://forum.allaboutcircuits.com/attachment.php?attachmentid=49180&d=1354377700

Also, if I connect the anodes to power and cathodes to the resistor, wouldn't that mean the current is drawn from the LED, to the button, and into the gates? When I had the anodes to the resistor and the cathode to GND, everything seemed to make sense as the power comes from the gates, to the button, and if it's pressed, the current goes to the LEDs. Now, it seems that the power goes from the LEDs, to the button, and into the gates. The way I had the circuit seemed to make more sense, but if I am damaging my circuit, I should fix it.
This is why looking at datasheets is so important. Look again at my last post and look at the datasheets again. It's very important you understand how this is working. It can be a little confusing - I still have to find my bearings now and then - but not impossible.

The simplest explanation is to look at Ron's diagram from post #22: http://forum.allaboutcircuits.com/attachment.php?attachmentid=49168&d=1354337872.

Think of the OR and NOT gate outputs as switches. If the output is low, the output is connected to GND. If the output is high, the output is connected to +5VDC. So far, it seems it wouldn't matter how the LED is hooked up, but looking at the datasheets, we note the outputs can "sink" 8mA and "source" -0.8mA. The - sign just denotes the direction the current is flowing in, so simply put, the output pin can source 0.8mA.

Now, sinking refers to having the load's anode side connected directly to Vcc, +5VDC in this case, and connecting the cathode to the output pin. When the output is logic zero, 0VDC or GND, there is a potential difference across the load: +5VDC on the anode side, 0VDC on the cathode side. When there is a potential difference, current flows and the load is powered. Since the output pin is "sinking" current, the pin can safely provide up to 8mA to the load. If the load requires more than that, the output pin could burn up internally.

Sourcing refers to just the opposite, what you were doing earlier. The cathode of the load is connected directly to GND. The anode is hooked up to the output pin. When the output is logic one (+5VDC), again there is a potential difference across the load and current flows. However, according to the datasheet, the output pin can only safely provide 0.8mA. This is not enough to power an LED. If the current-limiting resistor isn't high enough to limit the current to 0.8mA or less, the LED will try to pull more current and could damage the output pin. Of course, if the resistor was sized to limit the current to 0.8mA, you probably wouldn't see the LED light at all or it would be very, very dim.

Of course, since the output pins can only supply 8mA when sinking current, you probably want to resize the LED resistors to 470Ω. This will only give the LEDs about 6mA, but since you are using low power LED indicators, this should be fine.

Lastly, when you connect the LED's anode to +5VDC and the cathode to the output pin of the IC, when the output is logic one, the output is +5VDC. Therefore, the load sees +5VDC on both the anode and cathode. The voltage potential or difference is 0V. Therefore, no current flows. Same holds true in the reverse - cathode connected to GND, anode connected to output, and output logic zero (GND).

If I haven't totally confused you at this point, let me know and I'll try harder. :D
 

Attachments

Thread Starter

derderppolo

Joined Nov 19, 2012
17
As Ron pointed out, I made a boo-boo. Because the input to the NOT gate is effectively not connected when the switch is open and we cannot use a pull-down resistor, the NOT gate likely has an internal pull-up resistor causing the red LED to light when the switch is open.

Ron came up with a fix from post #24:

http://forum.allaboutcircuits.com/attachment.php?attachmentid=49180&d=1354377700



This is why looking at datasheets is so important. Look again at my last post and look at the datasheets again. It's very important you understand how this is working. It can be a little confusing - I still have to find my bearings now and then - but not impossible.

The simplest explanation is to look at Ron's diagram from post #22: http://forum.allaboutcircuits.com/attachment.php?attachmentid=49168&d=1354337872.

Think of the OR and NOT gate outputs as switches. If the output is low, the output is connected to GND. If the output is high, the output is connected to +5VDC. So far, it seems it wouldn't matter how the LED is hooked up, but looking at the datasheets, we note the outputs can "sink" 8mA and "source" -0.8mA. The - sign just denotes the direction the current is flowing in, so simply put, the output pin can source 0.8mA.

Now, sinking refers to having the load's anode side connected directly to Vcc, +5VDC in this case, and connecting the cathode to the output pin. When the output is logic zero, 0VDC or GND, there is a potential difference across the load: +5VDC on the anode side, 0VDC on the cathode side. When there is a potential difference, current flows and the load is powered. Since the output pin is "sinking" current, the pin can safely provide up to 8mA to the load. If the load requires more than that, the output pin could burn up internally.

Sourcing refers to just the opposite, what you were doing earlier. The cathode of the load is connected directly to GND. The anode is hooked up to the output pin. When the output is logic one (+5VDC), again there is a potential difference across the load and current flows. However, according to the datasheet, the output pin can only safely provide 0.8mA. This is not enough to power an LED. If the current-limiting resistor isn't high enough to limit the current to 0.8mA or less, the LED will try to pull more current and could damage the output pin. Of course, if the resistor was sized to limit the current to 0.8mA, you probably wouldn't see the LED light at all or it would be very, very dim.

Of course, since the output pins can only supply 8mA when sinking current, you probably want to resize the LED resistors to 470Ω. This will only give the LEDs about 6mA, but since you are using low power LED indicators, this should be fine.

Lastly, when you connect the LED's anode to +5VDC and the cathode to the output pin of the IC, when the output is logic one, the output is +5VDC. Therefore, the load sees +5VDC on both the anode and cathode. The voltage potential or difference is 0V. Therefore, no current flows. Same holds true in the reverse - cathode connected to GND, anode connected to output, and output logic zero (GND).

If I haven't totally confused you at this point, let me know and I'll try harder. :D
I just built the circuit found here (Ron's circuit from post #24), and it works perfectly! The LEDs are a little brigher (hard to tell, as it was day-time before and now it's night), and I'm glad I am no longer doing any potential damage to my circuit & components. :D

But, I can't say I understand how it works. Through your explanation, I understand why we had to change from the NOT gate to the OR and NAND gates, because the output pins can only safely provide 0.8mA, which is not enough power to light an LED. Since the LED requires more, it sucks it up from the gates, and can possibly damage my circuit. Correct?

I understand the whole "sinking" idea, but how does it apply to the circuit? Is the current is sinking from the LED cathodes to the circuit? If so, where does the current go from there?

But back to my previous circuit; how likely was it for my components to get damaged? If I use a 9-to-5 converter, would that increase or decrease the likelihood of damage? Would I have been fine? The circuit I built was very similar to circuits that we built in class, with power, leading to logic gates, through a button and then to LEDs, which we had no problems with damaged components.

I am a much more visual learner, and pictures would be much appreciated and really helpful!

Thanks again!
 
Last edited:

Ron H

Joined Apr 14, 2005
7,014
I just built the circuit found here (Ron's circuit from post #24), and it works perfectly! The LEDs are a little brigher (hard to tell, as it was day-time before and now it's night), and I'm glad I am no longer doing any potential damage to my circuit & components. :D

But, I can't say I understand how it works. Through your explanation, I understand why we had to change from the NOT gate to the OR and NAND gates, because the output pins can only safely provide 0.8mA, which is not enough power to light an LED. Since the LED requires more, it sucks it up from the gates, and can possibly damage my circuit. Correct?

I understand the whole "sinking" idea, but how does it apply to the circuit? Is the current is sinking from the LED cathodes to the circuit? If so, where does the current go from there?

But back to my previous circuit; how likely was it for my components to get damaged? If I use a 9-to-5 converter, would that increase or decrease the likelihood of damage? Would I have been fine? The circuit I built was very similar to circuits that we built in class, with power, leading to logic gates, through a button and then to LEDs, which we had no problems with damaged components.

Thanks again!
"Where does it go from there?"
Post #22 shows the complete current loop. I'll post it again here.
You probably didn't damage anything. Did you read post #32?
 

Attachments

Thread Starter

derderppolo

Joined Nov 19, 2012
17
"Where does it go from there?"
Post #22 shows the complete current loop. I'll post it again here.
You probably didn't damage anything. Did you read post #32?
Ah, I see how the current sinks now. Thank you.

And yes, I read post #32, and it was the post that raised curiosity as to whether or not it was likely for me to damage my circuit. If I am not damaging my circuit, I think it'll be better if I stick with my previous circuit, as I can explain it thoroughly, and simply.
 

Ron H

Joined Apr 14, 2005
7,014
Ah, I see how the current sinks now. Thank you.

And yes, I read post #32, and it was the post that raised curiosity as to whether or not it was likely for me to damage my circuit. If I am not damaging my circuit, I think it'll be better if I stick with my previous circuit, as I can explain it thoroughly, and simply.
Post 32 was supposed to allay your fears. Elec_mech had raised the issue of damage. He doesn't understand TTL very well. I started designing digital logic circuits before the first TTL IC family (SUHL, Sylvania Universal High-level Logic) was introduced in 1963. I'm not tooting my horn, I'm just trying to establish my credibility.:D
 

Thread Starter

derderppolo

Joined Nov 19, 2012
17
Post 32 was supposed to allay your fears. Elec_mech had raised the issue of damage. He doesn't understand TTL very well. I started designing digital logic circuits before the first TTL IC family (SUHL, Sylvania Universal High-level Logic) was introduced in 1963. I'm not tooting my horn, I'm just trying to establish my credibility.:D
I'd say your credibility was never in doubt. :p

Well, my fears are definitely diminished, but I've noticed that the green LED (and maybe the red LED as well) is really dim. Going back to earlier posts, it's because the output pins aren't giving the LEDs enough power. It's not a deal-breaker, but it would be better if it was a little brighter.

Thanks again everybody!
 

Ron H

Joined Apr 14, 2005
7,014
I'd say your credibility was never in doubt. :p

Well, my fears are definitely diminished, but I've noticed that the green LED (and maybe the red LED as well) is really dim. Going back to earlier posts, it's because the output pins aren't giving the LEDs enough power. It's not a deal-breaker, but it would be better if it was a little brighter.

Thanks again everybody!
We can't tell you why they are dim unless you post your current accurate schematic.
 
Top