Part 03 / 12

Inputs: Buttons and the Floating-Pin Trap

A logic input connected to nothing does not read as 0, it reads as whatever its surroundings suggest, and one 10 kΩ resistor is the difference between a circuit that works and one that seems haunted.

6 sections 1 interactive
§ 3.1

High, low and the gap between

A logic chip does not care about exact voltages. It sorts every input into one of two bins, or , 1 or 0. For the 74HC chips in this series, running on 5 volts, the bins are:

Input voltage The chip reads
3.5 V to 5 V high, 1, guaranteed
1.5 V to 3.5 V not guaranteed: high, low, or flickering between them
0 V to 1.5 V low, 0, guaranteed

The thresholds are fractions of the supply: CMOS inputs read anything above 70 % of it as high and anything below 30 % as low. On 4.5 volts from three AA cells, that is above 3.15 and below 1.35 volts.

The wide margins are deliberate. A real high is rarely exactly 5 volts and a real low rarely exactly 0, and the margins let a slightly tired battery, a long wire or a little electrical noise make no difference at all. The middle band is the problem. The chip promises nothing there, and an input that spends time in it gives answers that change from moment to moment.

§ 3.2

A button is not an input

Here is the trap. You want a button to make an input high when pressed and low when released. So you connect one side of the button to +5 V and the other to the input. Pressed, it works: the button joins the input to +5 V, and the chip reads high.

Released, the button is an open gap, and the input is connected to nothing at all. Nothing is pulling it low. It is not 0 volts; it is , and a floating input reads at random. The LED it drives might stay on after you let go, go off a second later, flicker when you move your hand, or change when someone switches on a lamp across the room.

This catches nearly every beginner, and it is maddening because it sometimes seems to work. Try it on screen first.

§ 3.3 · interactive

Try it: the floating input

Try it

The floating input

Hold the button, then let go and watch the input with nothing connected. Bring your hand near the wire. Then fit a pull-down resistor, and try a pull-up.

+5 Vbuttonjust a wire74HC08LED 5 V3.51.50 Vreads highanyone's guessreads lowLED

Floating: the input keeps whatever charge it last had, and stray charge and hum push it about. Wait, or bring your hand near.

One input of a 74HC08 on 5 V, with both inputs of the gate joined so its output simply follows the input. The floating voltage is a simplified model of stray charge and mains hum; real ones are just as unpredictable.

§ 3.4

Why it floats

A CMOS input, the kind on every 74HC chip, is the gate of a tiny transistor: a small plate of conductor, insulated from everything else by a very thin layer of glass. It draws almost no current. That is wonderful when something drives it, because a chip can feed dozens of inputs without effort. But it also means that when nothing drives it, nothing holds it either.

So the input behaves like a tiny capacitor that keeps whatever charge it last had. Let go of the button and it stays high, for a while. Then stray charge leaks in and out, and the wire to the input acts as an aerial. It picks up hum from the mains wiring in the walls, which swings back and forth 50 times a second in Europe and 60 in North America, and your hand, near the wire, couples in more. The voltage wanders through the middle band, and the output follows it.

Floating inputs cause a second, quieter problem. Inside the chip, every input drives a pair of transistors, one that connects the output towards +5 V and one towards ground, and part 5 shows how. An input stuck halfway turns both of them partly on at once, so current flows straight through them from + to ground. It wastes power and, with several floating inputs, can make a chip noticeably warm. That is why datasheets ask for every unused input to be tied high or low, even on gates you are not using.

§ 3.5

The 10 kΩ pull-down

The fix is one resistor from the input to ground, a . With the button released, the resistor connects the input to 0 V, and the input reads a firm low. A CMOS input takes almost no current, so almost none flows through the resistor, and by Ohm’s law it drops almost no voltage: the input sits at 0 volts, not somewhere near it. The Resistor shows the same law at work in a voltage divider. Pressed, the button connects the input straight to +5 V. The button wins, because it is a near-perfect connection and the resistor is a weak one, so the input reads high. The resistor simply passes a small current from +5 V to ground while the button is held:

5 V ÷ 10,000 Ω = 0.5 mA

Why 10 kΩ? A much smaller resistor works but wastes current, 5 mA through 1 kΩ, every moment the button is held. A much bigger one, a megohm or more, holds the input so weakly that hum and a nearby hand can still nudge it. Anything from about 4.7 kΩ to 47 kΩ works well, and 10 kΩ is the usual choice.

The mirror image works too. Connect the button between the input and ground, and put the resistor from the input to +5 V: a . Now the input is high until you press, and low while you do. A pressed button reading 0 is called , and it is common, especially in microcontrollers, many of which have pull-up resistors built in. This series mostly uses pull-downs, so that pressed means 1, but part 10 will need pull-ups.

If you built the motor circuit in Driving Bigger Things, you have met this before: a MOSFET’s gate floats in exactly the same way, and the same 10 kΩ pull-down fixed it.

§ 3.6

Build it

This build uses your first chip, a 74HC08, but only as a messenger. Its first gate has both inputs joined together, so its output simply copies the input, and drives an LED. Part 7 explains chips properly; for now you need three facts. Pin 1 is next to the notch, pin 14 goes to +5 V, and pin 7 goes to ground.

  1. Push the 74HC08 across the channel with its notch to the left, pin 1 in f14.
  2. Wire pin 14 (a14) to the top + rail and pin 7 (j20) to the bottom − rail. Put the 100 nF capacitor across the top two rails right beside pin 14.
  3. Tie the six unused inputs to ground with short black wires: pins 4 and 5 (j17, j18) to the bottom − rail, and pins 9, 10, 12 and 13 (a19, a18, a16, a15) to the top − rail.
  4. Put the push button across the channel in columns 7 and 9, and wire a7 to the top + rail.
  5. Fit the 10 kΩ pull-down from j9 to the bottom − rail.
  6. Run a yellow wire from h9 to h14, the strip of pin 1, and join pins 1 and 2 with a short wire from g14 to g15.
  7. From pin 3, run a wire from h16 to h23. Fit the 330 Ω resistor from g23 to g26, the LED with its long leg in i26 and its short leg in i27, and a black wire from j27 to the bottom − rail.
What you should see

The LED is off, and stays off when you wave your hand over the board. It lights instantly while you hold the button and goes out the moment you let go. Now pull out the 10 kΩ resistor: the LED may stay on after you let go, drift off later, or flicker when you touch the yellow wire. Put the resistor back.

You now have an input you can trust and an output you can see. The next part puts something cleverer than a messenger between them: a gate that makes a decision.

Sources for this part

Logic levels and floating inputs

The 7400 series

Series Logic on a Breadboard
Menu

Gears & Signals · Static site · No trackers