Arduino: Project 18: Building a Distance sensor

Hello everyone!! Welcome to this post on Arduino Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE

Soo this is one is a cool project. It’s a distance sensor!

Demo:

This is how my project turned out:

Things Required:

  1. Arduino UNO
  2. Jumper Wires
  3. 16×2 LCD Screen
  4. HC-SR04 Sensor
  5. 10k potentiometer
  6. Arduino IDE on computer

Reference Material:

  1. So here you can understand about the HC-SR04 sensor and the project: (LINK1) and (LINK2)

Code:

View on/ Download from Github: (LINK)

#include<LiquidCrystal.h>
int rs=7;
int en=6;
int d4=2;
int d5=3;
int d6=4;
int d7=5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int trigpin=12;
int echopin=11;
int traveltime;
int dt=25;
int distance;

void setup() {
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  Serial.begin(9600);
  lcd.begin(16,2);

}

void loop() {
  digitalWrite(trigpin, LOW);
  delayMicroseconds(dt);
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(dt);
  digitalWrite(trigpin, LOW);
  traveltime= pulseIn(echopin, HIGH);
  distance= traveltime*(0.034/2);
  delay(300);
  lcd.setCursor(0,0);
  lcd.print("Distance= ");
  lcd.print(distance);
  lcd.print(" cm");
}

Stay Tuned for upcoming posts on Arduino Projects! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

This image has an empty alt attribute; its file name is stay-tuned.gif

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close