0% found this document useful (0 votes)
30 views5 pages

Experiment 31

The document describes an experiment interfacing an ultrasonic sensor with an Arduino board. It involves displaying the distance measurements from the ultrasonic sensor on the serial monitor and an LCD display. The document provides details on the components used, wiring diagram, code explanation and outputs the distance in centimeters on both the serial monitor and LCD display.

Uploaded by

369.gpc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Experiment 31

The document describes an experiment interfacing an ultrasonic sensor with an Arduino board. It involves displaying the distance measurements from the ultrasonic sensor on the serial monitor and an LCD display. The document provides details on the components used, wiring diagram, code explanation and outputs the distance in centimeters on both the serial monitor and LCD display.

Uploaded by

369.gpc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment 3

Aim: Interface Ultrasonic sensor with Arduino and display the result on serial monitor and
LCD display.
Apparatus Required: Arduino uno board, Ultrasonic sensor, serial monitor, LCD display,
Proteus software package, Arduino software, jumper wires, resistor, Breadboard.
Serial Monitor:
Arduino uno board has one serial port at digital pins 0(RX) and 1(TX) to communicate with
other external serial devices or with computer through USB cable. The process of sending and
receiving data can be observed by flashing of TX and RX LEDs on the Arduino board.
Functions Used for Serial Communication
Serial.begin (baud rate)
This function is used to initiate the serial communication with baud rate.
e.g. Serial.begin(9600)
Serial.print (data, format type (optional))
It sends ASCII character on serial port so human can read it easily. This function converts the data to
ascii character and then send (print) it.
e.g. Serial.print (123);
Serial.print (“123”);
Serial.print (12, HEX)
Serial.write()
This function writes binary data to the serial port. It returns number of byte written.
e.g. Serial.write (65); // it writes actual byte to serial port
Serial.read()
This function is used to read data serially.
e.g. received_data = Serial.read()
Serial port Interfacing:

void setup()

Serial.begin(9600);

void loop()
{

Serial.println("SENSORS FOR IOT");

delay(1000);

Ultrasonic Sensor:
An ultrasonic sensor is an electronic device that measures the distance of a target object by emitting
ultrasonic sound waves, and converts the reflected sound into an electrical signal.

It consists of two main parts transmitter and receiver. Ultrasonic sensors emit a chirp usually between
23 kHz and 40 kHz, much higher than the typical audible range of human hearing at 20 kHz, hence the
term ultrasonic. Using this chirp, they measure the amount of time it takes for the sound to bounce
off an object. This is based on the same basic principles of echolocation used by bats to find their prey.
As the speed of sound in air at room temperature is 343 meters per second, that time can be easily
converted to distance, remembering that the ultrasonic chirp travels both to and from the object being
sensed.

Distance (meters) = (time elapsed [seconds] * 343 [meters/second]) / 2

Interfacing of Ultrasonics Sensor:

Schematic diagram
Sketch:
#include <LiquidCrystal.h>
//#include <SoftwareSerial.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //LCD : (rs, enable, d4, d5, d6, d7)
//SoftwareSerial mySerial(2, 3); // RX, TX

const int trigPin = 12; // Trigger Pin of Ultrasonic Sensor


const int echoPin = 11; // Echo Pin of Ultrasonic Sensor

void setup()
{
Serial.begin(9600); // Starting Serial Terminal
//mySerial.begin(9600);

lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.setCursor(0,0);
lcd.print(" Distance ");
Serial.print(" Distance ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
Serial.print(" Measurement ");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Made By : ");
delay(1000);
Serial.print("Made By :");
lcd.setCursor(0,0);
lcd.print("OverAllTechnical");
lcd.setCursor(0,1);
lcd.print("Gyan");

Serial.print(" OverAll Technical Gyan");


delay(2000);
lcd.clear();

void loop()
{
long duration, inches, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

// Serial.print(inches);
// Serial.print("in, ");

Serial.print("Distance:");
Serial.print(cm);
Serial.print("cm");
delay(100);
Serial.println();
lcd.setCursor(0,0);
lcd.print("");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance:");
lcd.print(cm);
lcd.print("cm");
delay(100);
// mySerial.println(cm);
// mySerial.println("cm");
// mySerial.println();
//
// delay(100);
}

long microsecondsToInches(long microseconds)


{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{

return microseconds / 29 / 2;

Conclusion : Distance is successfully displayed on LCD display and serial monitor.

You might also like