TK29ANALOGDIGITALbeginner

Analog to Digital Signal

An LM393 comparator on a TinkerBlock board: plug an analog block into the IN socket, set a threshold with the blue knob, and DIG tells your board whether the block's voltage is above or below it. The block's own voltage passes through on ANA, and a slide switch printed H and L turns the answer over.

Comes in this kit — not sold separately

Specifications

TypeThreshold switch: a comparator between an analog block and your board. DIG is HIGH or LOW; it returns no number
ComparatorON Semiconductor LM393, one of its two comparators. Offset 5 mV at most, response about 1.3 µs (datasheet typical)
ThresholdSet by a 10 kΩ single-turn trimmer from VCC to GND: any share of VCC, set with a small screwdriver
SwitchSlide switch printed H and L. H: DIG is HIGH while the input is higher than the knob. L: while it is lower
Input range0 to VCC − 1.5 V at 25 °C: about 1.8 V from 3.3 V, about 3.5 V from 5 V. Keep the knob below that; the input may go higher
OutputDIG, open collector with a 10 kΩ pull-up to VCC. ANA, the IN block's SIGNAL passed straight through
IndicatorRed LED with 1 kΩ from VCC to DIG: lit while DIG is LOW, the opposite of the output
HysteresisNone on the board. A slow or noisy input makes DIG chatter at the threshold; add hysteresis in the sketch
Supply3.3 V or 5 V on VCC, the same as your board's logic: DIG is pulled up to VCC. It also powers the block in IN
CurrentUnder 1 mA while DIG is HIGH and about 2 to 4 mA while it is LOW, plus the block in IN. Worked out, not measured
HeadersIN: 4-way right-angle socket for a TinkerBlock sensor. OUT: 4-pin right-angle male, 2.54 mm pitch, GND, VCC, DIG, ANA, GND on the square pad
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart
In the box1 × TK29 block. It also ships inside the TinkerBlock kits

What it is

A comparator between two blocks. An analog block, such as a TK08 potentiometer or a TK20 light sensor, plugs into the IN socket at the top. Your board wires to the OUT header at the bottom. Between them, an LM393 compares the block's voltage with the one set by the blue knob and says which is higher, as HIGH or LOW on DIG.

The TK29 at an angle: a black board with a gold border, a black four-way socket standing over the top edge beside a gold IN label, a silver slide switch and an eight-legged chip below it, a tall blue trimmer in the middle, a small LED and resistor at the lower left, gold chevrons down the right edge, a gold OUT label, and four right-angle pins leaving the bottom edge beside printed labels GND, VCC, DIG and ANA.
The TK29. The analog block plugs into the socket at the top; your board wires to the four pins at the bottom.

The name promises an analog-to-digital converter, and it is one only in the narrowest sense: it turns a voltage into one bit. analogRead returns a number; this returns yes or no. So the block also passes the input's voltage through on ANA, and your board can read both: the decision from DIG, the number from ANA.

The page this replaces got several things wrong. ANA is not an input to connect a sensor to; the sensor goes in IN. DIG is not always HIGH above the threshold; the slide switch decides. The inputs do not work all the way to VCC. And the output does not give a clean edge by itself: with no hysteresis, a slow input makes it chatter.

The four things to know

The switch. H: DIG is HIGH while the input is higher than the knob. L: while it is lower.

The light. The red LED lights while DIG is LOW, the opposite of the output.

The range. The LM393 compares from 0 V to about VCC − 1.5 V. From 3V3 that is 1.8 V, and the top 45 % of the knob is out of range. The input may go higher, as long as the knob stays inside.

No hysteresis. Near the threshold a slow input makes DIG flicker. Read ANA and switch at two lines in the sketch.

Which pin is which

OUT, parts up, reading left to right. The names are printed along the pins:

GNDto your board's GNDthe square pad: count from here
VCCto 3V3 or 5Vyour board's logic voltage
DIGto a digital inputthe comparator's answer
ANAto an analog input, optionalthe IN block's SIGNAL, passed through

IN takes a TinkerBlock sensor in its own order, GND, VCC, NC, SIGNAL, and prints no names. Its third position is connected to nothing, and DIG sits where a block's NC would be.

Wiring, in four lines

  1. GND to your board's GND.
  2. VCC to 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico. DIG is pulled up to VCC, so it must match.
  3. DIG to a digital pin: D2 on an Uno, GPIO 25 on an ESP32, GPIO 7 on an ESP32-S3, GP15 on a Pico.
  4. ANA to an analog pin if you want the number: A0 on an Uno, GPIO 34 on an ESP32, GPIO 4 on an ESP32-S3, GP26 on a Pico.

Then push an analog block into IN.

Example

// DIG_PIN, then ANA_PIN.
// Uno: 2 and A0. ESP32: 25 and 34. ESP32-S3: 7 and 4. Pico: 15 and 26.
const int DIG_PIN = 2;
const int ANA_PIN = A0;

void setup() {
  Serial.begin(115200);
  pinMode(DIG_PIN, INPUT);          // the block has its own pull-up
}

void loop() {
  Serial.print("DIG ");
  Serial.print(digitalRead(DIG_PIN));   // the decision
  Serial.print("   ANA ");
  Serial.println(analogRead(ANA_PIN));  // the number behind it
  delay(250);
}

Where to start

The handbook below is eleven short articles, each with a working figure. The first read is the whole build: a TK08 in IN, four wires, and DIG and ANA side by side. H and L explains the switch.

For a lamp that comes on at dusk, a light switch puts a TK20 in the socket. If DIG flickers, read chatter and hysteresis; if the knob seems dead past halfway, the input range.

When it doesn’t work

Is it an analog-to-digital converter?
Not in the sense analogRead is. A converter returns a number; this returns one bit, HIGH or LOW, from a comparator. It turns an analog voltage into a digital signal by comparing it with a threshold you set on the knob. It passes the voltage through on ANA as well, so your board's own ADC can still read the number.
Where does the sensor go?
Into the IN socket at the top, parts facing the same way as the TK29's. Its GND, VCC, NC and SIGNAL land on the socket's four positions in order, and it takes its power from the TK29. ANA on the OUT header is not an input: it is that block's SIGNAL carried through to your board.
What do H and L mean?
When DIG is HIGH. At H, while the input is Higher than the knob; at L, while it is Lower. The switch swaps the comparator's two inputs, so the threshold stays where it is and the answer turns over.
Why is the LED on when DIG is LOW?
It is wired from VCC through 1 kΩ onto DIG, so it only has a voltage across it when the comparator pulls DIG down. Lit means LOW. It is handy for setting the knob without a board.
Past halfway, the knob stops working.
From 3.3 V the LM393 compares only up to about 1.8 V, which is about 55 % of the knob's travel. Above that the threshold is out of range. From 5 V the range reaches about 3.5 V, 70 % of the travel.
DIG flickers when the input is near the threshold.
There is no hysteresis on the board, and the comparator answers in about a microsecond, so every wobble of a slow input across the knob flips DIG. Read ANA in the sketch and switch at two lines, one either side of the knob.

The analog to digital signal handbook

11 articles · about 55 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

The board

2 articles

A socket for an analog block at the top, a header for your board at the bottom, and a knob between them. It is a comparator, not a converter.

The comparator

4 articles

Two voltages in, one answer out. The switch decides which way round the answer comes, the light shows the opposite of it, and the top of the knob is out of range.

Reading it

2 articles

DIG with digitalRead and ANA with analogRead, side by side, and a sketch that tells you where the knob has put the threshold.

Using it

3 articles

A lamp that comes on at dusk with a TK20 in the socket, why it flickers as the light fades, and the short list of reasons the answer looks wrong.

Lessons using TK29

Each one is a working build, not a snippet.

Edit this page — content/modules/analog-to-digital-signal.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Analog to Digital Signal

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum