Lesson 5. Direction
In picturesAfter 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.
5.2. Idea: remember the first
SIN= 0 when only A is blocked;SOUT= 0 — only B;- a latch on two NANDs:
SIN= 0 setsIN= 1 ("coming in"),SOUT= 0 setsOUT= 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.
| Part | Pin | Label |
|---|---|---|
| Power | output | VCC |
| Ground | output | GND |
| IR pair: emitter E1 | In | VCC |
| IR pair: receiver R1 | Out | BA |
| IR pair: emitter E2 | In | VCC |
| IR pair: receiver R2 | Out | BB |
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.
| Part | Pin | Label |
|---|---|---|
| CD4011 | A 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.
| Part | Pin | Label |
|---|---|---|
| CD4011 | A 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
| Part | Pin | Label |
|---|---|---|
| LED | input | XA |
| LED | input | XB |
| LED | input | IN |
| LED | input | OUT |
| LED | input | BOTH |
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:
Alt/⌘+ click on beam A —XAandINlight up: the latch remembered "coming in".Alt/⌘+ click on beam B —BOTHlights up: both are blocked. Here in lesson 6 the counting happens.- Clear beam A —
BOTHgoes out,OUTlights up: the person is on the second beam. The count is already done. - Clear beam B — only
OUTis lit.
Going out — the same in reverse: B, A, clear B, clear A. At the "both" step BOTH and OUT are lit.
| Beams | XA | XB | IN | OUT | BOTH |
|---|---|---|---|---|---|
| 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)¿No te sale? Algo no funciona →