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

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

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

Automatic Street Light Controller Circuit Using LDR And 555 Timer IC

Automatic Street Light Controller Circuit Using LDR And 555 Timer IC   We are living in the world where everything goes to be automatic from your washing machine to your ceiling fan. Street lights are one of those   examples   of the automatic world. Automatic street light are those light which needs no manual operation to gets turn ON and turn OFF. Did you ever try to make such kind of street lights that gets turn ON and turns OFF automatically? In this article, we are going to make automatic street light using LDR and 555 timer IC. List of Components   555 Timer IC LDR LED Potentiometer Resistor 1* 1k ohm  Resistor 1* 220 ohm 9V Battery Printed Circuit Board(PCB) Or BreadBoard  Circuit   Diagram A very simple circuit diagram of automatic street light is given below.  Automatic Street Light Controller Circuit Principle and Working of Automatic Street Light Controller 555 Timer IC is the main part of the circuit tha...