📜 ⬆️ ⬇️

Inertial measurement of air temperature by ultrasound


Hi, Habr.

I like non-standard solutions. Now I will show you how to measure air temperature using ultrasound.

The scheme to the disgrace is simple - take the Arduino (I took the Nano) and connect the ultrasonic range finder to it (pin 2 - Echo, pin 4 - Trig). I used US-020, as it is more long-range and gives more stable readings than HC-SR04.


')
Fill the sketch with:
#define Trig 4
#define Echo 2

#define Steps

static const float defDist = 173.2; // cm
static const float defTemp = 17.0; // Celsius

void setup ()
{
pinMode (Trig, OUTPUT);
pinMode (Echo, INPUT);
Serial.begin (57600);
}
unsigned long impulseTime = 0;

void loop ()
{
float dist = 0;
for (int i = 0; i <50; i ++)
{
float distance_sm = 0;
digitalWrite (Trig, HIGH);
delayMicroseconds (10);
digitalWrite (Trig, LOW);
impulseTime = pulseIn (Echo, HIGH);

distance_sm = float (impulseTime) /58.0;
dist + = distance_sm;
delay (50);
}
dist / = 50.0;
Serial.println ("Distance:" + String (dist));
float Speed_of_sound = defDist / dist * sqrt (1.4 * 287.0 * (273.15 + defTemp)); // c = sqrt (X * R * T)
Serial.println ("Temp:" + String ((Speed_of_sound * Speed_of_sound) / (1.4 * 287.0) - 273.15)); // T = (c * c) / (X * R) in Kelvin
}

We place an ultrasound sonar in the direction of an obstacle at a distance of about two or three meters (less - worse accuracy, more - the sonar may not catch the echo) and fix it reliably. I have it from the table to the ceiling. We start, we look a distance in the monitor of a serial port. Rule the sketch - replace defDist and defTemp with your distance and current temperature readings. Starting temperature will have to measure, or point to the eye (like me). Again, flashing.

Everything, in the port monitor, we look at the temperature of the air volume between the sensor and the obstacle:



And now the explanation of "street magic". According to the physics textbooks:
The speed of sound in gases depends only on temperature and does not depend on gas pressure.

And this dependence is expressed by the formula:
c = sqrt (X * R * T), where:
- sound speed, m / s
X - adiabatic index
R - gas constant, j / kg · K

Measuring the response time of the sonar and comparing it with the default one, you can easily calculate the speed of sound. And knowing the speed is just as easy to calculate the temperature. For greater accuracy, we average the sensor readings over 50 measurements.

There is no inertial thermal element in the system, which needs time for heating or cooling to ambient temperature. Therefore, the inertia of measurement is completely absent - if you ventilate the room, the readings change very rapidly. Accuracy is certainly not so hot - about 0.5 degrees, but it is not a template.

Source: https://habr.com/ru/post/243357/


All Articles