0

When use switchstrong text

We know when use switch easy for us to state input logic.

Logic 1 means input connected to positive terminal.

Logic 0 means input connected to negative terminal.

How about unconnected input from anywires?

It will be problem when use pushbutton as input.

I want when unpushed button the state input will be 0. When button pushed, the state input will be 1.

But the problem is when button unpushed, the input state will "unconnected to any wires" which we can't say it as 0 state due to 0 state means connected to groundenter image description here

  • 1
    Pull-down resistor 10k or 100k will do. (Also add a LED driving resistor, like 330R) –  Dec 05 '20 at 15:26
  • 1
    @BrianDrummond if that really is a 7404 or other bipolar device like 74LS04 the pull down would have to be considerably stronger. For a 74HC04 or other CMOS device it would work though. – Justme Dec 05 '20 at 15:29
  • @Justme Somehow I read it as 74HC04 ... wrongly. You are correct. –  Dec 05 '20 at 15:34

2 Answers2

2

This is the job of what's called a pull-up resistor (or a pull-down resistor, depending on how you're using it). The circuit you should use looks like this:

schematic

simulate this circuit – Schematic created using CircuitLab

The left one is using a pull-down resistor, and will read logic low (0 for active-high logic) whenever the switch is not pressed, and will read logic high when it is. The right one is the opposite, using a pull-up resistor; this reads logic high (1 in active-high logic) when the switch is not pressed, and logic low when it is.

You'll need one resistor for each input, but if that sounds like too much, you can get resistor networks that have many resistors in a single package, and some logic chips have internal pull-up or pull-down resistors; check your datasheet. If you're using a microcontroller, most of those allow you to configure their inputs to use an internal pull-up or pull-down resistor; look at your μC's datasheet for information on this. It's usually as simple as setting bits in a register somewhere.

The exact value of the resistor doesn't matter that much. The lower the resistor, the faster it can charge or discharge the input capacitance, but this only really matters when dealing with things that actuate much faster than pushbuttons, like an I²C bus. But also, the lower the resistor, the higher the current will be when the switch is pressed, so you don't want it too low. Somewhere in the range of 1kΩ to 100kΩ usually works fine.


A note since you're using a 7404 specifically: the 7404, as well as the 74LS04, has internal pull-up circuitry, so you don't need any resistors if you put your pushbutton between the input and ground. An unconnected input will be read as high.

The presence of this internal pull-up also means that if you want a pull-down, you're going to need to use a small resistor value since you'll be forming a voltage divider.

Note that the 74HC series, unlike most 74 variants, does not have internal pull-ups, so if your chip is actually a 74HC04 you will need an external resistor.

Hearth
  • 27,177
  • 3
  • 51
  • 115
  • Thank you very much, your answer is more than i expect. How about double pull resistor? I mean both of your picture has combined and we got two resistor, the one near VCC the one near GROUND (both resistors have same value)? And we put push button whatever we want for example near VCC. What kind that resistor? – Muhammad Ikhwan Perwira Dec 05 '20 at 16:41
  • That would be a voltage divider, and wouldn't do anything useful for logic circuitry but is very useful for analog electronics. – Hearth Dec 05 '20 at 17:26
1

Typically a resistor is used for keeping the input at logic high level, and pushbutton to connect the input to ground.

Justme
  • 127,425
  • 3
  • 97
  • 261