Electrical – BCD code Detector

digital-logiclogic-gates

So basically I'm trying to design the circuit for a BCD code detector which should have 4 inputs and gives an output of 1 if the equivalent decimal is 0<=input<=9.
Else, it should give zero.

Now as I understand it(although not sure) the physical circuit using LED and resistors alongside the NAND gates, should light up when the output is 1 and off when the equivalent digital output is 0.

However, as I run the simulation (and also the real circuit) the LED does not turn on and off as I explained above. Why?????
enter image description here

Edit: the DCBA are simply the four digits binary input. With b corresponding to the most significant bit and A as the LSB. Now the circuit has worked as the answer below described but only if the DIP switch is rotated 180 degrees. Why though??? shouldn't a switch act as a short or open circuit and thus no matter how it's rotated, it's either on or off.

Best Answer

Because you have the LED wired to +5V.

That means that when the output of the logic gate is high (+5V), there's no net voltage across the LED, and it remains dark.

When the gate is low (0V), then there's a difference of 5V across the LED and resistor, and the LED lights up.

If you want the LED to light up for valid BCD digits, you need to eliminate the last inverter stage and connect the cathode of the LED to the previous gate's output, which goes high for non-BCD values, and low for valid BCD values.