/ImprovedDistanceMeter

Example implementation of sound speed calibration based on the relationship with ambient temperature for the HC-SR04 ultrasonic distance sensor using Arduino.

Primary LanguageC++

Improved Distance Meter

Improved Distance Meter is a distance meter for Arduino using HC-SR04, DHT11 sensors and an LCD screen. The improved thing is the calculation of sound speed which is used to get distance.

Calculation of distance

Common usage of HC-SR04 when calculating distance is like:

float distance = (duration/2) / 29.1;

The important thing here is the 29.1 value. It is the sound speed in microseconds/centimeter format. But the temperature of the environment affects that value. So to get distance with more accuracy, we need to change this value according to temperature of the environment.

So, to calculate this value, the code simply solves the following equation.


And then turns it into microseconds/centimeter format to be used in the calculation of distance. Simply gets more accuracy by doing this.

Scheme

About LCD and I2C

The used I2C LCD library may not be compatible with your LCD. Try the following before changing the library.

  • Change the values 16, 2 in LiquidCrystal_I2C lcd(0x27, 16, 2); to row and column count of your LCD screen.

  • Try to change value 0x27 in LiquidCrystal_I2C lcd(0x27, 16, 2); to 0x3F.