edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
taha_vs
Published © GPL3+

Digital Meter

Measuring short distances digitally as simple as possible with the SRF05 ultrasonic sensor.

BeginnerFull instructions provided2 hours2,559
Digital Meter

Things used in this project

Hardware components

Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
SparkFun Electronics SRF05
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fritzing

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

digital meter pcb

Schematics

digital meter bread board

Code

digital meter code

Arduino
//by t.vajed

#include <LiquidCrystal.h>
int echoPin=5;
int pingPin=6;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.clear();
  delay(150);
  lcd.print("digital, meter");
  delay(2500);
  lcd.clear();
  delay(150);
  pinMode(pingPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(A0,INPUT_PULLUP);
  pinMode(A1,INPUT_PULLUP);
}

void loop() {
//srf05 works in two mode in this project, first capture
   while(digitalRead(A0)==0){
    lcd.clear();
    lcd.print("capture mode");
    delay(200);
    if(digitalRead(A1)==0){
     //srf starts working 
     digitalWrite(pingPin, 0);
     delayMicroseconds(5);
     digitalWrite(pingPin, 1);
     delayMicroseconds(5);
     digitalWrite(pingPin, 0);
     int duration=pulseIn(echoPin, HIGH);
     lcd.clear();
     lcd.print(duration/58);
     lcd.print(" cm");
     lcd.setCursor(0,1);
     lcd.print(duration/74/2);
     lcd.print(" in");
     delay(3500);
    }
  }
  //scanning mode of srf
   digitalWrite(pingPin, 0);
   delayMicroseconds(5);
   digitalWrite(pingPin, 1);
   delayMicroseconds(5);
   digitalWrite(pingPin, 0);
   int duration=pulseIn(echoPin, HIGH);
   lcd.print(duration/58);
   lcd.print(" cm");
   lcd.setCursor(0,1);
   lcd.print(duration/74/2);
   lcd.print(" in");
   delay(1000);
   lcd.clear();
}

Credits

taha_vs
3 projects • 6 followers

Comments