Lesson 1. The beam and CD4011

In pictures

After this lesson the library has the first chip of the CMOS 4000 series — the CD4011, four NANDs in a package, with the same pin names as in the Texas Instruments datasheet — and an IR beam works on the canvas: block it and the "someone passed" lamp lights up and stays on until Reset is pressed.


1.1. Idea: how a shop counts people

At the shop entrance, at waist height, there are two invisible beams: an emitter on one side of the door, a receiver on the other. While the doorway is free the beam gets through and the receiver gives 1. A person blocks the beam — the receiver gives 0. The whole kit is about turning these zeros and ones into two numbers on the displays: how many people are inside now and how many came in today.

doorway (top view)streetshop floorE1R1beam AE2R2beam B
Two beams across the doorway, top view. Emitter E shines across into receiver R. Beam A is nearer the street, beam B nearer the shop floor. Someone coming in blocks A first, then both, then only B; someone leaving — the other way round.

1.2. Idea: the CMOS 4000 series

In 1968 RCA released the CMOS 4000 series — chips on pairs of P and N transistors, exactly like our gates. They ran on a battery and hardly warmed up, so they went into watches, calculators and counters. The pin numbers and names are from the Texas Instruments datasheet; TI still makes these chips.

  • CD4011 — four NANDs. Inputs A–H, outputs J–M;
  • pin 7 — VSS (ground), pin 14 — VDD (power). Our power is shared, so these pins are not there.
CD40114 × NAND1A14VDD2B13H3J12G4K11M5C10L6D9F7VSS8E
CD4011: four NANDs. Gates: A·B → J, C·D → K, E·F → L, G·H → M. Pin 7 is VSS (ground), 14 is VDD (power): our power is shared, the chip has no such pins. Numbered from the notch counter-clockwise.

1.3. Idea: NAND for everything

Anything can be built from NANDs alone, so in this kit all the direction logic is on CD4011:

  • a NAND with its inputs joined is a NOT: XA = NOT BA;
  • two NANDs crossed are a latch: a zero on one input sets it to 1, a zero on the other — to 0, ones on both — it remembers.
BARSTnRSTSEENSEENNE=BA, F=SEENN, L=SEEN · G=nRST, H=SEEN, M=SEENN · C=D=RST, K=nRST
The "someone passed" latch is two NANDs from one CD4011, crossed. The beam is blocked — BA = 0 — SEEN becomes 1 and stays when the beam is whole again. The Reset button through a third NAND (both inputs together make a NOT) gives nRST = 0 and clears SEEN.

1.4. Build

A new project. You need the gate NAND — from lesson 0 or any kit of the series.

Step 1. Chip CD4011 — 4 × NAND

Package pins from the TI datasheet: 1 A, 2 B, 3 J, 4 K, 5 C, 6 D, 8 E, 9 F, 10 L, 11 M, 12 G, 13 H; 7 — VSS (ground), 14 — VDD (power) — our power is shared by all chips, so these pins are not there. Port name = pin name: double-click a port → A and so on. The gates inside: A·B → J, C·D → K, E·F → L, G·H → M.

PartPinLabel
Input portoutputA
Input portoutputB
Input portoutputC
Input portoutputD
Input portoutputE
Input portoutputF
Input portoutputG
Input portoutputH
Output portinputJ
Output portinputK
Output portinputL
Output portinputM
NANDI0
I1
O0
A
B
J
NANDI0
I1
O0
C
D
K
NANDI0
I1
O0
E
F
L
NANDI0
I1
O0
G
H
M

Ctrl+G → name CD4011. Legs: inputs A, B, C, D, E, F, G, H; outputs J, K, L, M.

Step 2. Power, IR pair and button

IR pair — the Sensors palette: the emitter E1 and the receiver R1 are placed together on channel 1, with the beam between them. The emitter shines while its input is 1 — we put it on VCC. The receiver gives 1 while the beam gets through and 0 when the beam is blocked.

PartPinLabel
PoweroutputVCC
GroundoutputGND
IR pair: emitter E1InVCC
IR pair: receiver R1OutBA
Button «Reset»outputRST

Step 3. One CD4011 — three jobs

Gate A B → J: both inputs on the beam — a NAND with equal inputs works as a NOT: XA = 1 when the beam is blocked. Gate C D → K inverts the button the same way: nRST. Gates E F → L and G H → M crossed — a latch: the beam is blocked (BA = 0) — SEEN = 1 and it stays even when the beam is whole again, until Reset is pressed (nRST = 0).

PartPinLabel
CD4011A
B
J
K
C
D
E
F
L
M
G
H
BA
BA
XA
nRST
RST
RST
BA
SEENN
SEEN
SEENN
nRST
SEEN

Step 4. Lamps

XA — the beam is blocked now, SEEN — someone passed (remembered).

PartPinLabel
LEDinputXA
LEDinputSEEN

1.5. Check

  1. Press Reset: both lamps are off.
  2. Press the beam between E1 and R1 and hold — the beam is blocked: XA and SEEN light up.
  3. Let go — the beam is whole again: XA goes out, but SEEN stays lit — the latch remembers that someone passed.
  4. Reset — SEEN goes out.
  5. Alt/⌘ + click on the beam — the beam is blocked and fixed (a cross bar on the beam); the same click clears it. This is how several beams are blocked at once — you will need it in lesson 5.
What you didXASEENWhat it is
Reset○○nobody was here
blocked the beam●●a person in the beam
let go of the beam○●the person passed — remembered
Reset○○forgotten

Lesson 1 paste (Cmd+I)

You need the gate NAND (lesson 0). The paste is the CD4011 chip and the beam with the latch.

# Lesson 1 — the beam and CD4011: an IR pair, a 4 × NAND chip and the "someone passed" latch.# Paste: Cmd+I into a project with the NAND gate (lesson 0). chip CD4011 {  portIn(A)  portIn(B)  portIn(C)  portIn(D)  portIn(E)  portIn(F)  portIn(G)  portIn(H)  portOut(J)  portOut(K)  portOut(L)  portOut(M)  NAND(A, B, J)  NAND(C, D, K)  NAND(E, F, L)  NAND(G, H, M)} power(VCC)ground(GND)irtx{channel=1}(VCC)irrx{channel=1}(BA)button{label="Reset"}(RST)CD4011(A=BA, B=BA, J=XA, K=nRST, C=RST, D=RST, E=BA, F=SEENN, L=SEEN, M=SEENN, G=nRST, H=SEEN)led(XA)led(SEEN)

¿No te sale? Algo no funciona →