Introduction: Arduino Motion Activated Distance Sensor
In this project we will make a distance sensor that gets triggered by a motion sensor and outputs the centimeters/inches of it to the OLED display. This is useful if you need to be able to check when something passes a point as well as check how far the object is from your place at which you place your circuit.
Supplies
Materials:
Breadboard
Distance Sensor
OLED Display
Arduino
PIR Sensor
Switch
LED
Jumper Wires
330 and 560 ohm Resistors
Pushbutton
Step 1: Set Up Breadboard
First, prepare the breadboard by connecting the power and ground rails to the arduino with jumper wires as shown. Optionally you can colour code them as they are in the image above.
Step 2: Connecting Components
Plug in your components in to the breadboard, refer to the title image for help. Plug in your LED with a 330 ohm resistor into ground and the cathode as well as a black wire connecting the ground rail and the anode. Then, plug in the motion sensor and distance sensor facing outwards as well as plugging in trig, echo and the middle pin of the motion sensor of the motion sensor to the arduino. Connect the respective vcc(power) and ground pins to their respective rails with jumber wires. Connect the pushbutton with the motion sensor with a 560 ohm resistor as well as giving it power on the bottom right end of it. Then connect the bottom left leg to the digital pin 10 (the pin with the 10 and the squiggly line beside it.) Then connect your switch between the connection of the power and ground of the distance sensor connecting it with jumper wires from the power and ground rails into the switch then from the switch into the vcc(power) and ground respectively. Then plug in your Trig pin into digital pin 8 and Echo into digital pin 9. After that you should plug in your SCL pin from the OLED into the A0 pin on your arduino as well as the SDA pin into the A1 pin of your arduino.
Step 3: Configuration (Software)
Once everything is wired properly and set up make sure to plug your arduino into your computer and download Arduino IDE Here and download the libraries Adafruit BusIO, Adafruit GFX Library and Adafruit SSD 1306.
Then paste in the following code , then click "upload" with your completed corcuit plugged in to your device.
Attachments
Step 4: Finished
Now that you are finished, you can use it for whatever you want to, to whatever extent you want to.