jegatheesan
Published © GPL3+

BT Portable Measuring Tape

We are in a object oriented programming, so use a single project for multiple purpose is the theme here.

IntermediateFull instructions provided708
BT Portable Measuring Tape

Things used in this project

Hardware components

ultrasonic distance sensor
×1
serial 16 X 2 LCD Display
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

Ultra_distance.ino

Arduino
#include <LBT.h>
#include <LBTServer.h>
int trigPin = 7;
int echoPin = 8;
int distance=0;
int prevdistance=0;
int duration;
String Display2;
String Distancestr;
void setup()
{
 if(!LBTServer.begin((uint8_t*)"Sivam_LIO"))
 {
 return;
 }
  Serial1.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(115200);
  
  Serial1.write(22);
  Serial1.write(12);  
  lcddisplay();
}

void loop()
{
 uint8_t buf[1];
 int bytesRead;
 if(LBTServer.connected())
 {
    distancecal();
  if (prevdistance != distance)
  {
//     Distancestr="Distance ";
//     Distancestr=Distancestr+distance;
//     Distancestr=distance+"cm";    
     LBTServer.print(distance);            
     LBTServer.print("cm");                 
     delay(100);                
    prevdistance = distance;
    lcddisplay();
  }    
 }
 else
 {
 LBTServer.accept(1);
 }
  
  distancecal();
  if (prevdistance != distance)
  {
    prevdistance = distance;
    lcddisplay();
  }  
}

void distancecal()
{
  digitalWrite(trigPin, LOW);
  delay(1000);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  Serial.println(distance);
}

void lcddisplay(){
    Serial1.write(128);
    Serial1.println("**Digital Tape**");    
    Serial1.write(148);    
    Display2="Distance : ";
    Display2=Display2 + distance;
    Display2=Display2 + "cm      ";
    Serial1.println(Display2);
}

Credits

jegatheesan

jegatheesan

18 projects • 67 followers
Simply A Mechatronics Lover.

Comments