This is the simplest scanning option available, as it isn’t technically scanning anything. You merely connect each switch to a microcontroller pin, turn on the input pull-up resistors on those pins, and tie the other end of the switch to ground. If your microcontroller doesn’t have pull-up resistors, you will have to place those on externally. A schematic representation is shown below.
Figure 1 – Example switch per pin schematic.
This method consumes the most amount of pins, but is the least expensive, as it doesn’t require any extra components. Although you should be careful – with a large number of pins, not only does your microcontroller cost go up, but the number of I/O lines increases. If your switches are spread out over a large board, these I/O lines could take up a lot of PCB space, and make routing difficult and drive up PCB costs. So it’s not always the best option.
The programming for this setup is very simple, as you can merely read in the state of the pins which have switches connected to them. This also makes it easy to use interrupts with your switches, as they are directly connected. You can use this method in conjunction with other methods. For example, if you have 18 switches to read, you can set up a 4×4 matrix to get 16 switches, and then connect the 2 remaining to their own microcontroller pins.