Switch as an input. There are two configuration which are pull up (resistor tied up to 5V) and pull down (resistor tied down to 0V). In other word, pull up configuration is active low (logic 0 when switch is press) while pull down configuration is active high (logic 1 when switch is press).
Cheat Sheet : Switch
You can create 4x3 keypad only by using 1 analog input pin. Analog keypad node is connected to the analog pin. By pressing different switch will output different voltage. This voltage is then capture to determined which switch are being press. If no pin press, ADC pin will read approximately near to 5V.
Cheat Sheet : Analog Keypad
This 4x4 keypad need 8 pin in order to function. 4 pin as an input and 4 pin as an output, then it need to swap the role. Microcontroller need to scan the column value and then the row value.
Cheat Sheet : Matrix Keypad
Phototransistor convert light into current. Figure below is the simplest circuit in order to convert the current reading in phototransistor to the voltage.
Cheat Sheet : Phototransistor