Go Down

Topic: [ Arduino UNO ] Button state change (Read 16305 times) previous topic - next topic

PaulS

Quote
You set it as INPUT and do a digitalwrite HIGH to the pin.

What that accomplishes is to enable the pullup resistor, not turn the pin on.
The art of getting good answers lies in asking good questions.

wdl1908


Quote
You set it as INPUT and do a digitalwrite HIGH to the pin.

What that accomplishes is to enable the pullup resistor, not turn the pin on.


And the difference is?
What does a pull up resistor do?
Effectively turn the pin to 5v.
Ok you would not get enough current to get a LED burning bright but that not the goal is it?

PaulS

The difference between an INPUT pin, where some external source is supplying the voltage, and an internal pin that is set HIGH or LOW is that one can reasonably assume that the switch is pressed if the voltage is present, and not pressed if there is no voltage present (in a pulldown resistor situation) or the reverse (in a pullup resistor situation).

If the pin is set as OUTPUT, the HIGH/LOW state is dependent on what digitalWrite() was used to set it to, not on whether there is something consuming the voltage/current supplied to the pin.
The art of getting good answers lies in asking good questions.

wdl1908


The difference between an INPUT pin, where some external source is supplying the voltage, and an internal pin that is set HIGH or LOW is that one can reasonably assume that the switch is pressed if the voltage is present, and not pressed if there is no voltage present (in a pulldown resistor situation) or the reverse (in a pullup resistor situation).

If the pin is set as OUTPUT, the HIGH/LOW state is dependent on what digitalWrite() was used to set it to, not on whether there is something consuming the voltage/current supplied to the pin.


Very Correct, but that was not the question was it?

This was the question


I only have one question left: Why is there a separated 5v wire? Why not power it by the same pin 2?


So to get power to an input pin you just do a digitalwrite HIGH to the pin and the pin is powered via a pull up no extra resistor needed. Then connect the pin via the button to GND and the digitalread of the pin will be LOW when the button is pressedn and HIGH when it is not pressed.

PaulS

Quote
So to get power to an input pin you just do a digitalwrite HIGH to the pin and the pin is powered via a pull up no extra resistor needed.

No. The digitalWrite() function, for an INPUT pin turns on or off the pull-up resistor. It does NOT turn the pin HIGH or LOW. Only OUTPUT pins can be set (forced) HIGH or LOW.
The art of getting good answers lies in asking good questions.

wdl1908


Quote
So to get power to an input pin you just do a digitalwrite HIGH to the pin and the pin is powered via a pull up no extra resistor needed.

No. The digitalWrite() function, for an INPUT pin turns on or off the pull-up resistor. It does NOT turn the pin HIGH or LOW. Only OUTPUT pins can be set (forced) HIGH or LOW.


Please answer me this.

What does a pull up resistor do?

AWOL

Quote
What does a pull up resistor do?

For low currents, it pulls up to (or very near) the supply rail.
But it limits the current available.

wdl1908


Quote
What does a pull up resistor do?

For low currents, it pulls up to (or very near) the supply rail.
But it limits the current available.


Thank you AWOL you just proved my point.

AWOL

Quote
Thank you AWOL you just proved my point.

Do you mind me asking what your point was?
(bearing in mind that the pull-ups are in the range 20 to 50 kOhm)

wdl1908


Quote
Thank you AWOL you just proved my point.

Do you mind me asking what your point was?
(bearing in mind that the pull-ups are in the range 20 to 50 kOhm)


The point was that PaulS said that to get power on the pin you need to configure it as an OUTPUT. I said that it's not needed you just need to digitalWrite HIGH to an INPUT pin to get it powered. The original question was.


I only have one question left: Why is there a separated 5v wire? Why not power it by the same pin 2?

AWOL

Yes, but a couple of hundred micro amps at five volts is not what first comes to mind when someone mentions "power".

wdl1908


Yes, but a couple of hundred micro amps at five volts is not what first comes to mind when someone mentions "power".


No you are right it is not but it seems a lot of people who ask questions are not very knowledgeable about electronics but in light of the question and the desired effect it is supposed to accomplish it is enough.

Go Up