School Science Lessons
(UNPh39) 2024-07-24

Electronics, Components
Contents
39.5.0 Bistable circuits
39.7.0 Coding
39.6.0 Drivers
39.1.0 Electronic Components
39.4.0 Electronic logic circuits, logic gates
39.3.0 Logic circuits
39.2.0 Switches

39.1.0 Electronics Components
39.1.1 Resistor and light-emitting diode (LED)
See diagram 39.1.1: Resistor and light-emitting diode (LED).
* Use a LED, a battery and a resistor.
The passage of current causes the emission of light.
The intensity of light depends on the size of the current.
The direction in which current will flow is the same as that of the arrowhead in the symbol.
* Reverse the connections so that the diode is the other way round.
A LED will allow current to pass in only one direction.
* Connection directly across the battery destroys the LED, so insert a series resistor to limit the current, e.g. 10 milliamperes, mA.
39.1.1 Resistor and light-emitting diode (LED)
39.1.2 Brightness and current
39.1.3 LEDs in parallel
39.1.4 Current direction indicator
39.1.5 Light dependent resistor (LDR)
39.1.6 Simple burglar alarm using LDR

39.2.0 Switches
39.2.1 Manual control of a LED
39.2.2 Reed switch and magnet
39.2.3 Reed switch and coil, the reed relay
39.2.4 Reed relay used to control a motor
39.2.5 Reed relay with coil, contacts in parallel
39.2.6 Automatic washing line
39.2.7 Reversing an electric motor

39.3.0 Logic circuits
39.3.1 Simple AND circuit
39.3.2 Simple OR circuit
39.3.3 Relay as a NAND circuit
39.3.4 Simple burglar alarm
39.3.5 NAND circuit as an inverter
39.3.6 AND circuit using a NAND circuit and NAND circuit as inverter
39.3.7 Excess length detector using a NAND circuit an inverter
39.3.8 Two NAND circuits as a bistable ("Flip-flop")
39.3.9 Latched burglar alarm
39.3.10 Use a bistable to control an electric motor

39.4.0 Electronic logic circuits, logic gates
See 39.4.0: Modules.
Draw a circuit before connecting the parts.
If their circuit does not behave as expected, try to explain why this happens, before making any changes to the circuit.
CMOS integrated circuits operate over the wide voltage range of 3 V to 18 V and require little supply current, unless driving external devices, e.g. LEDs and 7-segment displays.
Use dry cells that can drive the LEDs and the 7-segment displays, because the current required will rarely exceed 0.2 A.
However, the working of CMOS integrated circuits can vary with the supply voltage chosen.
A supply voltage of 5 V or 6 V is recommended.
Integrated circuits can be damaged if supply polarity is reversed, so connect a diode, e.g. IN5401, between the power rails of each circuit, so the diode conducts if the supply connections are crossed.
The reverse voltage is about 1 V and current about 3 A.
When connecting prepared circuits, link the corresponding power rails of the circuits before connecting the circuits to the supply.
39.4.01 Truth tables for logic gates
39.4.1.0 LED indicators
39.4.2.0 NAND gate truth table
39.4.2.1 NAND gate as inverter (NOT circuit)
39.4.2.2 NAND gate as an inverter (NOT circuit) using separate inputs
39.4.2.3 Astable using two NAND gates connected as an AND gate
39.4.2.4 AND gate using two NAND gates
39.4.2.4.1 AND gate using two NAN gates connected as an AND gate
39.4.2.5 OR gate using three NAND gates
39.4.2.6 NOR gate using four NAND gates
39.4.3.0 Applications using NAND gates
39.4.3.1 Burglar alarm (NAND application)
39.4.3.2 Length detector (AND application)
39.4.3.3 Automatic night light (2 NAND gates as inverters)
39.4.3.4 Fire alarm (NAND gate as inverter, and thermistor)
39.4.3.5 Safety circuit for a safe (3-input AND gate)
39.4.3.6 Skittle alley winner indicator (3-input NAND gate)
39.4.3.7 Car doors warning light (2-input NAND gate)
39.4.3.8 Light at the top of the stairs (exclusive OR gate)

39.5.0 Bistable circuits
39.5.1.0 Bistable using two NAND gates
39.5.1.1 Two NAND gates as inverters
39.5.1.2 Two NAND gates with reversed conditions
39.5.1.3 Two NAND gates with positive feedback link, bistable
39.5.1.4 Bistable with complimentary outputs, Q and Q'
39.5.1.5 Bistable building block
39.5.1.6 Bistable and logic gate

39.5.2.0 Bistable applications using NAND gates
39.5.2.1 Latched burglar alarm using a bistable
39.5.2.2 Latched fire alarm using a bistable
39.5.2.3 Simple stop-go traffic lights
39.5.2.4 Traffic lights operated by an SPST switch
39.5.2.5 Quiz master

39.6.0 Drivers
Drivers are essential to drive heavy current devices such as motors, so an operational approach to drivers follows.
39.6.1 Loading an output
39.6.2 Use a NAND gate to switch an electric motor on or off
39.6.2.1 Inverting driver amplifier
39.6.2.2 Driver amplifier with relay omitted
39.6.3.0 Applications involving the driver amplifier and reed relay
39.6.3.1 Reversing an electric motor
39.6.3.2 Reversing an electric motor with a bistable circuit
39.6.3.3 Automatic light
39.6.3.4 Motor vehicle moving backwards and forwards between two light beams

39.7.0 Coding
Coding (Commercial)
39.7.1d Sending messages using a 4 bit binary code
39.7.01 Coding
39.7.2 Seven segment LED display
39.7.3 Seven segment display with a decoder
39.7.4 Two-line to four-line decoder from NAND gates

39.1.2 Brightness and current
See diagram 39.1.2: Brightness and current.
Connect the circuit shown, using a LED module, a resistor and a battery.
Use a low value resistor and note how brightly the LED glows.
Replace the resistor first by the one of medium value, then by one of large value, e.g. 27 k ohms, 2.7 k ohms and 270 ohms.
Note what happens to the brightness of the LED and how does the brightness of the LED depend on the current passing through it.

39.1.3 LEDs in parallel
See diagram 39.1.3: LEDs in parallel.
Use one red LED, one green LED and a battery.
Both LEDs glow, because Two LEDs of the same colour and resistance connected in parallel will glow with the same brightness.
The currents through each LED are equal.
A LED of different colour with the same value of series resistor may not glow with the same brightness.
Use a milliammeter to show that the currents through red and green LEDs with equal series resistors are almost the same.
Variations in apparent brightness are due to differences in the materials and to variations in the sensitivity of the eye to different colours.

39.1.4 Current direction indicator
See diagram 39.1.4: Current direction indicator.
If a battery is connected one way round to the indicator, one LED should glow.
If the battery connections are reversed, the other LED will glow.

39.1.5 Light-dependent resistor (LDR)
See diagram 39.1.5: Light-dependent resistor (LDR).
Use a light dependent resistor in series with a LED and a battery.
If the LED is covered or uncovered, the current will flow in either direction as with an ordinary resistor.
The resistance of a LDR is very large in the dark, e.g. a million ohms or more, but falls to a small value, e.g. two hundred ohms, in bright light.
Cadmium sulfide is commonly used for LDRs.
A LDR is not a photocell.

39.1.6 Simple burglar alarm using LDR
See diagram 39.1.6: Simple burglar alarm using LDR.
Use and LDR, a buzzer and a battery to construct a circuit that will sound an alarm when a light comes on.
The buzzer probably has a definite polarity.

39.2.0 Switches
The next 3 experiments show the progression from direct manual control to magnetic control, and then to electromagnetic control.

39.2.1 Manual control of a LED
See diagram 39.2.1: Manual control of a LED.
Connect a battery, and LED and a push-button switch together in a series circuit.
The LED lights only when the push-button switch is pressed.

39.2.2 Reed switch and magnet
See diagram 39.2.2: Reed switch and magnet.
Use a magnifying glass to see the two metal contacts inside the glass envelope of the reed switch.
These contacts are normally open.
Connect the switch in series with a buzzer and a battery.
Bring a small bar magnet close to the reed switch to see the contacts close.
A reed switch has two metal contacts, "reeds", inside a glass envelope filled with an inert gas to prevent corrosion.
The contacts consist of a ferrous metal so a magnet can magnetize them.
Bring the magnet close to the switch so that the metal strips become magnetized and attract each other.
When the contacts close, a current flows through the buzzer.
The magnet produces a force that closes the switch contacts.
The reed switch contacts either are open or closed, so the reed switch is a single-pole, single-throw, SPST switch.

39.2.3 Reed switch and coil, reed relay
See diagram 39.2.3: Reed switch and coil - reed relay.
Using a reed relay with two separate battery supplies.
Do not use either of the diode connections to the coil of the relay.
In this experiment, switching is controlled by the magnetic effect of a current-carrying coil that has a magnetic effect, an electromagnetic relay.
When the switch is closed, the relay uses a changeover reed switch, a single-pole double-throw, SPDT, switch.
The reed C and contact A consist of a magnetic metal.
Contact B is a nonmagnetic metal.
Contact C is normally in contact with B.
However, when a magnetic field magnetizes A and C, they are attracted together so that contact with B is broken and C contacts A instead.
Remove the field and C springs back to its original position.
Change the switch connections at the relay so that the LED is on until the push-button switch is pressed.
If current flows through the coil, the reed switch changes over and the LED lights.
Note that the flow of an electric current now determines the switching, and although the two circuits are separate, what happens in one circuit is controlled by what happens in the other circuit.
The current through the coil, needed to operate the switch, is usually smaller than the current allowed through the switch contacts.
So if the LED and resistor were replaced by an electric motor that needed a large current to make it rotate, the electric motor could be operated by a much smaller current through the coil circuit.

39.2.4 Reed relay used to control a motor
See diagram 39.2.4: Reed relay used to control a motor.
Use a reed switch, a motor and two batteries.
When the LDR is covered, its resistance is great, and not enough current flows through the relay coil to operate the reed switch and switch on the motor.
When the LDR is well illuminated with a torch, its resistance decreases and the relay operates.
Insert ammeters in series with the coil and the motor to show that the current through the motor, e.g. 0.2 A, is more than the current through the coil.
So the flow of a small current is used to control the flow of a much larger current.
If the reed relay is not used, the change in the resistance of the LDR is not enough to allow the motor to operate.

39.2.5 Reed relay with coil, contacts in parallel
See diagram 39.2.5: Reed relay with coil, contacts in parallel.
In 39.2.4 and 39.2.6, a small current in one circuit controlled a much larger current in another circuit that was completely separate with its own power supply.
In this experiment, a current through one branch of a parallel circuit, the coil branch, controls a much larger current through another branch, the motor branch, using only one battery.
Note what happens to the motor when the switch is closed.
In this circuit, the relay coil and the relay contacts are connected in parallel.
Trace the closed current paths from the battery, through each branch of the circuit and back to the battery again.
This circuit uses the idea of positive and negative supply rails.

39.2.6 Automatic washing line
See diagram 39.2.6: Automatic washing line.
Use two batteries, reed relay, electric motor and the rain sensor to make a circuit that switches on an electric motor when rain fails.
Make a rain sensor from a small piece of strip board on which are six copper strips are connected.
If a conducting solution bridges any of the strips, the two leads are short circuited allowing current to flow through the relay coil.
If the experiment does not work with tap water add salt to the water.
Rain water may conduct electricity, but not sufficiently to operate the reed relay in the circuit.
The experiment will work with rain if the copper strips are covered by dry absorbent paper soaked in a salt solution.

39.2.7 Reversing an electric motor
See diagram 39.2.7: Reversing an electric motor.
Use a push-button switch, the reed relay and three batteries to make a circuit so that the direction of rotation of the motor is reversed when the switch is pressed.
With a 3 volt motor only one battery may be used.

39.3.0 Logic circuits
39.3.1 Simple AND circuit
See diagram 39.3.1: Simple AND circuit.
Connect two push-button switch modules in series with a LED and a battery.
Table 39.3.1
S1 S2 LED
Not pressed Not pressed OFF
Pressed Not pressed OFF
Not pressed Pressed OFF
Pressed Pressed ON
The table tells us that the LED is on when S1 AND S2 are pressed, so the circuit is called an AND circuit.
An AND circuit may be used in a motor car if the ignition light shows that the car can be started only when the driver has engaged his safety belt AND closed the door.

39.3.2 Simple OR circuit
See diagram 39.3.2: Simple OR circuit.
Table 39.3.2
S1 S2 LED
Not pressed Not pressed OFF
Pressed Not pressed ON
Not pressed Pressed ON
Pressed Pressed ON
The truth table for an OR circuit tells us that the LED is on when either S1 OR S2, or both, are pressed.
In a burglar alarm pressure pads are open SPST switches.
A pad is placed under a carpet so that the pressure of the burglar's foot closes the switch.
The circuit could be used with two such switches.
An alarm sounds, if the buzzer replaces the LED, if entry were through door 1 OR door 2.

39.3.3 Relay as a NAND circuit
See diagram 39.3.3: Relay as a NAND circuit.
A logic circuit is a switching circuit in which the state of the output at any instant depends on the present state of all the inputs.
The output is HIGH only for some input combinations.
NAND is a contraction of "negative AND".
NAND circuits are commonly used in electronics.
Construct the NAND relay circuit with its coil and contacts in parallel with the supply, and its inputs and outputs are either HIGH or LOW.
Table 39.3.3a
INPUT B INPUT A OUTPUT
LOW LOW HIGH
LOW HIGH HIGH
HIGH LOW HIGH
HIGH HIGH LOW
Using a reed relay, a LED and a battery, connect leads to the diode input terminals of the relay, A and B.
Connect the other end of one of these leads to the positive supply rail so that the input is HIGH.
Connect the lead to the negative supply rail so that the input is LOW.
The output is HIGH if the LED is on and LOW if the LED is off.
The output is HIGH when one or both of the inputs are LOW.
In an AND circuit, its output is HIGH when input A and input B are HIGH, see the AND circuit truth table below.
In a NAND circuit, the output is LOW when input A and input B are HIGH, see the NAND relay circuit truth table below.
The contacts at the output form an SPDT switch.
Connect the pole of this switch to the negative supply rail, i.e. the output is LOW.
This is the position at the output when no current flows through the relay coil.
When either or both inputs are taken LOW, current flows through the coil and the output contact changes over.
The output goes HIGH and the LED module is connected directly to the positive supply rail.
No current can flow through an input if it is HIGH nor if the input is unconnected.
So an unconnected input behaves as though it were HIGH.
Include diodes at the inputs, because without diodes, if one input taken HIGH and the other taken LOW, a short circuit across the battery may occur.
AND circuits.
Table 39.3.3b
INPUT B INPUT A OUTPUT
LOW LOW LOW
LOW HIGH LOW
HIGH LOW LOW
HIGH HIGH HIGH
NAND relay circuit LOW
Table 39.3.3c
INPUT B INPUT A OUTPUT
LOW HIGH LOW HIGH
LOW HIGH HIGH
HIGH LOW HIGH
HIGH HIGH LOW


39.3.4 Simple burglar alarm
See diagram 39.3.4: Simple burglar alarm - NAND circuit.
Note what happens when switch A or switch B is pressed, or both are pressed together.
Modify this circuit so that the alarm sounds either when a switch was closed or when a light shines on a LDR.
This circuit is more realistic using pressure pads instead of the switch modules, as in 39.3.2.
A light beam can trigger the alarm by replacing one switch module by a LDR module.
Cover the LDR or darken the room so that the LED will have a very HIGH resistance and little current flows through the relay coil.
When light fails on the LDR its resistance rapidly decreases and current can flow through the coil, so the LDR operates the relay.
The input is now LOW.

39.3.5 NAND circuit as an inverter
See diagram 39.3.5: NAND circuit as an inverter.
Connect a LED to the output and a flying lead to one input of the NAND circuit.
Use the flying lead to take the input HIGH and LOW.
Use one input of a NAND circuit or join the two inputs of a NAND circuit as a single input, so the NAND circuit behaves as an inverter.
Table 39.3.5
INPUT OUTPUT
HIGH LOW
LOW HIGH


39.3.6 AND circuit using a NAND circuit and NAND circuit as inverter
See diagram 39.3.6: AND circuit using a NAND circuit and NAND circuit as inverter.
Using two NAND circuits (one as an inverter), a LED and a battery.
The inverter inverts the output of the NAND circuit.
Compare the truth table below with 39.3.3.
Connect a flying lead to each input terminal of the first NAND circuit.
Remove the flying lead from input B and connect a push-button switch between input B and the negative supply rail.
Connect the flying lead from input A to the positive supply rail, i.e. HIGH, then operate the switch several times.
Connect the flying lead from input A to the negative supply rail, i.e. LOW, and operate the switch.
Connect the lead from input A to the positive supply rail, HIGH, so that operating the switch connected to input B causes the LED to go on or off.
The output follows the changes at input B.
When input A is LOW, the LED is off and operating the switch does not affect it.
The action of the circuit is like a gate and it is called a "gate".
With input A HIGH, the gate is opened and the signals pass through it.
With input A LOW, the gate is closed and the output is not affected by changes at input B.
Table 39.3.6
INPUT B INPUT A OUTPUT
LOW LOW LOW
LOW HIGH LOW
HIGH LOW LOW
HIGH HIGH HIGH


39.3.7 Excess length detector using a NAND circuit as an inverter
See diagram 39.3.7: Excess length detector using a NAND circuit as an inverter.
Use two NAND circuits (one connected as an inverter), two LDR modules and a buzzer.
Illuminate each LDR with a light beam.
If light shines on an LDR, its resistance is LOW.
The inputs of the first NAND circuit are therefore LOW, so its output must be HIGH.
The buzzer sounds only when both the LDRs are shaded.
The second NAND circuit is an inverter, so its output is LOW and the buzzer does not sound.
If one LDR is covered, but not the other, one input is still LOW, a current still flows in the coil, the output of the first NAND circuit is still HIGH, the output of the inverter is LOW, and nothing happens.
However, if both LDRs are covered, the output from the first NAND is LOW, so the output from the second is HIGH and the buzzer sounds.
If objects of greater length than the distance between the LDRs pass in front of them, the buzzer sounds.
The two relay modules, a NAND circuit followed by an inverter, are together acting as an AND circuit.
So, the output is HIGH, the buzzer sounds, only when input 1 AND input 2 are HIGH.

39.3.8 Two NAND circuits as a bistable ("Flip-flop")
See diagram 39.3.8: Two NAND circuits as a bistable ("Flip-flop").
(This circuit may be called a Bistable multibrator.)
To show the circuit, press the RESET switch.
The green LED is on and the red LED is off.
Press the SET switch.
The red LED is on and the green LED is off.
Press the SET switch repeatedly.
The red LED is still on and the green LED is still off.
Press the RESET switch again.
The green LED is on and the red LED is off.
Press the RESET switch repeatedly.
The green LED is still on and the red LED is still off.
When the RESET switch is pressed, the output of NAND circuit 2 is HIGH and the output of NAND circuit 1 is LOW.
When the SET switch is pressed, the output of circuit 1 is HIGH and the output of circuit 2 is LOW.
The bistable circuit has two stable states.
The first stable state occurs when the output of NAND circuit 2 is HIGH and the output of NAND circuit 1 is LOW, the RESET state.
The second stable state occurs when the output of NAND circuit 1 is HIGH and the output of NAND circuit 2 is LOW, the SET state.
In a bistable circuit, after the SET switch has been pressed, repeated depressions of this switch have no effect.
Also, after the RESET switch has been pressed, repeated pressing of this switch have no effect.
The SET and RESET inputs are normally unconnected, i.e. they "float HIGH".
To change from one stable state to the other the appropriate input must be taken LOW.
Follow the path of the current flow through the coils and the connections between the two NAND circuits.
Note how the two NAND circuits are joined and share the same power rails.
The output C of the first circuit is connected to the input D of the second circuit.
Similarly, the output F of the second circuit is connected to the input A of the first circuit.
A red LED is connected between C and M.
If C is HIGH, the red LED will light.
If C is LOW, the red LED will not light.
A green LED is connected between F and N.
If F is HIGH, the green LED will light.
If F is LOW, the green LED will not light.
A bistable circuit has two stable states.
For the first stable state, if C is HIGH, the red LED will light, D will be HIGH, F will be LOW so the green LED will not light.
As F is low, A is LOW, so C remains HIGH.
For the second stable state, if C is LOW, the red LED will not light, D will be LOW, F will then be HIGH so the green LED will light.
As F is high, A is HIGH, so C remains LOW.
This is the second stable state, and so it is called a "bistable" - it has two stable states.
Note that the output of the 1st module is connected to the input of the 2nd module and the output of the 2nd module is connected to the input of the 1st module.
1. To set the bistable in one stable state or the other, push-button switches are connected between input B and the negative rail at P and between input E and the negative rail at Q.
2. To set the first stable state, press the push-button switch at P, current flows through the relay coil, C becomes HIGH and the red LED will light.
3. To set the second stable state, press the second push button at Q, current flows through the relay coil F becomes HIGH, the green LED will light.
The circuit could be used to control of simple traffic lights so that the red light and the green light cannot be turned on together.

39.3.9Latched burglar alarm
Replace the red LED in the circuit of 39.3.8 with a buzzer.
Remove the green LED.
If the buzzer sounds, press the RESET switch to silence it.
The SET switch is now the trip switch of the alarm.
If it is pressed, the alarm sounds and it cannot be turned off by releasing the trip switch or pressing it again.
The output is said to be "locked" or "latched", because the bistable is locked in its second stable state.
The alarm can only be turned off by pressing the RESET switch.
This latched alarm is an improvement on the alarm constructed in 39.3.4.

39.3.10 Use a bistable to control an electric motor
Remove the buzzer from the circuit of 39.3.9, or both LEDs from the circuit of 39.3.8, and connect the motor between the outputs of the two NAND
circuits C and F in diagram 39.3.8.
Pressing the SET and RESET switches alternately changes the direction of rotation of the electric motor.
The bistable circuit here is used simply to reverse the polarity of the motor supply.

39.4.01 Truth tables for logic gates
See diagram 39.4.01: Logic symbols.
AND gate: Circuit has two or more inputs, and one output that is high if all inputs are high.
NAND gate: Circuit has two or more inputs, and one output that is high if one or more of the inputs are low, and low if all the inputs are high.
OR gate: Circuit has two or more inputs, and one output that is high if one or more of the inputs are high.
NOR gate: Circuit has two or more inputs, and one output that is high only if all inputs are low.
INVERTER (NOT gate): Circuit has one input, and one output that is high if the input is low and low if the input is high.
Table 39.4.01
AND . . NAND . .
B A OUTPUT B A OUTPUT
LOW LOW LOW LOW LOW HIGH
LOW HIGH LOW LOW HIGH HIGH
HIGH LOW LOW HIGH LOW HIGH
HIGH HIGH HIGH HIGH HIGH LOW
. . . . . .
OR . . NOR . .
LOW LOW LOW LOW LOW HIGH
LOW HIGH HIGH LOW HIGH LOW
HIGH LOW HIGH HIGH LOW LOW
HIGH HIGH HIGH HIGH HIGH LOW
INVERTER (NOT gate) .
INPUT OUTPUT
HIGH LOW
LOW HIGH


39.4.1.0 LED indicators
See diagram 39.4.1.0.
Use a LED indicator module or different LEDs and power supply, connected correctly.
Plug a lead into the top input socket of the indicator module or the first LED.
Connect the other end of this flying lead to the positive power supply rail or to the negative power supply rail.
If the flying lead connects to the positive rail, the input is said to be HIGH.
If the flying lead connects to the negative rail, the input is said to be LOW.

39.4.1.1 Indicator in a circuit diagram
See diagram 39.4.1.1: Circuit diagram.
Note how an indicator is represented in the circuit diagram.
The power supply need not be drawn.
Only the parts of a module in use need be shown, so diagram 39.4.1.1 is the equivalent of diagram 39.4.1.0.
The + and - signs near the power rails show that a power supply is connected between them.

39.4.1.2 Control function in an AND gate
See diagram 39.4.1.2: Control function in an AND gate.
The term "gate" refers to the switching circuit in which the state of the output at any instant depends on the state of the inputs at that instant, i.e. a logic circuit.
In an AND gate one of its inputs has a control function when a succession of high and low pulses arriving at the other input.
If the control input is held low, the output will be held low if the state of the other input is high or low, so the gate is closed.
If the control input is held high, the output state follows the state of the other input, so the gate is open.
A NAND gate is open when its control input is high, as with an AND gate, but the pulses arriving at the other input are inverted when they arrive at the output.
The OR gate and NOR gates are both open when their control inputs are low.
However, the output pulses are inverted with the NOR gate.

39.4.2.0 NAND gate truth table
See diagram 39.4.2.0.
Use a NAND gate, LED indicator and power supply.
Each input A and B can be connected to the positive power supply rail (high) or to the negative power supply rail (low) using a flying lead.
Note how the different LEDs light when the input is connected high or low.
The output is high if the LED is lit and low if the LED is unlit.
Connect the inputs high and low, complete the truth table for a NAND gate.
Note whether an unconnected input behaves as if it is high or low.

39.4.2.1 NAND gate as inverter (NOT circuit)
See diagram 39.4.2.1: NAND gate as inverter (NOT circuit).
Note the inversion circle at the output of a gate with an inverting function.
The symbol for AND with an inversion circle becomes symbol for NAND ("not and").
The symbol for OR with inversion circle becomes the symbol for NOR ("not or").
The NAND gates can be used to make NOT circuits, AND, OR and NOR gates.
The NAND gate used in these experiments has inputs that are high when unconnected.
Connect the two inputs of a NAND gate together as shown in the diagram.
The two joined inputs can now be thought of as a single input.
This single input can be taken high or low using the flying lead.
By taking the input high and then low, complete the truth table for the inverter.
The inverter is also called a NOT circuit.

39.4.2.2 NAND gate as an inverter (NOT circuit) using separate inputs
See diagram 39.4.2.2.2.
Instead of using a two input NAND gate as an inverter, as in 39.4.2.1 by joining the two inputs of the NAND gate, use one input of a NAND gate by joining a flying lead to it and connect the other to the positive rail, so it is permanently high, or leave it unconnected, i.e. "floating", as in diagram 39.4.2.2.1.
Note how the circuit behaves if the input is taken high and low.
Note what happens if one input is tied permanently low.
However, for these experiments, show an inverter as in diagram 39.4.2.2.2.

39.4.2.3 An astable using two NAND gates connected as an AND gate
See diagram 39.4.2.3.
Use two NAND gates connected as an AND gate.
When the control input is high, pulses will pass through the AND gate and the two LEDs will flash on and off together.
If the control input is taken low, the LED at the output will be permanently low.
If a single NAND gate is used and the control input is high, the output LED will flash on and off.
However, it will be on when the LED at the input is off, and vice versa.
When the control input is low, the output LED will be permanently on.

39.4.2.4 AND gate using two NAND gates
See diagram 39.4.2.4: AND gate using two NAND gates showing power supply connections.
Connect the circuit using two NAND gates.
The second NAND gate is connected as an inverter, i.e. a NOT circuit.
Check that the circuit behaves as an AND gate by taking the inputs high and low.
Complete the truth table.

39.4.2.4.1 AND gate using two NAND gates connected as an AND gate
See diagram 39.4.2.4.1: AND gate using two NAND gates connected as an AND gate.
By convention, draw the symbol without power supply connections as in 39.4.2.2.2.
The diagram shows how to include supply lines in circuit diagrams to show power supply connections to electronic devices inside the NAND gate.

39.4.2.5 OR gate using three NAND gates
See diagram 39.4.2.5: OR gate.
Note the truth table for an OR gate.
Compare this with the truth table for a NAND gate.
If every high input to the NAND gate becomes a low and every low input becomes a high, the gate is an OR gate.
Design an OR gate using three NAND gates.
Build the circuit and check that it produces the correct truth table.

39.4.2.6 NOR gate using four NAND gates
See diagram 39.4.2.6: NOR gate.
Note the truth table for a NOR gate.
Use four NAND gates to convert the OR gate to a NOR gate.
Check that the circuit produces the correct truth tables for a NOR gate.

39.4.3.0 Applications using NAND gates
Electronic circuits can do useful tasks and control devices, e.g. LEDs, buzzers and motors.
In these experiments integrated circuit NAND gates are used instead of NAND circuit relays.
However, the circuits are identical whether relay or integrated circuit (IC) NAND gates are used.
These applications use illuminated LDRs to keep inputs low.
So an LDR can act as a switch that is open in the dark and closed when illuminated.
Connect input devices such as LDRs between gate inputs and the negative supply rail.
An unconnected input floats high, so an LDR connected to the positive supply rail will not change logic level at the input when illumination changes.
When connected to the negative supply rail, an LDR will cause a low level input when brightly illuminated, low resistance, and a high level input when dark, high resistance.
A suitable LDR is the ORP 12.
Buzzers are used, because they are low current devices that can operate over a voltage range of 3 V to 15 V and emit a constant frequency audible tone.

39.4.3.1 Burglar alarm (NAND application)
See diagram 39.4.3.1: Burglar alarm (NAND application).
Use a single NAND gate, an LDR, a push-button switch and a buzzer to make a simple burglar alarm.
The alarm should sound when the LDR is illuminated by the burglar's torch or the switch is closed by the burglar's foot.

39.4.3.2 Length detector (AND application)
See diagram 39.4.3.2: Length detector (AND application).
Use two NAND gates (one gate connected as an inverter) with two LDRs and a buzzer to construct a system that will sound an alarm when an object is longer than a specified maximum length.
Such a circuit might be used to reject overlong objects passing along a conveyor belt in a factory.
The LDRs are positioned a distance x apart (where x is the specified maximum length of the object) and illuminated by "pencil" torches.
The alarm sounds when both beams are interrupted.

39.4.3.3 Automatic night light (2 NAND gates as inverters)
See diagram 39.4.3.3: Automatic night light (2 NAND gates as inverters).
Use two NAND gates (both connected as inverters), an LDR and a LED indicator to make a circuit in which a light (the LED) will come on in the dark.
This circuit could be used to turn on a light when it gets dark.
This application uses two NAND gate inverters to drive a LED indicator.
The circuit on the left is not very sensitive to changes of light intensity, because the LDR and the internal circuitry of the NAND gate module form a potential divider between the supply rails.
As R has a high resistance, it needs a large change in the resistance of the LDR to change the voltage level at the NAND gate input appreciably.
The second circuit allows the sensitivity to be changed.
The variable resistor should be set so that the LED is on the verge of switching on.
Then any darkening of the LDR will cause the LED to light.
The value of the variable resistance to use depends on ambient light conditions, but 10 k ohm should suit most circumstances.

39.4.3.4 Fire alarm (NAND gate as inverter, and thermistor)
Potentiometers, (Commercial).
See diagram 39.4.4: Fire alarm (NAND gate as inverter, and thermistor)
1. Use a NAND gate connected as an inverter, a thermistor, a variable resistor and a buzzer to make a simple fire alarm.
The alarm should sound when the thermistor is heated.
To adjust the circuit so that the alarm sounded when the temperature reached a higher value, include a potential divider and a thermistor.
2. An inexpensive TH3 thermistor can be used for this fourth application.
Its resistance at room temperature is about 400 ohm, and decreases to about 20 ohm at 100oC.
At room temperature, the 5 k ohm variable resistor, i.e. a 5 k ohm potentiometer connected as a variable resistor, should be set so that the buzzer is just turned off.
Warming the thermistor with the hand will then cause the buzzer to sound.
To increase the temperature at which the alarm responds, decrease the value of the variable resistance.
Note that a 2.5 k ohm variable resistor provides greater sensitivity.

39.4.3.5 Safety circuit for a safe (3-input AND gate)
See diagram 39.4.5: Safety circuit for a safe (3-input AND gate).
A safety circuit for a large safe sounds an alarm only if the door is closed, but not locked.
Closing the door opens a switch, while locking the door closes another switch.
What sort of logic gate is required to do this?
Set up the circuit and test it.
Adapt the circuit for a safe that has two locks.
Note that 9 NAND gate 4 is omitted, the circuit is a 3 input NAND gate.

39.4.3.6 Skittle alley winner indicator (3-input NAND gate)
See diagram 39.4.3.6: Skittle alley winner indicator (3-input NAND gate).
In a fairground skittle alley, customers try to overturn three skittles.
Each skittle stands on a small switch that it keeps closed until it is overturned.
Design a circuit that lights a lamp only when a customer is successful.
The problem is similar to 39.4.3 (e), but it uses a 3 input AND gate.
If gate 4 is omitted, the circuit is a 3 input NAND gate.

39.4.3.7 Car doors warning light (2-input NAND gate)
See diagram 39.4.7: Car doors warning light, (2-input NAND gate).
Design a circuit that will cause a warning lamp on the dashboard of a two door car to light if either of the doors is not closed.
Closing a door closes a switch.

39.4.3.8 Light at the top of the stairs (exclusive OR gate)
See diagram 39.4.3.8: Light at the top of the stairs (exclusive OR gate).
In the truth table, "0" stands for LOW, and "1" stands for HIGH.
Complete the truth table to show the voltage level at each of the lettered points for each of the level combinations at A and B.
Set up the circuit and check predictions for the output F.
Use a flying lead from another LED indicator to check predictions for the level at each point Q, D and E, by touching the free end of the flying lead on to each of those points in turn.
The circuit is an exclusive OR gate.
Note that F is high when A or B is high, excluding the case when both are high.
It is a "light at the top of the stairs" circuit.

39.5.1.0 Bistable using two NAND gates
Use two NAND gates.
Press RESET switch and note which LED is on and which LED is off.
Press and release the switch marked SET and note what happens.
Press and release the SET switch several times and note what happens.
Press and release RESET and note what happens.
In the circuit diagram, the LED indicator connected to the output of NAND gate 1 is not drawn beneath the LED indicator of gate 2.
However, that is where it is placed on the indicator module.
Circuit diagrams are easier to understand if the parts are drawn in convenient places rather than as they are placed on the modules.
The positive power rail is drawn in the above diagram although no leads are shown connected to it.
Such a power rail may be omitted from circuit diagrams, but are included in these experiments.
In this experiment when the RESET switch is pressed, the output of NAND gate 2 goes high and the output of NAND gate 1 is low.
When the SET switch is pressed, the output of NAND gate 1 goes high and the output of NAND gate 2 goes low.
The bistable circuit has two stable states.
The first stable state exists when the output of 2 is high and the output of 1 is low (the RESET state).
The second stable state exists when the output of 1 is high and the output of 2 is low (the SET state).
After the SET switch has been pressed, more depressions of this switch have no effect.
The same is true of the RESET switch.
The SET and RESET inputs are normally high.
To change from one stable state to the other, the appropriate input must be taken briefly low.

39.5.1.1 Two NAND gates as inverters
See diagram 39.5.1.1: Two NAND gates connected within the output of one gate joined to the input of the other gate.
Connect two NAND gates so that the output of one is joined to the input of the other.
If the second input of each gate is not used, both gates act as inverters.
If the input of the first gate is made high, its output will be low.
The input of the second gate is therefore low and its output high.
Connect the output of the second gate to the input of the first gate, see broken line.
The original high input to the first gate provided by the flying lead is removed and the system is stable.
The high output of the second gate maintains the high input to the first gate.

39.5.1.2 Two NAND gates with reversed conditions
See diagram 39.5.1.2: Two NAND gates connected as above (in 39.5.1.1), but with the flying lead tied low.
A different situation arises if the flying lead to the first gate is originally tied low.
Since the input of the first gate is now low, the output of the second gate is also low.
Connect the output of the second gate to the input of the first gate.
Remove the original flying lead.
The system is now stable.
However, the output conditions at the two gates are reversed compared with 39.5.1.2.
The system consisting of two inverters can be connected to form two stable states.

39.5.1.3 Two NAND gates with positive feedback link, bistable
See diagram 39.5.1.3: Second input of each NAND gate used to switch between two stable states.
The second, and so far unused, input of each NAND gate can be used to switch between the two states.
The diagram shows the initial stable state.
The inputs of the first NAND gate are both high, and its output is low.
However, if the SET switch is pressed, one input of the first NAND gate is taken low, its output goes high.
The output of the second gate therefore goes low and this low state is fed back to the other input of the first gate.
If the SET switch is now released, the system is in the second completely stable state.
Note that pressing the SET switch a second time has no effect.
The system can only be switched back to its original state by pressing the RESET switch.
The line shown dotted in the earlier diagrams provides a positive feedback link.
In other words, the output of the system is fed back to provide an input of the same polarity.

39.5.1.4 Bistable with complimentary outputs, Q and Q'
See diagram 39.5.1.4: Redrawing of 39.5.1.3 with top gate SET labelled Q and lower RESET Q'.
In electronics literature, the above bistable would usually be drawn as in the diagram.
The connections are identical, but the gates are shown one beneath the other.
The output of the top gate, with the SET input, is usually labelled Q.
The output of the other gate, with the RESET input, is labelled Q'.
The two inputs and called complementary outputs, because each is the inverse of the other.

39.5.1.5 Bistable building block
See diagram 39.5.1.5: Symbol for 39.5.1.4 with circles on S and R input lines active low.
(normally high, take low for effect)
Diagram 39.5.1.5 is too complicated to use in circuit diagrams so this symbol is in common use.
The circles on the S and R input lines show that they are active low.
The S and R inputs are normally high and must be taken momentarily low to have an effect.
This bistable building block, called an RS bistable or as an RS flip-flop has the following properties:
1. There are two stable states: SET state (0 high, b low) and RESET state (0 low, U high).
2. Normally the system will be in one of its stable states.
In both states the S and R inputs will be high.
3. To change from the SET state to the RESET state the R input must be taken briefly low.
If R is taken low again, nothing happens.
4. To change from the RESET state to the SET state the S input must be taken briefly low.
If S is taken low again, nothing happens.
This behaviour can be summarized in a truth table:
Table 39.5.1.5
S R Q Q'
HIGH HIGH same same
LOW HIGH HIGH LOW
HIGH LOW LOW HIGH
LOW LOW avoid avoid

Note that the state with both S and R low is avoided or disallowed, since both Q and Q' are then forced to go high simultaneously and the system will be in neither of its stable states.

39.5.1.6 Bistable and logic gate
See diagram 39.5.1.6: Bistable and logic gate.
Difference between a bistable and a logic gate.
A logic gate requires retention of its input signals to remain in a given state.
The bistable remains in a stable state when the inputs are removed.
The particular state will depend upon which input was last taken low.

39.5.2.1 Latched burglar alarm using a bistable
See diagram 39.5.2: Bistable application using NAND gates-latched burglar alarm.
1. Use two NAND gates, two push-button switches and a buzzer to make a latched burglar alarm.
One switch should correspond to the "trip" switch.
If this is closed (by the burglar's foot, perhaps) the alarm should sound and stay on even when the switch is released or pressed again.
The second switch should correspond to the "reset" switch, and would be hidden away in a place known only to the householder.
Only when this switch is pressed should the alarm be silenced.
Convert this circuit to an alarm that will come on and stay on when a light, e.g. the burglar's torch, shines on an LDR.
Replace the trip switch by an LDR to make a light-activated latched alarm.
A variable resistor connected between the LDR and the positive supply rail to form a potential divider, will allow the sensitivity to be adjusted.
With CMOS modules, the output of NAND gate 1 may be unable to drive both the buzzer and the input to NAND gate 2.
Use a LED indicator rather than a buzzer.
2. Try to "buffer" the buzzer by connecting it to the output of another NAND gate whose inputs go to the output of NAND 2 in the circuit above.
When the "trip" switch is pressed, the alarm sounds and cannot be turned off by releasing the switch or by depressing it again.
The output is "latched".
The bistable is now locked in its second stable state (the state with the output of the NAND gate connected to the buzzer high, and the output of the other NAND gate low.
The alarm can only be turned off by pressing the "reset" switch.
In a practical system the trip switch might be contained in a pressure pad of the type designed especially for home security systems.
Such a pad is placed under a carpet near a door so that the switch is closed by the pressure of the intruder's foot.
Pressure pads of this kind are available.

39.5.2.2 Latched fire alarm using a bistable
See diagram 39.5.2.2: Latched fire alarm using a bistable.
Build a fire alarm that, once triggered, will continue to sound until it is reset.
See: 39.4.3.4 for information about a thermistor.
See: 39.5.2.1 for information about driving the buzzer.

39.5.2.3 Simple stop-go traffic lights
See diagram 39.5.2.3: Simple stop-go traffic lights.
Traffic in a one way street has to cross a bridge that can only have one car on it at a time.
The bridge is to be controlled by a set of stop-go lights, activated by switches in the road.
The lights go red when a car enters the bridge and then green as the car leaves it.
Design a circuit to do this job.

39.5.2.4 Traffic lights operated by an SPST switch
See diagram 39.5.2.4: Traffic lights operated by an SPST switch.
Stop-go traffic lights is to be operated by an SPST switch, so that either the red light is on or the green light is on, but not both together.
When SET is high, RESET is low and the green LED is on.
Since both inputs to NAND gate 1 are high, the red LED is off.
When SET is low, the red LED is on, and since both inputs to gate 2 are now high, the green LED goes off.

39.5.2.5 Quiz master
See diagram 39.5.2.5: Quiz master.
A quiz master circuit is used to identify the first contestant to push the answer button in a quiz game.
Each contestant has a push-button and a LED indicator light.
The light of the first person to answer should come on and stay on.
Simultaneously all other lights should be prevented from coming on.
Use four NAND gates two connected as a bistable, a push-button switch and a LED indicator.
Complete the wiring of the four gates for one contestant, then wire for another contestant separately.
Finally connect the two sets.
If the B inputs of the two quiz stations are taken low, the bistable circuit formed by the two right hand gates will be reset.
So the 5 outputs at the stations are high and the LEDs are off.
At the station of one contestant, the A input will initially be high, because it is connected to the output of the other station that has just been reset.
The A input effectively "opens" the NAND gate to which it is connected, so if this contestant is the first to press the switch, the bistable is set by a low pulse and the LED indicator comes on.
At the same time 0 goes low, and since this output is connected to the A input of the other station, the NAND gate controlled by this A input is closed.
This means that a low going pulse from the other contestant's push-button can pass to the bistable.
The bistable therefore remains in the reset state with the indicator light off.
Build a simpler quiz master station using fewer NAND gates, but it may not have the required properties of simultaneously latching the victor's indicator LED and permanently disabling the switches of all other contestants.

39.6.1 Loading an output
See diagram 39.6.1: Loading an output.
1. Set up the first circuit.
Press the push-button and note what happens.
When the switch is closed, note whether the output of the NAND gate high or low.
2. Replace the LED with an electric motor module as shown in the second circuit.
Press the push-button and note what happens.
3. Connect a LED in parallel with the motor as shown in the third circuit.
Press the push-button and note what happens.
Note whether the output of the NAND gate is still high as in or is it now low.
A logic gate operates satisfactorily only when small currents of a few milliamperes, mA, are used, because a larger current for the motor may change the logic level of the output.
The next experiment shows that this difficulty is overcome using a driver.
Use a LED in series with a 33 M resistor.

39.6.2 Use a NAND gate to switch an electric motor on or off
See diagram 39.6.2: Use a NAND gate to switch an electric motor on or off.
Use the Driver Amplifier module and the reed relay.
Note what happens when the switch is pressed.
When the switch is pressed, note whether the output of the NAND gate is high or low.
The driver amplifier is a special kind of inverter.
When the switch is pressed, note whether its output is high or low.
The relay is connected between the positive supply line and the output of the driver.
The motor operates when a current flows through the relay coil.
When this happens note whether the output of the driver is high or low.
Replace the switch by an LDR.
Note what happens to the motor when the LDR is covered or uncovered.

39.6.2.1 Inverting driver amplifier
See diagram 39.6.2.1: Simplest driver amplifier with a transistor and a resistor.
The function of a driver is to provide an interface between a device such as an integrated circuit that can control only a small current, and a device such as a relay or an electric motor, which usually requires a large current for its operation.
The simplest and cheapest inverting driver amplifier consists of a single transistor and one resistor.
A relay and its protective diode, essential when switching inductive loads, would then be connected between the positive supply line and the transistor collector in the way shown.
When the transistor input goes high, the collector current flows through the relay coil into the transistor.
Use two transistors connected as a Darlington pair.
The current gain of such a system is far higher than that of a single transistor, and the base current needed to switch the collector current on is then easily supplied by the high output of any integrated circuit.
Note that the circuit diagram shows the motor being driven by a separate power supply.
If separate supplies are not available, the motor may be driven by the supply used for the modules, if this supply can deliver the necessary current.

39.6.2.2 Driver amplifier with relay omitted
The driver amplifier operates a relay that controls the motor.
The same job, of course, could be done in other ways.
See diagram 39.6.2.2: (a) Relay omitted, motor and logic unit same power supply.
In the diagram, the relay is omitted entirely when the motor current does not exceed the maximum current allowed by the driver.
However, if the motor and the logic circuitry share the same power supply this would disadvantage CMOS integrated circuits where only a small battery is needed for the ICs.
motor would soon run this flat, or might not operate at all.
See diagram 39.6.2.2: (b) Driver omitted, but motor may need a large current, so contacts overheat.
Reed relays will operate satisfactorily off a low voltage supply with a coil current of only a few milliamperes, mA.
They can be operated directly using the logic gate output.
However, a disadvantage of this type of relay is that the contact ratings are often small, and could overheat when used with a motor requiring a large current.
The current need of the device to be operated by the relay lies within the current rating of the relay contacts.

39.6.3.0 Applications involving the driver amplifier and reed relay
39.6.3.1 Reversing an electric motor
See diagram 39.6.3.1: Reversing an electric motor.
Using a push-button switch, a NAND gate and the driver amplifier and reed relay, set up a circuit so that the direction of rotation of a motor is reversed when the switch is pressed.
Three batteries will be needed, one for the modules and two for the motor.
The NAND gate is not necessary if the switch is connected between the driver input and the positive supply rail.

39.6.3.2 Reversing an electric motor with a bistable circuit
See diagram 39.6.3.1: Reversing an electric motor with a bistable circuit.
Using two push-button switches, two NAND gates, a reed relay and the driver module, set up a circuit that reverses the direction of rotation of a motor when one switch is pressed and released.
Three batteries will be needed, one for the modules and two for the motor.
Use a low value resistor connected in series with the motor supply to prevent a shot circuit of the motor supply.
The resistor value must be low enough not to interfere with the operation of the motor.
The two NAND gates form an RS bistable.
The contact of the relay switch will be in the lower position when 0 is low, and the motor will rotate in a certain direction.
When the bistable is switched to its other state, 0 goes high, the relay operates and the switch goes to the higher position.
This reverses the polarity of the supply to the motor that now rotates in the opposite sense.
So a reversal occurs every time the bistable is switched.

39.6.3.3 Automatic light
See diagram 39.6.3.3: Automatic filament light.
Use a driver module, a reed relay, an LDR and gates to make a circuit in which a filament lamp will come on automatically in the dark.
Use a very bright lamp, e.g. 12 V 3 W lamp or 12 V 0.1 A MES bulb.
This shows that this circuit is controlling a much larger power than the circuit of 39.4.3 (c).
If a variable resistor is used to adjust the sensitivity so that the lamp is just on, and the lamp is moved to illuminate the LDR, the circuit becomes astable, because light from the lamp reduces the LDR's resistance.
This switches the lamp off.
The fall in light intensity then causes the circuit to switch the lamp on again.

39.6.3.4 Motor vehicle moving backwards and forwards between two light beams
See diagram 39.6.3.4: Motor vehicle moving backwards and forwards between two light beams.
Use the circuit of 39.6.3.2 with two inverters and two LDRs to make the motor reverse every time a light beam is interrupted.
The point about this application is that, when illuminated, the resistance of the LDRs will be low.
So they cannot be connected directly to the SET/ RESET inputs of the bistable, since these must both be high.
The answer is to use inverters between the LDRs and the SET/RESET inputs.
Two long leads are attached to the motor and connected to the appropriate points in the circuit.
If the LDRs are set up as shown, and illuminated by pencil torches, the vehicle should oscillate backwards and forwards between the light beams.
A 4.5 V LEGO motor from technical set 107 can be fitted with wheels and works well.

39.7.01 Coding
Coding (Commercial).
39.7.1 Sending messages using a 4 bit binary code
See diagram 39.7.1: Sending messages using a four-bit binary code.
Connect a flying lead to each of the four inputs of the LED Indicator module.
The LEDs are turned on or off by taking the flying leads at the inputs high or low.
When an input is high and the corresponding LED is on.
Let it represent the binary digit 1.
When an input is low and the corresponding LED is off, let it represent the binary digit 0.
Note that the term binary digit is usually shortened to bit.
The four LEDs can therefore represent a 4 bit binary pattern.
A 4 bit binary pattern can represent non-numerical information if an agreed code is used, e.g. the 7 bit ASCII code,
(American Standard Code for Information Exchange).
Invent a 4 bit binary code for sending messages.
Write the code in a table.
A few words have been added to start off.
How many words can be represented with a 4 bit pattern?
Give a copy of the invented code to another group, and send a message using the LED indicators.
Send the message, word by word, by lighting the agreed 4 bit binary pattern for each word.
Apart from a copy of the invented code, what other information must be given to the other group to decode the message?
When using any binary code, numerical or non-numerical, know which is the LSB (least significant bit) and which is the MSB (most significant bit).
The LSB is shown on the right when binary patterns are written horizontally according to the conventions for numbers, i.e. represents the number 13 in the scale of 10 (decimal) notation.
Table 39.7.1
MSB - - LSB
23 22 21 20
1 1 0 1

The binary digit 1 represents a high logic level, and the binary digit 0 represents a low logic level.
Encoding means that information is put into a binary pattern.
For numerical information, encoding usually means changing from a scale of ten, decimal, to a binary notation.
In decoding the information is extracted from the binary pattern.
With numerical information, this means changing from a binary to a scale of ten, decimal, representation.

39.7.2 Seven-segment LED display
See diagram 39.7.2: Seven-segment LED display.
Use the seven-segment LED display on the Seven Segment Display module.
The display has seven segments, labelled a to g in the diagram.
A single segment behaves like an ordinary LED, and lights when current flows from positive (anode) to negative (cathode).
All the cathodes are connected and to a single lead, the common cathode lead, which is connected to the negative supply line.
Connect a flying lead to the point marked TEST and touch the other end on to the pins marked a to g, one at a time.
Note what happens.
Copy the tables below and complete them to show how to display the digits 0 to 9.
Use the Display / Decoder module with a flying lead.
Insert a safety resistor between the test point and the supply line to limit the current and prevent any damage to the display in case of direct contact between the flying lead and wires on the display side of the other resistors.
Locate the terminal pins on the decoder side of these resistors to prevent damage to the display if any direct contact between a terminal pin and the positive rail, which would damage the module.
To check answers, connect the terminal pins directly to the appropriate power supply rail, because the current flowing through each segment also flows through the resistor in series with the test socket.
Eventually, the voltage drop across this resistor is too large to allow sufficient current to flow to light the segments clearly.
However, do not make direct connection of the decoder / driver outputs, the terminal pins, to the power rail.

39.7.3 Seven-segment display with a decoder
See diagram 39.7.3.1: Decoder/ driver linked to seven-segment display.
Use the Seven Segment Display module and the four decoder inputs to light the display.
Use flying leads to take the decoder inputs (A, B, C and D) high or low.
Let a high input represent the binary digit 1, and let a low input represent binary digit 0.
Use the flying leads to complete the tables.
When the digit 1 is displayed, segments b and c of the display are In.
Which outputs of the decoder must then be low, and which outputs are high?
As there are four inputs (A, B, C and D) to the decoder, 24 or 16 separate messages can be transferred.
When the binary number 0000 is received, the decoder gives the message that a, b, c, d, e, f should light and the number 0 is displayed.
When the input 0001 is received the message goes out that b and c should light and hence the number 1 displayed.
With a common cathode module, the inputs b and c are high, and all the others low.
The integrated circuit used in this experiment is called a BCD to seven segment decoder/driver.
(BCD stands for "Binary Coded Decimal").
The input is a decimal digit in the binary code (i.e. 0000 to 1001) and the decoder decodes the input to drive a seven segment display.
A BCD to seven segment display decoder may or may not respond to the numbers beyond 1001 (i.e. from 1010 to 1111), depending on the integrated circuit used.
For the recommended CMOS decoder/driver, the display will be blank beyond 1001.
An N bit binary code is said to be completely decoded if 2N distinct output signals are produced from N input signals.
In each case every possible binary pattern present on the input lines activates a distinct output line.
With two inputs there are four possible binary patterns (00, 01, 10 and 11) and so four output lines are required.
With three inputs, eight output lines are required.
With four inputs 16 output lines are required.
So N inputs require 2N outputs for complete decoding.
In computers with 16 lines from the microprocessor to the computer memory, each memory location is identified by a different binary pattern on these lines.
A separate and unique signal must be generated for each location when it is selected for the storage or retrieval of information.
If the 16 memory input lines are completely decoded, 216 = 65, 536 distinct signals can be generated to select memory locations.
Some microcomputers have a memory size of 64 K where 1 K = 1024.
So 64 K means that there are 64 × 1024 = 65, 536 memory locations.
The BCD to seven segment display decoder used earlier is not a complete decoder, since R has 4 inputs, but only 7, not 16, outputs, so it is a partial decoder.

39.7.4 Two-line to four-line decoder from NAND gates See diagram 39.7.1: Send messages using a four-bit binary code.
See diagram 39.7.2: Seven-segment LED display, single segment, use a seven-segment display with a decoder.
See diagram 39.7.3: Decoder /driver linked to seven-segment display, Examples of completely decoded N-bit binary codes.
See diagram 39.7.4: Two-line to four-line decoder using NAND gates.
Two inputs labelled X and Y that are inverted by NAND gates 1 and 2 to produce x' and y'.
An AND gate is formed from NAND gates 3 and 4, with two inputs A and B.
See diagram 39.7.3.4: Motor vehicles moving backwards and forwards between two + light beams.
If X = 0 and Y = 0, how can A and B be connected to light the LED? How can A and B be connected to light the LED, if X = 0 and Y = 1? How can A and B be connected to light the LED, if X = 1 and Y = 0?
How can A and B be connected to light the LED, if X = 1 and Y = 1?
Build the circuits and check the predictions.
Use the results from above to draw a circuit diagram of a 2 line to 4 line decoder.
Build the decoder with NAND gates.
NAND gates with 3 inputs are also available in integrated circuit form (the output is low only when all 3 inputs are high).
Draw a circuit diagram showing how a 3 line to 8 line decoder could be built from 2 input and 3 input NAND gates.
A 3 line to 8 line decoder can be built using 2 input NAND gates only.
How many of these gates would be required?
Gate 4 provides the high output to light the LED and is not essential to the decoding function.
Integrated circuit decoders are often available with high or with low outputs and the choice between these depends on the task the decoder has to do.
This 2 line to 4 line decoder uses ten NAND gates.
To build the decoder with low outputs only six NAND gates are required.
Use voltmeters to detect the logic levels.
A 3 line to 8 line decoder would require three NAND gates to invert the three inputs X1, Y1 and Z1 to produce X2, Y2 and Z2.
Eight 3-input NAND gates would then be required to produce a distinct low output for each of the eight possible combinations of X, Y and Z at the decoder inputs.
If high outputs are preferred to light indicators, a further eight NAND gates connected as inverters would be needed.
Since three 2-input NAND gates are required to produce one 3-input NAND gate, a total of [3 + (8 × 3) + 8] = 35 two input NAND gates would be required to produce a 3 line to 8 line decoder with high outputs.
Such decoders are available as single integrated circuits.