user40830: The problem here is that I want to connect 5 input buttons to an Arduino but I do not want to utilize 5 input pins of Arduino, is there any matrix like connection using which I can reduce the number of inputs used. The conditions here are:

All the buttons will be connected to ground and initialized using:
pinMode(PIN_NUMBER, INPUT_PULLUP)

Only digital input is required and not analogue



user51082: If you do not want to use analog input but not opposed to adding one more component then you can get by with 3 digital pins, two connected to shift register (e.g. SN74HC164) and one reading common return from all buttons. Binary counter can also be used, but with rather high latency.
If you are OK with complicating things even more, you can use external logic for initializing the register, in which case two pins would be sufficient - one for clock output and another for feedback input.
Here is a simple circuit that can be extended to scan any number of buttons by chaining registers or choosing chips with more bits.

Unlike the answers stretching "digital input" function (as implied by OP) to include PWM and Serial communication, this method uses simplest digital I/O: one pin cyclically selects the button, another reads whether it is pressed or not.
The same 2-pin principle (selector output + feedback input) can be used in many different combinations. For example, you can have one side of each switch connected to the ground, as you mentioned in your question. The other sides are fed back to Arduino via analog MUX (e.g. 74HC4051). The MUX address is selected by binary counter (e.g. 74HC193) and the counter is reset by its own QD pin when it reaches 0x08.

user-1: 
Only digital input is required and not analogue

I'd consider arranging the switches to produce different voltages depending on which button was pressed and feed the resulting analogue signal level into one of these (the MOD input): -

It doesn't need to run at 1 MHz of course; RSET can be chosen to make it free run at (say) 1 kHz. The resulting duty cycle (set by the switches) can be read under software control via a digital input line.

user614: If you have only one digital pin available, you might consider the 1-wire bus. For example, the DS2408 provides 8 open-drain GPIO pins.

If you can use an analog input pin, then Brian's answer is correct.
Some simple adjustments of the resistor values create equal-size voltage steps for the A/D converter as shown below.

For the 4-switch case, this gives 5V for no switch pressed, and 0-3.75V in approximately equal steps for a switch press. This approach works well up to 16 switches and beyond.
The general approach for calculating the resistor values is as follows:

Select the pullup resistor value; say, 10K ohms.
Decide how many switches are required: N = 16.
The top switch generates 0 volts by shorting the A/D input to ground.
The next switch down will generate Vcc / N volts:
R = 10k × 1/(N-1) = 666.7 Ω
Select the nearest standard 5% value: 680 ohms
Repeat for switches i = 2 through N - 1:

The next switch down will generate Vcc × i / N volts, but you must subtract out the values of the resistors above it. This helps avoid cumulative errors.
R = 10K × i/(N - i) - 680 Ω - ...
Select the nearest standard 5% value.


For the specific example of 16 switches, you should end up with the following resistor values: 680, 750, 910, 1000, 1200, 1500, 1800, 2200, 2700, 3900, 5600, 7500, 13K, 27K and 82K. Even with 5% resistors, all of the resulting voltages are within 0.25% of full scale of their nominal values.

user19213: If all switches have one input grounded, you cannot use matrixing.
In any case, the best you could do would be a 2 * 3 matrix, which uses 5 signals, the same as individual switching (though you may be able to share the strobes with other signals e.g. display strobes)
If you are allowed to use an analog input you can pull the input high with one resistor, and allow each switch to pull it low with a different resistance. Then each switch results in a different analog voltage and you can decipher an ADC reading into a switch input. That way, only one input is required.

40830: <p>The problem here is that I want to connect 5 input buttons to an Arduino but I do not want to utilize 5 input pins of Arduino, is there any matrix like connection using which I can reduce the number of inputs used. The conditions here are:</p>
<ul>
<li><p>All the buttons will be connected to ground and initialized using:</p>
<p><code>pinMode(PIN_NUMBER, INPUT_PULLUP)</code></p>
</li>
<li><p>Only digital input is required and not analogue</p>
</li>
</ul>
 51082: <p>If you do not want to use analog input but not opposed to adding one more component then you can get by with 3 digital pins, two connected to shift register (e.g. <a href="http://www.ti.com/lit/ds/symlink/sn74hc164.pdf" rel="nofollow noreferrer">SN74HC164</a>) and one reading common return from all buttons. Binary counter can also be used, but with rather high latency.</p>

<p>If you are OK with complicating things even more, you can use external logic for initializing the register, in which case two pins would be sufficient - one for clock output and another for feedback input.</p>

<p>Here is a simple circuit that can be extended to scan any number of buttons by chaining registers or choosing chips with more bits.</p>

<p><a href="https://i.stack.imgur.com/RSPLO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RSPLO.png" alt="enter image description here"></a></p>

<p>Unlike the answers stretching "digital input" function (as implied by OP) to include PWM and Serial communication, this method uses simplest digital I/O: one pin cyclically selects the button, another reads whether it is pressed or not.</p>

<p>The same 2-pin principle (selector output + feedback input) can be used in many different combinations. For example, you can have one side of each switch connected to the ground, as you mentioned in your question. The other sides are fed back to Arduino via analog MUX (e.g. 74HC4051). The MUX address is selected by binary counter (e.g. 74HC193) and the counter is reset by its own QD pin when it reaches 0x08.</p>
 -1: <blockquote>
  <p>Only digital input is required and not analogue</p>
</blockquote>

<p>I'd consider arranging the switches to produce different voltages depending on which button was pressed and feed the resulting analogue signal level into one of these (the MOD input): -</p>

<p><a href="https://i.stack.imgur.com/KXaMm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KXaMm.png" alt="enter image description here"></a></p>

<p>It doesn't need to run at 1 MHz of course; R<sub>SET</sub> can be chosen to make it free run at (say) 1 kHz. The resulting duty cycle (set by the switches) can be read under software control via a digital input line.</p>
 614: <p>If you have only one digital pin available, you might consider the <a href="https://playground.arduino.cc/Learning/OneWire/" rel="nofollow noreferrer">1-wire</a> bus. For example, the <a href="https://www.maximintegrated.com/en/products/ibutton/memory-products/DS2408.html" rel="nofollow noreferrer">DS2408</a> provides 8 open-drain GPIO pins.</p>

<hr>

<p>If you can use an analog input pin, then <a href="https://arduino.stackexchange.com/a/71642/614">Brian's answer</a> is correct.</p>

<p>Some simple adjustments of the resistor values create equal-size voltage steps for the A/D converter as shown below.</p>

<p><a href="https://i.stack.imgur.com/3og9b.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3og9b.gif" alt="schematic"></a></p>

<p>For the 4-switch case, this gives 5V for no switch pressed, and 0-3.75V in approximately equal steps for a switch press. This approach works well up to 16 switches and beyond.</p>

<p>The general approach for calculating the resistor values is as follows:</p>

<ol>
<li>Select the pullup resistor value; say, 10K ohms.</li>
<li>Decide how many switches are required: N = 16.</li>
<li>The top switch generates 0 volts by shorting the A/D input to ground.</li>
<li><p>The next switch down will generate Vcc / N volts:</p>

<p>R = 10k &times; 1/(N-1) = 666.7 &Omega;</p></li>
<li><p>Select the nearest standard 5% value: 680 ohms</p></li>
<li><p>Repeat for switches i = 2 through N - 1:</p>

<ul>
<li><p>The next switch down will generate Vcc &times; i / N volts, but you must subtract out the values of the resistors above it. This helps avoid cumulative errors.</p>

<p>R = 10K &times; i/(N - i) - 680 &Omega; - ...</p></li>
<li><p>Select the nearest standard 5% value.</p></li>
</ul></li>
</ol>

<p>For the specific example of 16 switches, you should end up with the following resistor values: 680, 750, 910, 1000, 1200, 1500, 1800, 2200, 2700, 3900, 5600, 7500, 13K, 27K and 82K. Even with 5% resistors, all of the resulting voltages are within 0.25% of full scale of their nominal values.</p>
 19213: <p>If all switches have one input grounded, you cannot use matrixing.</p>

<p>In any case, the best you could do would be a 2 * 3 matrix, which uses 5 signals, the same as individual switching (though you may be able to share the strobes with other signals e.g. display strobes)</p>

<p>If you are allowed to use an analog input you can pull the input high with one resistor, and allow each switch to pull it low with a different resistance. Then each switch results in a different analog voltage and you can decipher an ADC reading into a switch input. That way, only one input is required.</p>
