Arduino Ladder · Bozoma Innovation Hub

Band 7  ·  Distance and Display

Swap  The guard on a four-digit display

The same parking guard, two pins instead of six, a much shorter sketch, and digits you can read across a room.

Time
90 min
You need
TM1637 display, HC-SR04, buzzer, 12 jumper wires (plus the Band 4 light sensor and its 10k resistor if you do Gold)
At once
One per display
Before this
Finish Band 7 up to Part 4. This replaces the screen work in Parts 5 to 8, so come here if the twelve-wire screen defeated you. If your screen has a small green board soldered to its back, do Part 6a instead: it is already four wires and you keep the letters.

Sketches for this project

Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.

Why

The other road through Band 7

Band 7's core build puts the parking guard on an LCD. On the bare sixteen-pin kind that is twelve wires and a contrast knob, and it is the longest single build in the course.

This is the same device on a four-digit display. Two Arduino pins instead of six, and four wires to the screen instead of twelve. Twelve wires on the whole board rather than twenty-two. And digits bright enough to read from across a room, which is a thing an LCD genuinely cannot do.

If the twelve-wire screen defeated you, come here instead. Be honest with yourself about the trade, though. You do not get the padding bug, you do not get the contrast knob, you do not get the experience of finding one wrong wire among twelve, and you do not get the sixteen-character writing exercise, which is the best design problem in the band and cannot be done on four digits. Those are real losses. The Look closer section turns two of them into something you can write up, and the Done list below makes you do the writing exercise on paper anyway.

Is this your display?

A small blue board with four red digits, a colon in the middle, and four pins

Marked CLK, DIO, VCC, GND. There is a chip on the back doing the hard work.

→ This page. Build it.

A wide green board with sixteen bare pins along the top and a blue screen

That is the LCD, the bare kind, with nothing soldered to its back. It shows letters as well as numbers, which this one cannot. Twelve wires and a contrast knob.

→ Band 7 Part 6b, and b7_05_bin_worked_parallel.ino.

The same blue screen, but with a small green board soldered to the back of it

Four pins on that little board, marked GND VCC SDA SCL. That is the I²C LCD: the same screen with the twelve wires already done for you inside. Four wires, no contrast knob.

→ Band 7 Part 6a. Do that rather than this page: it is already short, and you keep the letters.

If you have both, build this one first. It gets you a working guard in an hour, and the LCD version then makes much more sense because you already know what the device is supposed to do.

Build

Four wires to the screen, twelve on the board

30 min
+ − − + j i h g f e d c b a 16 20 25 30 35 40 45 USB ARDUINO UNO HC-SR04 VCC / Trig / Echo / GND HC-SR04 VCC / Trig / Echo / GND + + buzzer buzzer a40 a40 a42 a42 b40 b40 b42 b42 f20 f20 f21 f21 f22 f22 f23 f23 j20 j20 j21 j21 j22 j22 j23 j23 SCL SCL SDA SDA AREF AREF GND GND 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 IOR IOR RST RST 3V3 3V3 5V 5V GND GND GND GND VIN VIN A0 A0 A1 A1 A2 A2 A3 A3 A4 A4 A5 A5
The sensor's four holes do not move. Three of its wires do: VCC and GND go to the rails, and Echo goes back to pin 11.
Which rail pairYour board has two + rails and two − rails, one pair along each long edge, and on most boards the two pairs are not joined to each other. On this page, as in all of Band 7, “the rail” always means the pair along the top edge, nearest row j. The buzzer sits down in rows a and b and its wire still runs the long way round to the top pair. Split the rail wires across both pairs and nothing works, with nothing visibly wrong.
Before you startUSB unplugged. If the LCD is on the board, take it and its twelve wires off, and take out the contrast knob too. The sensor's own four holes stay where they are, but three of its wires move: its VCC goes to the + rail instead of straight to 5V, its GND goes to the − rail instead of straight to a GND pin, and its Echo goes back to pin 11 if Part 6b had you move it to pin 9. The table below has both.

Install the library. Tools, then Manage Libraries, search TM1637, and install the one by Avishay Orpaz. Once, on one machine.

You should seeINSTALLED next to it in the list.
If you have no internet on that computerDownload it as a .zip on any machine, carry it on a USB stick, and use Sketch, then Include Library, then Add .ZIP Library.

Wire it.

PartPinNote
Display CLK2Any digital pin would do; these two were free.
Display DIO3
Display VCC+ railTwo things want 5V and the Arduino has one 5V pin. That is what the + rail is for.
Display GND− rail
Sensor VCC+ rail
Sensor Trig10
Sensor Echo11Move it back to 11 if you got as far as Part 6b, which had you put it on pin 9 because the LCD wanted pin 11 for itself. This display does not. Leaving it on 9 gives you a permanent 999 that looks exactly like a broken sensor.
Sensor GND− rail
Buzzer6Body in the board, long leg b40, short leg b42. Wire a40 to pin 6, wire a42 to the − rail. No resistor. If the legs will not reach two holes apart, use b40 and b43, and move the − rail wire to a43. Never put both legs in the same numbered column: the five holes in a column are one connection, so the buzzer would be shorted out and pin 6 joined straight to ground.
Power5VOne wire from the + rail to the Arduino's 5V pin
GroundGNDOne wire from the − rail to a GND pin
You should seeTwelve wires when you have finished counting: four to the display, four to the sensor, two to the buzzer, and the two rail wires. The LCD version of this build has twenty-two.

Upload b7_06_guard_tm1637.ino.

You should seeThe digits light up showing 0, then a distance in centimetres that follows your hand. Walk your hand in and the beeping starts slow, speeds up, and becomes one solid tone under 10 cm. Take your hand away and it goes quiet and shows 999.
If the display stays darkCheck VCC and GND first. Unlike an LCD there is no contrast to get wrong, so a dark display here really is a power problem.
If the digits are lit but show nonsenseCLK and DIO are swapped. They are next to each other on the board and it is an easy mistake.
If it always shows 999The sensor is reading 0, which means no echo. Point it at a flat wall 30 cm away. If it still shows 999, check Trig and Echo are not swapped.
If the digits are too dim or too brightChange the 5 in screen.setBrightness(5). It goes from 0 to 7.
Look closer

A whole class of bug that is simply not available here

25 min

Band 7 Part 7 spends a long time on two faults: a screen that flickers, and a screen that leaves old digits behind when the number gets shorter. Going from 100 to 99 showed 990, and the fix was to pad every write to a fixed width.

Neither problem exists on this display.

void showDistance(long cm) {
  if (cm == lastShown) {
    return;
  }
  lastShown = cm;
  screen.showNumberDec(cm, false);
}

No padding. No spaces. No counting to sixteen. showNumberDec draws all four digits every time, so there is nothing left over to leave behind.

The question worth sitting with

Two devices doing the same job, and one of them has a whole category of bug that the other cannot have.

  1. Why can the TM1637 not leave an old digit behind, when the LCD can?
  2. These three lines are still there even though flickering is not a problem here:
    if (cm == lastShown) {
      return;
    }
    Take them out and upload. What actually changes?
  3. Which of the two devices would you rather hand to somebody who has never programmed?
Check your answers

1. Because it has no cursor and no idea of “where you are”. An LCD writes characters one after another from wherever the cursor was left, so a short word overwrites part of a long one. The TM1637 has exactly four digit positions and redraws all of them on every call. Fewer choices, fewer mistakes.

2. Very little that you can see, and that is the honest answer. Taking it out makes the board send the same number to the display about twenty times a second, which is the rate the delay(50) at the bottom of loop sets, instead of only when the number changes: wasteful, and on some displays a source of faint flicker, but not visibly broken here. Keeping it is still right. Doing work that changes nothing is a habit worth not having, and on a busier sketch it would matter.

3. There is no wrong answer, but say why. This one is easier to wire, easier to write for, and readable across a room. The LCD shows words, which is the entire reason Band 7's core build says Nearly there rather than a number. A guard that can say STOP is telling somebody what to do; one that says 08 is making them work it out.

The colon, and the two numbers that are easy to confuse

The two dots in the middle live on the second digit, and there are two ways to switch them on. They use different numbers, and swapping them is the usual way people lose an evening.

If you are usingThe colon isLooks like
setSegments, drawing digits by hand0x80, added into the second digit's own bytedata[1] = data[1] | 0x80;
showNumberDecEx, letting the library do it0x40, passed as the dots argumentscreen.showNumberDecEx(t, 0x40);

0x80 is the colon bit inside a digit. 0x40 is what showNumberDecEx wants you to hand it, and the library turns it into 0x80 on your behalf. Two numbers for one job, because two different people wrote the two functions. This is normal, and reading the library's own header file is how you settle arguments like this.

This sketch leaves the colon off. Turn it on with showNumberDecEx(cm, 0x40) if you want to see it. Blinking it once a second is what makes a four-digit display look like a clock rather than a number, and it is a few lines with a millis check if you ever build one.

Change it

Make it yours

35 min
Bronze
Show ---- instead of 999 when nothing is in range. Use setSegments, which takes four bytes, one for each digit:

uint8_t dashes[] = {0x40, 0x40, 0x40, 0x40};
screen.setSegments(dashes);

In a setSegments byte, 0x40 is the middle bar of a digit. That is the same number that means “colon” when you hand it to showNumberDecEx, and it is exactly the confusion the table above is about. Then say in your log, in one sentence, why dashes are better than 999 for the person using the thing.
Silver
Use the four digits to show two numbers at once: the current distance on the left pair and the closest you have got on the right pair, with the colon lit to separate them. You have four digits and two things to say, so both have to fit in two digits each, and deciding what to do about 100 or more is the interesting part.
Gold
Make the brightness follow the room, using the light sensor from Band 4: dim at night, bright in daylight. Then measure your own thresholds properly, as Band 4 taught you, and write them in your log. A display that is blinding at night is a display people unplug.
Done

You still owe Band 7 the same evidence

This Swap replaces the LCD guard. To claim Band 7 you still need:

  • A video of somebody using it, and a close photo of the display with a real reading on it
  • Your ruler-accuracy table from Part 3, all five rows, plus your notes on the three awkward surfaces
  • Your beep timing table from Part 9b. Part 9b walks through the LCD sketch, but its gapFor function is character for character the same as the one in your sketch, so do the table on your own file and write in your log that you did
  • Your four sixteen-character messages, written out and counted on paper, even though this display cannot show them. This is the band's best design exercise and you do not get to skip it for having a shorter screen
  • The two distances you decided you would trust, and why
  • Your build log
  • Five or six correct answers in Part 11, the Check yourself questions, including question 2

Part 11's questions are set on an LCD sketch you have not built, and one of them is about the padding problem this display does not have. Answer them anyway, and use the comparison above to do it. Knowing why a bug cannot happen on your hardware is a better answer than never having met it.

Ship it

One video under sixty seconds, and one post of five lines. You built something different from the person next to you, so your video is the one nobody else in the room can post. Say in the post which build you chose and why — that choice is itself worth a line.

The four shots: three seconds of the thing still, fifteen of you doing something to it, fifteen of it responding all the way to the end, and ten of your measurement or the thing that went wrong first.

Show your work has the template and the three checks to make before anything goes public. Tag it #BozomaBuilds.