Distance Sensor With Oled and Piezo Buzzer

by Astronaut1 in Circuits > Arduino

9 Views, 0 Favorites, 0 Comments

Distance Sensor With Oled and Piezo Buzzer

EZGIF VID.gif
Easy Street.JPG
IMG_0768.JPG
IMG_0769.JPG
IMG_0770.JPG
IMG_0771.JPG

This is a project that uses an ultrasonic sensor, an Arduino Uno, a Servo, a .96 OLED, a button, and a Piezo buzzer. When you plug it in, it sweeps the servo across the room and displays the distance on the OLED. If the distance is less than 20cm, the buzzer goes off and if you press the button it pauses.

Downloads

Introduction

Easy Street.JPG

In this project we build a mini radar scanner using an Arduino Uno, a servo motor, an HC-SR04 ultrasonic sensor, a 0.91" OLED display, a piezo buzzer, and a button. The servo sweeps the sensor back and forth, the OLED shows the live distance and angle, and the buzzer alerts you when something gets closer than 20cm. The button lets you pause, switch between cm and inches, and manually control the angle.

Parts List


  1. Arduino Uno
  2. SG90 servo motor
  3. HC-SR04 ultrasonic sensor
  4. 0.91" SSD1306 OLED display (128x32)
  5. Piezo buzzer
  6. Push button
  7. Breadboard and jumper wires
  8. External battery pack for the servo


Wiring


  1. OLED VCC → 3.3V (NOT 5V or it will fry!)
  2. OLED GND → GND
  3. OLED SDA → A4
  4. OLED SCL → A5
  5. HC-SR04 VCC → 5V
  6. HC-SR04 GND → GND
  7. HC-SR04 Trig → Pin 6
  8. HC-SR04 Echo → Pin 8
  9. Servo signal → Pin 9
  10. Servo VCC → external battery pack positive
  11. Servo GND → battery pack negative AND Arduino GND
  12. Buzzer + → Pin 3
  13. Buzzer - → GND
  14. Button → Pin 2 and GND


Install Libraries

In Arduino IDE open Library Manager and install Adafruit SSD1306 and Adafruit GFX Library.

Upload Code

Upload the final code. The servo will start sweeping automatically and the OLED will show the live angle and distance.

Using It

  1. Single click → pause/unpause the servo
  2. Double click → switch between cm and inches
  3. Triple click → enter manual mode, hold button to sweep to any angle, triple click again to go back
  4. Buzzer → beeps when anything is detected closer than 20cm
  5. Mount the HC-SR04 on top of the servo horn pointing forward for best results