Common sensor interfaces and code examples
Now that we have gotten to know a few types of very useful sensors for Arduino robots, we need to understand how to talk to them. As we mentioned in Chapter 1, Introducing Robotics and the Arduino Ecosystem, an Arduino board such as the Arduino Uno has many different types of interfaces and the Arduino IDE provides us with the software building blocks to use these interfaces very easily. This section will walk you through the most relevant interfaces and show example code for each of them that communicates with a specific sensor.
GPIO – great for simple sensors
General-Purpose Input/Output (GPIO) includes all the digital pins of our Arduino. For the purpose of this section, we will only use its input functionality. To interface with sensors, it can be used in two different modes (with and without an internal pull-up resistor), and some GPIOs can serve as external interrupt triggers to capture inputs with very high timing accuracy...