Project tutorial
Ultrasonic Distance Sensor & Display

Ultrasonic Distance Sensor & Display © GPL3+

A fun way to measure distance

  • 550 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

This is a ultrasonic distance sensor, with a display. It can be used to measure stuff with one hand. This is done with an idioTware shield and an accompanying i2c 128*64 OLED display, which outputs data from the ultrasonic sensor.

Step 1: Connect the idioTware shield to the Arduino Uno, it only goes in one way.

Step 2: Connect the display to the pins on the top-left corner of the idioTware shield, with the power and ground matching up.

Step 3: Connect the ultrasonic sensor's power leads to the power row on the digital I/O pins in the center of the board.

Step 4: Connect the Trig pin of the ultrasonic sensor to digital pin 3.

Step 5: Connect the Echo pin of the ultrasonic sensor to digital pin 2.

Step 6: Power up the Arduino and upload the code.

Done! now you can measure distance with the ultasonic sensor and display it.

Code

Ultasonic Distance Sensor & Display CodeArduino
#include<NewPing.h>
#include"U8glib.h"

#define TRIGGER_PIN 3
#define ECHO_PIN 2
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI

void setup() {
  u8g.setRot180();
}

void draw(int distance) {
  u8g.setFont(u8g_font_fur30);
  u8g.setPrintPos(0, 63);
  u8g.print(distance);
  u8g.print("cm");
}

void loop() {
  int dist = sonar.ping_cm();
  u8g.firstPage();
  do {
    draw(dist);
  }
  while (u8g.nextPage());

  delay(100);
}

Comments

Similar projects you might like

LCD display distance of an ultrasonic sensor

Project tutorial by adam johns

  • 5,936 views
  • 0 comments
  • 8 respects

Distance Sensor and OLED

Project tutorial by javier muñoz sáez

  • 22,053 views
  • 22 comments
  • 65 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 2,811 views
  • 0 comments
  • 15 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 5,698 views
  • 4 comments
  • 19 respects

DIY Distance Meter with Arduino and a Nokia 5110 Display

Project tutorial by Nick Koumaris

  • 6,382 views
  • 0 comments
  • 16 respects
Add projectSign up / Login