📏 Digital Measuring Wheel
Measure long distances by rolling a wheel with a rotary encoder.
Overview
A rotary encoder translates rotational movement into digital pulses. By attaching a wheel of a known circumference to the encoder, we can calculate exact distance rolled by counting the pulses.
What you'll learn: Hardware interrupts, quadrature encoder reading, and circumference math.
Estimated time: 3-4 hours. Difficulty: ⭐⭐⭐ Intermediate.
Components Needed
| Component | Specification | Qty | Notes |
|---|---|---|---|
| Arduino Nano | 5V | 1 | |
| Rotary Encoder | Optical or Mechanical | 1 | Optical is more accurate |
| 16x2 LCD | I2C Interface | 1 | Display output |
| Wheel | Custom/Toy | 1 | Known diameter |
Step-by-Step Tutorial
1
Measure the Wheel
Accurately measure the diameter of your wheel in cm. Calculate circumference (C = π * d).
2
Determine PPR
Check your encoder's Pulses Per Revolution (PPR). Distance per pulse = C / PPR.
3
Wire Interrupts
Connect Encoder Pin A to Arduino Pin 2, Pin B to Pin 3 (Interrupt pins).
4
Write ISR
Use an Interrupt Service Routine (ISR) to increment a counter every time Pin A pulses, checking Pin B to determine direction.
Mechanical encoders "bounce" rapidly when spinning. You must implement hardware debouncing (capacitors) or software debouncing, or use an optical encoder which has clean signals.
Code / Configuration
measuring_wheel.ino
INO
// Digital Measuring Wheel
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int encA = 2;
const int encB = 3;
volatile long pulseCount = 0;
// E.g., Wheel diameter = 6.5cm, Circumference = 20.42cm
// Encoder = 400 pulses per rev
const float cmPerPulse = 20.42 / 400.0;
void setup() {
pinMode(encA, INPUT_PULLUP);
pinMode(encB, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(encA), updateEncoder, RISING);
lcd.init(); lcd.backlight();
}
void loop() {
float distance = pulseCount * cmPerPulse;
Reviews & Ratings
—0 reviews
Sign in to leave a review
Loading reviews...