Introduction

Looking for a simple yet impressive Arduino project that is both beginner-friendly and practical? This Arduino-based Smart Distance Scale uses an HCSR-04 ultrasonic sensor, an OLED 0.96 inch display, and the compact Arduino Nano to measure and visually represent distances with accuracy and style.

But wait - what if you want to turn your hobby project into a market ready prototype or even a polished product? Stick around! We're also featuring JUSTWAY, your go-to partner for rapid prototyping and on-demand manufacturing. Learn how to transform your DIY builds into production-grade hardware.

Let's dive in!

What This Project Does

This project lets you:

Components Required

Taking You Project Further - with JUSTWAY

So you've built a working prototype. It's functional and cool. But what if you want to:

This is where JUSTWAY steps in - your ultimate rapid prototype and on-demand manufacturing partner.

What is JUSTWAY?

JUSTWAY empowers innovators by transforming 3D models and designs into marker-ready prototypes and end-use parts, offering:

Rapid Prototyping Services

Turn you concept into reality - fast!

Mass Production Support

When you're ready to scale up!

JUSTWAY's Manufacturing Capabilities

How To Order from JUSTWAY in 4 Easy Steps

Step1: Upload Your Design

Step2: Select Material & Finish

Step3: Preview Live Model

Step 4: Confirm & Place Your Order

Pro Tip: Want to show off your electronics inside? Choose transparent resin. Want a market ready black matte enclosure? They have that too !

Circuit Diagram & Connections

Ultrasonic Sensor - Arduino Nano

OLED Display (SH1106) - Arduino Nano

Arduino Code Explanation

// Ultrasonic → SH110x OLED (I2C) Demo
// Works with SH1106/SH1107 128x64 modules using Adafruit SH110X + GFX

#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Wire.h>

// ===== OLED CONFIG =====
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C          // Common: 0x3C (sometimes 0x3D)

// For SH1106 (most 128x64 I2C modules):
Adafruit_SH1106G display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// If your panel is SH1107, use:
// Adafruit_SH1107 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);

// ===== ULTRASONIC CONFIG =====
// HC-SR04 pins
const int PIN_TRIG = 9;
const int PIN_ECHO = 10;

// Measurement params
const unsigned long ECHO_TIMEOUT_US = 30000UL;  // ~5m max (sound one-way ~0.0343 cm/us)
const uint8_t SAMPLES = 5;                      // simple moving average

// ===== HELPERS =====
float measureDistanceCm() {
  // Trigger a 10 µs pulse
  digitalWrite(PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);

  // Read echo pulse width
  unsigned long duration = pulseIn(PIN_ECHO, HIGH, ECHO_TIMEOUT_US);
  if (duration == 0) return NAN; // timeout/no object

  // distance = (duration_us * speed_of_sound_cm_per_us) / 2
  // speed of sound ≈ 0.0343 cm/us at ~20°C
  return (duration * 0.0343f) / 2.0f;
}

float cmToIn(float cm) {
  return cm * 0.393700787f;
}

float avgDistanceCm(uint8_t n = SAMPLES) {
  float sum = 0;
  uint8_t good = 0;
  for (uint8_t i = 0; i < n; i++) {
    float d = measureDistanceCm();
    if (!isnan(d)) { sum += d; good++; }
    delay(20);
  }
  if (good == 0) return NAN;
  return sum / good;
}

// Draws a horizontal bar (0–maxVal) across the width
void drawBar(float value, float maxVal) {
  if (isnan(value) || maxVal <= 0) return;
  int w = map((int)(value * 100), 0, (int)(maxVal * 100), 0, SCREEN_WIDTH - 4);
  w = constrain(w, 0, SCREEN_WIDTH - 4);
  // outline
  display.drawRect(2, 48, SCREEN_WIDTH - 4, 12, SH110X_WHITE);
  // fill
  if (w > 0) display.fillRect(3, 49, w, 10, SH110X_WHITE);
}

void setup() {
  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);

  Wire.begin();
  // For some boards, you may need Wire.setClock(400000);

  display.begin(OLED_ADDR, true);  // true = reset
  display.clearDisplay();

  display.setTextColor(SH110X_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println(F("SH110x Ultrasonic"));
  display.println(F("Initializing..."));
  display.display();
  delay(800);
}

void loop() {
  float cm = avgDistanceCm();
  float in_ = cmToIn(cm);

  display.clearDisplay();

  // Title
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print(F("Ultrasonic Distance"));

  if (isnan(cm)) {
    display.setCursor(0, 20);
    display.setTextSize(2);
    display.println(F("No echo"));
    display.setTextSize(1);
    display.setCursor(0, 40);
    display.println(F("Check wiring/aim"));
  } else {
    // Big number (cm)
    display.setTextSize(2);
    display.setCursor(0, 18);
    display.print(cm, 1);
    display.print(F(" cm"));

    // Smaller line (inches)
    display.setTextSize(1);
    display.setCursor(0, 40);
    display.print(in_, 2);
    display.println(F(" in"));

    // Bar graph up to a chosen max (e.g., 200 cm)
    drawBar(cm, 200.0f);
  }

  display.display();
  delay(120);
}

The sketch does the following:

Key Features in the Code:

Why This Project is Useful

This Arduino Smart scale isn't just a "cool build." It's:

With an enclosure from JUSTWAY, it becomes a polished, presentable product ready for showrooms or startup demos.

Video Demonstration

Conclusion

With just a few components, you've built a real-time smart scale that not only teaches core Arduino concepts but also has real-world applications. And thanks to JUSTWAY, your hobby projects can scale up beautifully - from garage builds to professional products.