We will continue our exploration of sensors by modifying our original Hello LED
code. In this project, we will combine a distance sensor with our PIR sensor, and flash an LED based on the values of these sensors. This circuit will not only tell us that someone is approaching, but will also give us an indication of how close they are.
We will cover the following in this section:
- Configuring a distance sensor
- Taking
Hello LED
to another level
We will start by configuring the distance sensor and running some code. The following is a circuit diagram of our distance sensor circuit:
The following are the connections to be made:
- VCC from the motion sensor connects to the 5 V DC output from the Raspberry Pi
- GPIO pin 17 connects to Trig on the distance sensor
- Echo on the distance sensor connects to a 330 Ohm resistor
- GND on the distance sensor connects to GND on the Raspberry Pi and a 470 Ohm resistor
- The other end of the 330 Ohm resistor...