Now that we have built our port expander hardware, we need to learn how to program it so that our Raspberry Pi can detect the things that we connect to it as part of our home security system. We will begin by connecting switches to our system in the form of magnetic sensors—the most common component used in home security systems to detect intrusions through doors and windows.
In this chapter we will cover the following topics:
Learning about reed switches and how they work as door sensors
Enabling and setting up the I2C bus on the Raspberry Pi
Connecting our sensor to an input on our port expander
Learning how to access our I2C port expander from a Bash script
Writing a script that will detect the state of our door sensor
Looking at other types of contact sensors that can be connected and programmed in the same way