Introduction: Measuring the Speed of Sound With Arduino Microcontroller and Ultrasonic Sensor

Picture of Measuring the Speed of Sound With Arduino Microcontroller and Ultrasonic Sensor

My 6 year old daughter, Samatha, demonstrates how to measure the speed of sound in air with Arduino Uno microcontroller and ultrasonic sensor.

I think this is a good project for kids to get exposed to science, engineering and maths.

Step 1: We Need

Picture of We Need

1. Arduino Uno microcontroller board

2. Ultrasonic sensor (HC - SR04)

3. Ruler

4. Jumper wires (Female/Male)

5. Some object like a small box

6. Calculator

7. Computer, Arduino software (IDE)

Step 2: Arduino Uno Microcontroller

Picture of Arduino Uno Microcontroller

The Arduino Uno is a credit card size microcontroller board.

It has the following important components:

  • Power pins
  • 14 digital I/O pins
  • 6 analog inputs
  • 16 MHz crystal oscillator
  • Reset button
  • USB connection.

We can connect it to a computer with a USB cable or battery to get started.

Arduino Uno can sense the environment by receiving input from a variety of sensors and can control LEDs, Servo motors, motors, and other actuators.

The microcontroller on the board is programmed using the Arduino software.

Please see the video to build some basic circuits with Arduino Uno microcontroller.

Step 3: a Little Bit About Ultrasonic Sensors

Picture of  a Little Bit About Ultrasonic Sensors

HC-SR04 ultrasonic modules have two transducers: one acts as a speaker (S) which converts electric pulses into sound waves and emits them with a frequency of 40000 Hz (40 kHz), the other acts as a microphone (M) to receive the ultrasonic waves that have bounced off an object (O).

The timer will start on the microcontroller when the pulse is transmitted and timer will stop when echo waves are received by the microphone. That is how we get the total time for the wave to travel from S --> O --> M.

Step 4: Now Connect Ultrasonic Sensor to the Microcontroller

Picture of Now Connect Ultrasonic Sensor to the Microcontroller

HC-SR04 Ultrasonic sensor has four pins:

Vcc: Operating Voltage pin

Trig: Signal transmitting pin

Echo: bounced off signal sensing pin

Gnd: Ground pin

Connect all these 4 pins to microcontroller board with jumper wires.

1. Connect Vcc to 5V pin

2. Gnd to ground pin

3. Trig to pin 13

4. Echo to pin 7

You can choose any digital pins on the microcontroller for connecting Trig and Echo of the ultrasonic sensor.

Step 5: Arduino Software Program (Sketch)

Picture of Arduino Software Program (Sketch)

The Arduino program basically will do the following steps:

  1. Turn on Trig pin
  2. Send out a 10 microsecond width pulse
  3. Turn off theTrig pin
  4. Print the total time of travel of the pulse on the serial monitor.

----------------------------------------------------------------

int trigPin = 13; // set pin 13 as trig pin
int echoPin = 7; // set pin 7 as echo pin
int time; 
void setup() {
  
  Serial.begin(9600);

pinMode(trigPin, OUTPUT);  // set trig pin as output, we send pulse through this 

pinMode(echoPin,INPUT);  // set echo pin as input, we detect echo through this pin
  
  }
void loop() {
 //sending 10 microsecond width pulses, frequency ~ 40KHz
 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2000);
 
digitalWrite(trigPin,HIGH); //trig pin delayMicroseconds(10);  //pulse width 10 microseconds
digitalWrite(trigPin, LOW); //trig pin off
time = pulseIn(echoPin, HIGH);  //pulseIn(), function return time in microseconds

//print time on the serial monitor
  
  Serial.print(" Time taken for the pulse to travel:  ");
  Serial.print(time);
  Serial.println(" microseconds");
  delay(2000);

}

Step 6: Experimental Setup, Procedure and Data Aquisition

Picture of Experimental Setup, Procedure and Data Aquisition

Before starting the experiment note down the room temperature, in our case it was 75 degrees F.

1. We need to put the sensor at 0 cm on the ruler

2. Put your object at any desired position on the ruler, we kept it at 5cm, so the total distance (D) is 10 centimeters.

3. Upload the program to microcontroller with USB cable.

4. open the serial monitor, and we can see the total time of travel of the pulse, write that on data sheet.

4. Move the object to 10 cm position on the scale, now the total distance is 20 cm, and write down the time from serial monitor.

5. We took data (time) for 6 trails (at different positions), if you have a longer ruler then you can take data for more data points.

Step 7: Data Analysis and Experimental Result.

Picture of Data Analysis and Experimental Result.

After noting down the total time for different distances, now we can calculate the speed of sound:

Speed of sound = Distance/Time (S=D/T)

For example:

Distance = 10 cm, Time = 289 microseconds = 289*10^-6 s

S = D/T = 10 cm / 289*10^-6 s = 0.03460207612 *10^4 m/s

S = 346.02 m/s

After calculating the speed of sound for different distances, finally take the average (sum of all speeds divided by 6).

The average S = 343.8 m/s at 75 F.

Step 8: Confirmation

Picture of Confirmation

The speed of sound in our experiment is 343.8 m/s

Speed of sound waves traveling in a medium will change based on the temperature (T) of the medium.

Speed of sound in air as a function of temperature : S = 331.4 + 0.6Tc m/s

where Tc = temperature in degrees centigrade.

Based on this formula, the accepted speed of sound at 75 F (23.88 degree Centigrade), S = 345.9 m/s

percent error = [ |accepted value - experimental value| / (accepted value) ] * 100 %

percent error = 0.6 % (pretty close)

Comments

About This Instructable

7,284views

17favorites

License:

More by Kranthi Gunthoti:How to extract your own DNA at homeMeasuring the speed of sound with Arduino microcontroller and ultrasonic sensorKitchen Physics - Measure the speed of light with chocolate!
Add instructable to: