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
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
Post a Comment