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 cable...

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 C...

TOUCH SWITCH CIRCUIT WITH MOSFET

TOUCH SWITCH CIRCUIT WITH MOSFET By  leeselectronic  in  Technology Electronics 1,326 13 Featured Download Favorite By  leeselectronic Lee's Electronic Follow More by the author: About: Electronic Hobby Store  More About leeselectronic » Intro: Touch Switch Circuit With MOSFET Created by: Jonsen Li Overview: The simple touch switch LED circuit utilizes biasing characteristics of the MOSFET. MOSFET stands for Metal-oxide-semiconductor field effect transistors. It is a voltage controlled device meaning that the current passing through the device is controlled by the voltage between two terminals. Parts you will need: A power MOSFET (IRFZ-44 NPN)  (Lee's ID: 71211) 9V battery  (Lee's ID: 83741) 12V LED bulb  (Lee's ID: 5504) Jumper wires  (Lee's ID: 21802) Breadboard  (Lee's ID: 10686) 9V battery clip  (Lee's ID: 653) Add Tip Ask Question Comm...