What is 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. Ultrasonic waves travel faster than the speed of audible sound (the sound that humans can hear). Ultrasonic sensors have two main components: the transmitter (which emits the sound using piezoelectric crystals) and the receiver (which encounters the sound after it has travelled to and from the target).
What is 16×2 LCD I2c?
This is a 16×2 LCD display screen with I2C interface. It is able to display 16×2 characters on 2 lines, white characters on blue background. Usually, Arduino LCD display projects will run out of pin resources easily, especially with Arduino Uno. And it is also very complicated with the wire soldering and connection. This I2C 16×2 Arduino LCD Screen is using an I2C communication interface. It means it only needs 4 pins for the LCD display: VCC, GND, SDA, SCL. It will save at least 4 digital/analog pins on Arduino. All connectors are standard XH2.54 (Breadboard type). You can connect with the jumper wire directly.
What are Jumper Wires?
Jumper Wires are simply wires that have connector pins at each end, allowing them to be used to connect two points to each other without soldering. Jumper wires are typically used with breadboards and other prototyping tools in order to make it easy to change a circuit as needed. Fairly simple.
What is Arduino UNO?
Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with an AC-to-DC adapter or battery to get started. You can tinker with your UNO without worrying too much about doing something wrong, worst-case scenario you can replace the chip for a few dollars and start over again.
What is Breadboard?
The breadboard is the bread-and-butter of DIY electronics. Breadboards allow beginners to get acquainted with circuits without the need for soldering, and even seasoned tinkerers use breadboards as starting points for large-scale projects.
The materials and supplies we need:
1) Ultrasonic Sensor
2) 16×2 LCD I2c
3) Jumper wires (generic)
4) Arduino UNO
5) Breadboard(generic)
Procedure:
In this project, we have used an HCSR-04 to determine the distance of an obstacle from the sensor. The basic principle of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in the environment then waves are returned back to the origin as ECHO after striking on the obstacle. So, we only need to calculate the traveling time of both sounds means outgoing time and returning time to origin after striking on the obstacle. As the speed of the sound is known to us, after some calculation we can calculate the distance.
Working of Ultrasonic Sensor:
• The high-level signal is sent to 10 microseconds using Trigger.
• The module sends 40 KHz signals automatically and then detects whether the pulse
is received or not through Echo.
• If the signal is received, then it is through the high level. The time of high duration is
the time gap between sending and receiving the signal is calculated.
Distance measurement using ultrasonic sensor and Arduino Uno code:
Download the i2c LCD library
Arduino Code:
/*
* Hello Friends Welcome To "`Robotry BD"
* Here is the code for Distance Measurement with Arduino Ultrasonic Sensor...
*/
#include //LCD i2c library
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); // from this and
above are LCD i2c stuff
const int trigPin = 8; //pins of the module and where they are wired
const int echoPin = 9;
long duration; //variables needed for measuring
float distanceCm;
void setup() {
lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
lcd.clear(); //I add this function so solve that problem of "cmcm"
digitalWrite(trigPin, LOW); //setting the trigger pin on low
delayMicroseconds(2); //delay is usually in milliseconds but here we are on µs
digitalWrite(trigPin, HIGH);//emitting the ultrasounds
delayMicroseconds(10); //duration of emission
digitalWrite(trigPin, LOW); //turning off the emitter
duration = pulseIn(echoPin, HIGH); //measuring the duration pulseIn function measure the time
between the echo pin getting on high and the getting on low
distanceCm= duration*0.034/2;
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.setCursor(0,1);
lcd.print(distanceCm);
lcd.print(" cm");
delay(1000);
}
Copy