shhavel
Published © GPL3+

Measuring Tape Prototype

A device for measuring length, which performs keyboard input of the received number.

BeginnerProtip1,004
Measuring Tape Prototype

Things used in this project

Hardware components

Arduino Leonardo
Arduino Leonardo
×1
Breadboard (generic)
Breadboard (generic)
×1
SparkFun SoftPot Membrane Potentiometer - 500mm
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Capacitor 100 nF
Capacitor 100 nF
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

measuring_tape_v0_6XmwFsjdde.png

Code

Untitled file

Arduino
// Length measurement using a soft potentiometer.
// Keyboard input of the received length (value in inches).
#include <Keyboard.h>

#define BUTTON_PIN 7
#define TAPE_PIN A0      // Pin connected to softpot wiper
#define TAPE_LENGTH 200  // Softpot length in tenths (1 tenth = 1/10 inch)

void setup() {
  pinMode(BUTTON_PIN, INPUT);
  pinMode(TAPE_PIN, INPUT);
  Serial.begin(9600); // debug
  Keyboard.begin();
}

void loop() {
  if (digitalRead(BUTTON_PIN) == HIGH) { // if the button is pressed
    int x = analogRead(TAPE_PIN);        // Read the value from the sensor (0-1023)

    if (x > 0) {
      float d = map(x, 0, 1023, 0, TAPE_LENGTH); // Map the 0-1023 value to 0-TAPE_LENGTH
      float l = d / 10;  // Convert length to inches

      Serial.println("measured length: " + String(l) + " inches"); // debug

      Keyboard.print(l); // Input value
    }
    delay(500);
  }
}

Credits

shhavel
1 project • 3 followers

Comments