Projects / Hinge angle gauge

Hinge angle gauge

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the pot

    Outer legs to 5V and GND, wiper to A0.

  2. NANO

    Wire the button

    D2 to GND.

  3. NANO

    Wire the display

    SDA to A4, SCL to A5, with 5V and GND.

  4. NANO

    Mount the pot

    Shaft coupled to the moving part.

  5. NANO

    Upload and calibrate

    Set 0 degrees and press, then 90 and press.

  6. NANO

    Move the hinge

    The angle follows.

  7. NANO

    Check against a protractor

    Test at 45 degrees.

  8. NANO

    Clear the maximum

    Press the button in run mode.

In short

How do you build a hinge angle gauge?

A pot on a hinge or lever arm measures the angle and shows it on a display, handy for lids, flaps and pivoting arms. You need Arduino Nano, Potentiometer 10 kΩ, SSD1306 OLED Display, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Pot outer legsNano 5V and GNDPot across the supply
Pot wiper (middle)Nano A0Angle signal
Calibration buttonNano D2 and GNDPress at each of the two known angles
OLED SDANano A4I2C data
OLED SCLNano A5I2C clock
OLED VCC and GNDNano 5V and GNDPower (check your OLED accepts 5 V)

Code

A potentiometer is a position sensor: turn its shaft and the voltage on the middle pin moves in proportion to the angle, so it can measure how far a hinge or a lever has swung. The analog input reads that voltage as a number from 0 to 1023, and a two-point calibration turns the number into degrees: you hold the hinge at zero degrees and press the button, then at 90 degrees and press again, and the sketch works out a straight line between the two readings. The calibration is saved in the Nano's EEPROM, so it survives a power cut. The reading is the average of eight samples, which smooths the small noise on the analog input. A press in run mode clears the maximum angle, which is useful for checking how far a lid or flap opens. A typical pot turns about 270 degrees, so it covers most hinge work, and a pot with a linear taper gives the straightest result. Fix the pot body to the fixed part and attach the shaft to the moving part with a small arm or a coupler, and make sure there is no slip, as any slack shows up as error.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int POT = A0, BTN = 2;
const byte MAGIC = 0xB7;

enum Mode { CAL_0, CAL_90, RUN };
Mode mode = CAL_0;
int raw0 = 0, raw90 = 1023;
float maxAngle = 0;
bool wasPressed = false;
unsigned long lastPress = 0, lastDraw = 0;

int readPot() {                                    // average eight reads to reduce noise
  long sum = 0;
  for (int i = 0; i < 8; i++) sum += analogRead(POT);
  return sum / 8;
}

void saveCal() {
  EEPROM.update(0, MAGIC);
  EEPROM.put(1, raw0);
  EEPROM.put(3, raw90);
}

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  if (EEPROM.read(0) == MAGIC) {                   // use the saved calibration
    EEPROM.get(1, raw0);
    EEPROM.get(3, raw90);
    mode = RUN;
  }
}

void loop() {
  int raw = readPot();
  bool pressed = (digitalRead(BTN) == LOW);
  if (pressed && !wasPressed && millis() - lastPress > 40) {
    lastPress = millis();
    if (mode == CAL_0)       { raw0 = raw;  mode = CAL_90; }
    else if (mode == CAL_90) { raw90 = raw; saveCal(); mode = RUN; maxAngle = 0; }
    else                     { maxAngle = 0; }      // in run mode a press clears the maximum
  }
  wasPressed = pressed;

  float angle = 0;
  if (raw90 != raw0) angle = 90.0 * (raw - raw0) / (float)(raw90 - raw0);
  if (mode == RUN && angle > maxAngle) maxAngle = angle;

  if (millis() - lastDraw >= 100) {
    lastDraw = millis();
    oled.clearDisplay();
    oled.setTextColor(SSD1306_WHITE);
    oled.setTextSize(1);
    oled.setCursor(0, 0);
    if (mode == CAL_0)       oled.print("Set 0 deg, press");
    else if (mode == CAL_90) oled.print("Set 90 deg, press");
    else                     oled.print("Hinge angle (deg)");
    oled.setTextSize(3);
    oled.setCursor(0, 16); oled.print(angle, 1);
    oled.setTextSize(1);
    oled.setCursor(0, 50); oled.print("Raw "); oled.print(raw);
    oled.setCursor(70, 50); oled.print("Max "); oled.print(maxAngle, 0);
    oled.display();
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
First startSet 0 deg prompt
After two pressesRun mode with a live angle
At 0 and 90 degreesReads close to 0 and 90
At 45 degreesAbout 45, within a few degrees
RebootThe calibration is kept

If it does not work

Angle goes the wrong way

Swap the outer pot legs or recalibrate.

Reading jumps

The wiper is dirty or the coupling slips.

Wrong at the ends

The pot has reached its stops, use a smaller range.

Blank screen

Check A4 and A5.

Want to recalibrate

Clear the EEPROM or change the MAGIC value in the sketch.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the hinge angle gauge?

Arduino Nano, Potentiometer 10 kΩ, SSD1306 OLED Display, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the hinge angle gauge take to build?

About 100 minutes for a beginner maker, in 8 steps.

How do I know the hinge angle gauge works?

First start: Set 0 deg prompt. After two presses: Run mode with a live angle. At 0 and 90 degrees: Reads close to 0 and 90.

Angle goes the wrong way: what should I check?

Swap the outer pot legs or recalibrate.

Reading jumps: what should I check?

The wiper is dirty or the coupling slips.

Wrong at the ends: what should I check?

The pot has reached its stops, use a smaller range.

Blank screen: what should I check?

Check A4 and A5.