Lesson 5. Direction

In pictures

After this lesson the circuit knows which way a person is going: two beams and two CD4011 light "coming in" or "going out" and give a clock at the moment both beams are blocked.


5.1. Idea: two beams one after another

Beam A is on the street side, beam B on the shop side, a step between them. Someone coming in blocks A first, then both, then only B. Someone leaving — the other way round. So the direction is which beam is blocked first.

1. only AABXAXBINOUTBOTH2. bothABXAXBINOUTBOTH3. only BABXAXBINOUTBOTH4. nobodyABXAXBINOUTBOTH
Someone comes in: step by step, what lights up. A blocked beam is grey. At step 1 the latch remembers "in" (IN); at step 2 both are blocked — BOTH = 1: here the counters add 1. At step 3 the latch has already switched to OUT, but the count is done.

5.2. Idea: remember the first

  • SIN = 0 when only A is blocked; SOUT = 0 — only B;
  • a latch on two NANDs: SIN = 0 sets IN = 1 ("coming in"), SOUT = 0 sets OUT = 1 ("going out");
  • while both beams are blocked the latch remembers who was first.

5.3. Idea: the clock is when both are blocked

BOTH = 1 when both beams are blocked. This is the clock for the counters: by this moment the direction is already remembered and does not change. Stood on one beam and left — both were never blocked, no count.

In the CD4029 datasheet TI offers one more circuit on four NANDs (Fig. 11) — for the case when there are ready clocks "up" and "down", for example from two buttons. We have no clocks — we have beams, and the direction latch already does its job.

5.4. Build

The same project. The library needs CD4011 (lesson 1).

Step 1. Power and two beams

Two IR pairs: the first — channel 1 (beam A, the street side), the second — channel 2 (beam B, the shop side). Put the pairs one under the other: a person walks across both beams.

PartPinLabel
PoweroutputVCC
GroundoutputGND
IR pair: emitter E1InVCC
IR pair: receiver R1OutBA
IR pair: emitter E2InVCC
IR pair: receiver R2OutBB

Step 2. CD4011 #1: which beam is blocked

XA, XB = 1 — the beam is blocked (a NAND with equal inputs = NOT). SIN = 0 — only A is blocked (SIN = NOT(XA AND BB)); SOUT = 0 — only B is blocked.

PartPinLabel
CD4011A
B
J
K
C
D
E
F
L
M
G
H
BA
BA
XA
XB
BB
BB
XA
BB
SIN
SOUT
XB
BA

Step 3. CD4011 #2: who was first and "both"

Two NANDs crossed — a latch: SIN = 0 sets IN = 1 ("coming in"), SOUT = 0 sets OUT = 1 ("going out"); while both or none are blocked the latch remembers. NBOTH = NOT(XA AND XB), BOTH = NOT NBOTH = 1 — both beams are blocked: this is the clock for the counters.

PartPinLabel
CD4011A
B
J
K
C
D
E
F
L
M
G
H
SIN
OUT
IN
OUT
SOUT
IN
XA
XB
NBOTH
BOTH
NBOTH
NBOTH

Step 4. Lamps

PartPinLabel
LEDinputXA
LEDinputXB
LEDinputIN
LEDinputOUT
LEDinputBOTH

5.5. Check

A person passes like this: first blocks the first beam, then both, then only the second, then leaves. With the mouse you can only hold one beam, and two are needed at once, so fix the beams: Alt/⌘ + click on a beam — blocked, the same click — cleared.

Coming in:

  1. Alt/⌘ + click on beam A — XA and IN light up: the latch remembered "coming in".
  2. Alt/⌘ + click on beam B — BOTH lights up: both are blocked. Here in lesson 6 the counting happens.
  3. Clear beam A — BOTH goes out, OUT lights up: the person is on the second beam. The count is already done.
  4. Clear beam B — only OUT is lit.

Going out — the same in reverse: B, A, clear B, clear A. At the "both" step BOTH and OUT are lit.

BeamsXAXBINOUTBOTH
only A blocked●○●○○
both blocked●●●○●
only B blocked○●○●○
nobody○○○●○

Do not delete the circuit — lesson 6 builds on it.


Lesson 5 paste (Cmd+I)

You need CD4011 (lesson 1). This circuit stays on the canvas — lesson 6 builds on it.

# Lesson 5 — direction: two IR beams and two CD4011. IN — coming in, OUT — going out, BOTH — both blocked (the clock).# Paste: Cmd+I into the same project (CD4011 from lesson 1 needed). This circuit stays — lesson 6 builds on it. power(VCC)ground(GND)irtx{channel=1}(VCC)irrx{channel=1}(BA)irtx{channel=2}(VCC)irrx{channel=2}(BB)CD4011(A=BA, B=BA, J=XA, K=XB, C=BB, D=BB, E=XA, F=BB, L=SIN, M=SOUT, G=XB, H=BA)CD4011(A=SIN, B=OUT, J=IN, K=OUT, C=SOUT, D=IN, E=XA, F=XB, L=NBOTH, M=BOTH, G=NBOTH, H=NBOTH)led(XA)led(XB)led(IN)led(OUT)led(BOTH)

Stuck? Something doesn't work →