What is the role of INPUT mode on Arduino ?

Hi,
I am newbie to both Arduino and Electronics. I always thought when we are saying INPUT and OUTPUT, we assume it's INPUTof power, or OUTPUT of power.
The ledPin set to OUTPUT is hence acceptable to me. Now, power input is being given by the "POWER" pins (5V, 3.3V, etc.) - why do we specify another pin as an INPUT ? I can't understand the flow here. The source of my doubt is here :

What is the role of pin 8 ?

Thanks !

pinMode(pin, OUTPUT); digitalWrite(pin, HIGH or LOW); lets you set a pin to a HIGH/1/true logic level (near 5v) or a LOW/0/false logic level (near 0v).

pinMode(pin, INPUT); digitalRead(pin); lets you see if the signal connected to the pin is HIGH/1/true or LOW/0/false.

OUTPUT lets the Arduino control its environment.

INPUT lets the Arduino sense its environment.

OUTPUT (digital output) is to turn a led on.
INPUT (digital input) is to read if a button is pressed.

Now it gets funny: The digital pins can be programmed as digital OUTPUT or as digital INPUT, just what you want it to be.
It gets even better: The analog inputs (to read a voltage) can also be programmed as digital OUTPUT or digital INPUT.

What is the role of pin 8 ?

When the button is not being pressed, the wire connected to pin 8 is at ground because of the resistor. Both leads of the resistor are at ground. Pin 8 is grounded.

When the button is pressed, it connects 5 volts to one end of the resistor. Now one lead of the resistor is at 5 volts and the other lead is at ground. The wire connected to pin 8 is also connected to 5 volts. It stays at 5 volts because the resistor value is so great (10,000 Ohms) that it won't let very much current pass to ground. The 5 volt source from the Arduino can easily keep up and maintains the voltage at 5 volts. Pin 8 is at 5 volts.

Pin 8 is acting as an input to the Arduino. Various values can be put into the Arduino through pin 8.

We use input/output in two senses, for power and for signals - signals carry information (or more precisely we only care about the information carried - usually a tiny amount of power flows in the same direction as the signal, and modern microelectronics is all about reducing this power to as low a level as possible (so you can have more circuitry for the same power).

The button switches are an interesting case - the power flows from the supply to the resistor when the switch is closed, and stops when the switch is open - this power is far greater than the power flowing into the input pin that is sensing it - but that tiny amount is what carries the information from the switch to the processor.

BTW there is an error in that video - it claims a resistor is not needed for an LED connected to pin13 - this is wrong, the resistor is needed. Some older versions of the Arduino had an internal resistor I think, but modern Arduinos don't.

Let's get back to the basics and answer his question: "What is the role of INPUT mode on Arduino"

A microcontroller, which is what the Arduino basically is, is designed to control things via it's OUTPUT capability.

It determines what to do and when to do it based upon cues that it gets using it's INPUT capability.

Don

Now it gets funny: The digital pins can be programmed as digital OUTPUT or as digital INPUT, just what you want it to be.
It gets even better: The analog inputs (to read a voltage) can also be programmed as digital OUTPUT or digital INPUT.

It's not really funny at all, it's just a result of the simplification in terminology that was devised to make it easier for non-technical types to use the microcontroller.

The microcontroller used as the basis for the Arduino UNO etc, has 20 available I/O (Input/Output) pins. They are all basically the same and any of them can be configured as either INPUT or OUTPUT and they can be switched 'on-the-fly', while the program is running. All of the I/O pins have alternate functions and it is those alternate functions upon which the simplified Arduino terminology is based.

Six of the pins can be connected to an internal A/D (Analog to Digital) converter so those are called 'Analog Inputs'. Six of the pins can be driven by the internal timers to produce PWM (PulseWidth Modulated) signals so those are called 'PWM' pins. Two of the pins can be used for Serial communications so those are called TX(Transmit) and RX(Receive). If you are not using some of that capability then the corresponding pins are available for normal I/O.

Don