ArrowtronElectronics Store
Free shipping over ₹999
100% genuine components
Dispatch in 1–2 days
Secure payments · UPI, Cards

Build an Ultrasonic Distance Display with Arduino & OLED

In this beginner-friendly project you will build a digital distance meter that measures how far an object is and displays the reading in real time on a crisp OLED screen.

Beginner~45 minutes5 components

What you’ll build

A compact distance meter: the Arduino Nano triggers the HC-SR04 ultrasonic sensor, calculates the distance from the echo time, and prints it to the 0.96″ OLED display, updating several times per second.

Components you’ll need

ComponentQtyPrice
Arduino Nano ATmega328P Compatible Board1₹149
HC-SR04 Ultrasonic Distance Sensor1₹89
0.96 inch OLED Display Module I2C 128×64 Blue1₹149
830 Point Solderless Breadboard Full Size1₹99
Male to Female Jumper Wires 40pcs 20cm Multicolour1₹49
Total₹535

Step-by-step guide

  1. Place the Arduino Nano on the breadboard and power the rails: connect 5V to the red rail and GND to the blue rail.
  2. Wire the HC-SR04: VCC to 5V, GND to GND, Trig to D9, and Echo to D10.
  3. Connect the OLED display over I2C: VCC to 5V, GND to GND, SDA to A4, and SCL to A5.
  4. Double-check all connections against the wiring diagram before powering up.
  5. Install the Adafruit_GFX and Adafruit_SSD1306 libraries from the Arduino Library Manager.
  6. Upload the sketch below, then open the project on the breadboard and move your hand in front of the sensor to watch the distance update live.

The code

Here is the core sketch. It reads the echo pulse, converts it to centimetres, and refreshes the OLED.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire);
const int trig = 9, echo = 10;
void setup(){ pinMode(trig,OUTPUT); pinMode(echo,INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); }
void loop(){
  digitalWrite(trig,LOW); delayMicroseconds(2);
  digitalWrite(trig,HIGH); delayMicroseconds(10); digitalWrite(trig,LOW);
  long d = pulseIn(echo,HIGH)*0.034/2;
  display.clearDisplay(); display.setTextSize(2);
  display.setCursor(0,20); display.print(d); display.print(" cm");
  display.display(); delay(200);
}

Build this project

Add all 5 required components to your cart in one click — total ₹535.

Add all components to cart
Scroll to Top