Skip to main content

ARDUINO ULTRASONIC SENSOR TUTORIAL WITH CODE


ULTRASONIC SENSOR TUTORIAL



This is Arduino based tutorial for ultrasonic sensor. in this video, I described how to connect ultrasonic sensor with Arduino also interface LCD with this.



Component required for tutorial

(1) Arduino microcontroller

(2) Ultrasonic sensor

(3) LCD



ciruit diagram is given in video.



Arduino Code for tutorial:



Ultrasonic sensor tutorial by IGENTECH



#include<LiquidCrystal.h> // include header file of lcd

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //assign pins of lcd

const int trigPin = 8; // assign trig pin to 8

const int echoPin = 7; // assign echo pin to 7

// defines variables

long duration;

int distance;





void setup()

{

  lcd.begin(16,2); // begin lcd

  lcd.print("UltrasonicSensor"); // print ultrasonic sensor on lcd

  lcd.setCursor(0,2);            // set cursor to second row of lcd

  lcd.print("   IGENTECH      "); // print igentech to second row

  delay(2000);



pinMode(trigPin, OUTPUT); // set trig pin as a output

pinMode(echoPin, INPUT);  // set echopin as input pin

}



void loop() {

lcd.clear(); // clear lcd screen

// clear trig

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); // trig high to get a wave for 10 microsecond

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); // estimate duration of pulse high

distance= duration*0.034/2;   // calculate distance from duration

// print output in lcd

lcd.print("Distance in cm:");

lcd.setCursor(0,2);

lcd.print(distance);

delay(200);

}



This is Arduino based tutorial for ultrasonic sensor. in this video, I described how to connect ultrasonic sensor with Arduino also interface LCD with this.



Component required for tutorial

(1) Arduino microcontroller

(2) Ultrasonic sensor

(3) LCD



ciruit diagram is given in video.



Arduino Code for tutorial:



Ultrasonic sensor tutorial by IGENTECH



#include<LiquidCrystal.h> // include header file of lcd

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //assign pins of lcd

const int trigPin = 8; // assign trig pin to 8

const int echoPin = 7; // assign echo pin to 7

// defines variables

long duration;

int distance;





void setup()

{

  lcd.begin(16,2); // begin lcd

  lcd.print("UltrasonicSensor"); // print ultrasonic sensor on lcd

  lcd.setCursor(0,2);            // set cursor to second row of lcd

  lcd.print("   IGENTECH      "); // print igentech to second row

  delay(2000);



pinMode(trigPin, OUTPUT); // set trig pin as a output

pinMode(echoPin, INPUT);  // set echopin as input pin

}



void loop() {

lcd.clear(); // clear lcd screen

// clear trig

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); // trig high to get a wave for 10 microsecond

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); // estimate duration of pulse high

distance= duration*0.034/2;   // calculate distance from duration

// print output in lcd

lcd.print("Distance in cm:");

lcd.setCursor(0,2);

lcd.print(distance);

delay(200);

}
  
Power77 Tech Electronic Project  
Project Components Shoping Link :


 

Comments

Popular posts from this blog

Arduino NANO 3X3X3 LED CUBE

DIY | 3X3X3 LED CUBE FOR ARDUINO NANO+ By   RGBFreak   in   Technology Arduino 17,143 146 22 Featured Download Favorite By   RGBFreak RGBFreak's YouTube Channel Follow More by the author: About: Hi there visitor! First of all thank you for checking out my profile! My name is Youri. I study Technical Computer Science in the Netherlands. I especially love the electronical part of my study. Since I l...   More About RGBFreak » Intro: DIY | 3x3x3 LED Cube for Arduino Nano+ Hi everyone! My name is RGBFreak and I created a YouTube channel quite recently. I love DIY and I especially love LED's, so that's why I decided to make my own 3x3x3 LED Cube! You will need the following items to make this LED Cube: • 27 single colored LED's. • Arduino Nano or one of his bigger brothers. • 3 NPN Transistors. I used the BC547. • 3 pin headers with 3 pins. • 1 pin header with 4 pins. • A piece of perfboard. • A few small cables. Ad

DIGITAL UV-METER, WITH OLED DISPLAY. ARDUINO PROJECT FOR BEGINNERS

DIGITAL UV-METER, WITH OLED DISPLAY. ARDUINO PROJECT FOR BEGINNERS By   techn0man1ac   in   Technology Arduino 4,792 87 13 Featured Download Favorite By   techn0man1ac Techn0man1ac blog Follow About: Techn0man1ac - техноманьяк   More About techn0man1ac » Intro: Digital UV-meter, With OLED Display. Arduino Project for Beginners Video demonstration (English subtitles). Hello,   instructable . Today I will tell you how to make a simple digital VU meter (sound level meter) using Arduino and OLED displays and 2 resistors by yourself (DIY). The device is quite simple, for beginners it will be a rewarding experience. Add Tip Ask Question Comment Download Step 1: Components for This Arduino Project: 3 More Images Arduino Nano V3.0; 0.96 inch IIC I2C 128X64 OLED Display; One 10K, resistor(R1 no scheme); One 10K-100K potentiometer(R2no scheme); Wires. Add Tip Ask Question Comment Download Step 2: Dev

Ultrasonic Distance Sensor in Arduino With Tinkercad

  Ultrasonic Distance Sensor in Arduino With Tinkercad Let's measure distances with an ultrasonic rangefinder (distance sensor) and Arduino's digital input. We'll connect up a circuit using a breadboard and use some simple Arduino code to control a single LED. You may have already learned to   read a pushbutton   and   PIR motion sensor   with Arduino's digital input, and we'll build on those skills in this lesson. Ultrasonic rangefinders use sound waves to bounce off objects in front of them, much like bats using echolocation to sense their environment. The proximity sensor sends out a signal and measures how long it takes to return. The Arduino program receives this information and calculates the distance between the sensor and object. Find this circuit on Tinkercad Explore the sample circuit embedded here by starting the simulation and clicking on the proximity sensor. This will activate a highlighted area in front of the sensor with a circle "