top of page

Lesson-07 : Introduction to the interfacing of Ultrasonic sensor with Arduino Uno

Let us first understand what is Ultrasonic sensor and why, where it is used? Then will move to interfacing part.

Ultrasonic sensor

As shown below the HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger, Echo and Ground respectively. This sensor is a very popular sensor used in many applications where measuring distance or sensing objects are required. The module has two eyes like projects in the front which forms the Ultrasonic transmitter and Receiver. The sensor works with the simple high school formula that is

Distance = Speed × Time


The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air and when it gets objected by any material it gets reflected back towards the sensor this reflected wave is observed by the Ultrasonic receiver module and distance is computed.


Interfacing Ultrasonic sensor with Arduino


Interfacing Ultrasonic sensor with Arduino
Interfacing Ultrasonic sensor with Arduino

Step by step wiring connections

  • Insert the LED into the breadboard

  • Connect the +ve rail of the breadboard to +5v of Arduino and –ve rail of the breadboard to GND of Arduino

  • Connect the +ve terminal of the LED to the digital pin 2 of Arduino

  • Connect the –ve terminal of the LED to the –ve rail through 220 Ohm.

  • Connect the VCC of the sensor to the +ve rail and Gnd of the sensor to the -ve rail

  • Connect the trigger pin of the sensor to the digital pin 8 of Arduino

  • Connect the Eco pin of the sensor to the digital pin 9 of Arduino

Code for Interfacing the Ultrasonic sensor

  1. Define the Pin Mode in the void Setup

  2. Define the logic in the void Loop

Functions used in this example:

  1. pinMode(Pin_Number, IN/OUT); to set the mode i.e. input or output for example pinMode(3,OUTPUT);

  2. digitalWrite(Pin_Number,LOW/HIGH); to set the pin as High or low for example digitalWrite(3,LOW);

  3. Serial.begin(9600); to start serial monitor

  4. delay(microseconds) to put a time delay between two instructions. For example delay(1000) i.e. 1 sec delay

  5. Serial.println(data); to print the value on the serial monitor

Register for the IoT course provided by Nation Innovation.





5 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating