For fast transaction call 0945.463.7074
Learning Sensor Kit for Arduino Tutorial Ultrasonic

Learning Sensor Kit for Arduino Tutorial Ultrasonic

This project will show us how to use the Ultrasonic Distance Sensor, its configuration, wiring and how would it work using Arduino An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. This project can be embedded in such project that requires distance measuring.

Ultrasonic Distance Measuring with Arduino UNO R3

Things you’ll need:

  • Arduino Uno R3
  • Ultrasonic Distance Sensor
  • Uno R3 Sensor shield V5.0
  • Breadboard
  • Connecting Wire

 

Mounting your Uno R3 Sensor shield V5.0 to your Arduino UNO R3. Click here.

Schematic Diagram:

 

Connections of sensor are as follows:
Vcc to Arduino 5V
Gnd to Arduino Ground
Trig to Digital I/O pin 9 (Transmitter)
Echo to Digital I/O pin 10 (Receiver)

 

Building the Code

For you to make this project work, you’ll need first to download the Arduino Software and install it in your computer. To do so, visit the Arduino Website and download the application.

Connect your Arduino Board to your computer using the Power Cable.

Open up your Arduino software and write the following code:

const int trigPin = 9;                  // assign Digital I/O pin 9 to trigPin or the transmitter
const int echoPin = 10;              // assign Digital I/O pin 10 to echoPinor the receiver
 
long duration;                           // use variable duration for as to save the received data from the sensor
int distance;                              //  use variable to save the calculated distance from the received data
void setup() {
 
pinMode(trigPin, OUTPUT);     // configure trigPin as output
pinMode(echoPin, INPUT);       // configure echoPin as input
Serial.begin(9600);
 
}
void loop() {
 
digitalWrite(trigPin, LOW);      // initialize first the sensor by setting it low
delay(50);
 
digitalWrite(trigPin, HIGH);     // activate the transmitter of the sensor
delay(50);                               
digitalWrite(trigPin, LOW);      // turns off the transmitter
 
duration = pulseIn(echoPin, HIGH);      // set the receiver on and enables the pulses from the
                                                            // transmitter to pass in the receiver
distance= duration*0.034/2;                  //calculate the distance measurement in cm
 
Serial.print("Distance: ");                      // display the distance in your Serial Monitor
Serial.println(distance);                         // and its value
 
}

Select the Board and Port you are using, in the Menu Bar select “Tools”. Select the corresponding board you are using and the designated port. Check this out on how to select board, Easy Learning Kit for Arduino Tutorial.

Upload your code.

Now, test your project by moving your hand closer to the Sensor and the distance is displayed in your serial monitor.

 

How it work:

In order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2, since the speed of sound is 340m/s or 0.034cm/us.

 

 

 

 

Now you can build your own Ultra Sonic Robot Car! Just click here.

Check out our other Sensor Tutorials below:

 

Happy Coding!


0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program