Realtime air temperature measuring added

This commit is contained in:
Mal 2020-10-25 00:07:05 +02:00
parent 5a569b3406
commit 0fe60ad13f

View File

@ -1,15 +1,42 @@
class Thermistor
{
int analogPin;
public:
Thermistor(int analogPin)
{
this->analogPin = analogPin;
pinMode(analogPin, INPUT);
}
double getDegrees()
{
double temp = log(10000.0 * (1024.0 / analogRead(this->analogPin) - 1));
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp)) * temp) - 273.15;
return temp;
}
};
Thermistor thermistor(15);
class HCSR04
{
int pinTrigger;
int pinEcho;
double soundMetresPerMillisecond = 0.343;
double getMetersPerMillisecond()
{
return (331 + 0.6 * thermistor.getDegrees()) / 1000.0;
}
public:
HCSR04(int pinTrigger, int pinEcho)
{
this->pinTrigger = pinTrigger;
this->pinEcho = pinEcho;
pinMode(this->pinTrigger, OUTPUT);
pinMode(this->pinEcho, INPUT);
}
@ -27,7 +54,7 @@ class HCSR04
double getMetres()
{
return this->getMilliseconds() * this->soundMetresPerMillisecond * 0.5;
return this->getMilliseconds() * this->getMetersPerMillisecond() * 0.5;
}
double getCentimeters()