Project tutorial
Distance scale

Distance scale © SHL

A portable scale

  • 6 views
  • 0 comments
  • 0 respects

Apps and online services

About this project

wanted a portable scale and an accurate one too

Code

codeC/C++
const int trigPin = 2;
const int echoPin = 4;
void setup() { 
Serial.begin(9600);} 
void loop()
{
long duration, inches, cm, mm;
pinMode(trigPin, OUTPUT); 
digitalWrite(trigPin, LOW); 
delayMicroseconds(2000); 
digitalWrite(trigPin, HIGH); 
delayMicroseconds(1000); 
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT); 
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration); 
cm = microsecondsToCentimeters(duration);
mm = microsecondsToMillimeters(duration);
Serial.print(inches); 
Serial.print("in, "); 
Serial.print(cm);
Serial.print("cm, ");
Serial.print(mm);
Serial.print(" mm");
Serial.println(); 
delay(1000);
}
long microsecondsToInches(long microseconds)
{return microseconds / 74 / 2;}
long microsecondsToCentimeters(long microseconds)
{return microseconds / 29 / 2;}
long microsecondsToMillimeters(long microseconds)
{return microseconds / 2.9 / 2;}M
coding just copy itC/C++
const int trigPin = 2;
const int echoPin = 4;
void setup() { 
Serial.begin(9600);} 
void loop()
{
long duration, inches, cm, mm;
pinMode(trigPin, OUTPUT); 
digitalWrite(trigPin, LOW); 
delayMicroseconds(2000); 
digitalWrite(trigPin, HIGH); 
delayMicroseconds(1000); 
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT); 
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration); 
cm = microsecondsToCentimeters(duration);
mm = microsecondsToMillimeters(duration);
Serial.print(inches); 
Serial.print("in, "); 
Serial.print(cm);
Serial.print("cm, ");
Serial.print(mm);
Serial.print(" mm");
Serial.println(); 
delay(1000);
}
long microsecondsToInches(long microseconds)
{return microseconds / 74 / 2;}
long microsecondsToCentimeters(long microseconds)
{return microseconds / 29 / 2;}
long microsecondsToMillimeters(long microseconds)
{return microseconds / 2.9 / 2;}M

Schematics

distance meter digram
Screen shot 2018 02 16 at 4 masvqzlcmm euzytwba8u

Comments

Similar projects you might like

Distance Sensor and OLED

Project tutorial by javier muñoz sáez

  • 22,196 views
  • 22 comments
  • 65 respects

DIY Distance Meter with Arduino and a Nokia 5110 Display

Project tutorial by Nick Koumaris

  • 6,398 views
  • 0 comments
  • 17 respects

Distance Alarm System

Project tutorial by Darwin Dela Cruz

  • 3,433 views
  • 3 comments
  • 17 respects

Measure Distance With Sonic Ranger And Record It On MicroSD

Project tutorial by Boian Mitov

  • 2,616 views
  • 0 comments
  • 20 respects

A Cool Scale

Project tutorial by Arduino_Scuola

  • 2,459 views
  • 0 comments
  • 0 respects

Weigh Objects with an Arduino Scale

Project showcase by Team Arduinotronics

  • 71,148 views
  • 22 comments
  • 36 respects
Add projectSign up / Login