Project tutorial
LCD display distance of an ultrasonic sensor

LCD display distance of an ultrasonic sensor © MIT

This project displays the readings of the ultrasonic sensor on LCD of your smartphone through 1Sheeld

  • 7,244 views
  • 0 comments
  • 8 respects

Components and supplies

About this project


Code

Untitled fileArduino
#define CUSTOM_SETTINGS
#define INCLUDE_LCD_SHIELD

#include <OneSheeld.h>

const int echoPin1 = 2;
const int trigPin1 = 4;

void setup() {
  // initialize serial communication:
  OneSheeld.begin();
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  LCD.clear();
}

void loop()
{
 long duration1, distance1;

  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);

  duration1 = pulseIn(echoPin1, HIGH);
  // convert the time into a distance1
  distance1 = duration1 / 29 / 2;
  if(distance1 < 10)
  {
    LCD.setCursor(0,0);
    LCD.print(distance1);
    LCD.print("cm");
    LCD.setCursor(0,3);
    LCD.print("   ");
  }
  else if(distance1 < 100)
  {
    LCD.setCursor(0,0);
    LCD.print(distance1);
    LCD.print("cm");
    LCD.setCursor(0,4);
    LCD.print("   ");
  }
}
Codebender

Schematics

Ultrasnoic%20Distance%20Display_bb.png
Ultrasnoic%20distance%20display bb

Comments

Similar projects you might like

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 2,811 views
  • 0 comments
  • 15 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 5,696 views
  • 4 comments
  • 19 respects

Analog Clock using 1Sheeld Graphical LCD

Project tutorial by Ahmed El-Hinidy

  • 2,069 views
  • 0 comments
  • 7 respects

Soil Moisture Sensor With LCD Display

Project tutorial by Patel Darshil

  • 22,386 views
  • 6 comments
  • 39 respects

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 9,085 views
  • 1 comment
  • 17 respects
Add projectSign up / Login