Вот вариант доплеровского расходомера на 32 atmege http://avr.ru/ready/measure/mass/debet/part2
Там 3 кодаbsn писал(а): ↑02.06.2019{, 23:18}Несколько лет назад попадалась эта статья: "Ультразвуковой анемометр на одной паре датчиков" Сейчас не нашёл там скетча. Но у автора, как я понял, путь от идеи до реализации пройден.
http://blog.regimov.net/%D1%83%D0%BB%D1 ... 5-hc-sr04/
Код: Выделить всё
#include <dht.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define Trig 4
#define Echo 2
#define Trig2 8
#define Echo2 12
#define ONE_WIRE_BUS 7
#define Steps
dht DHT;
#define DHT21_PIN 0
static const float defDist = .6985; // m
static const float defDist2 = .713; // m
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup()
{
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
pinMode(Trig2, OUTPUT);
pinMode(Echo2, INPUT);
Serial.begin(57600);
// Start up the library
sensors.begin();
Serial.println("X Distance Tds18820 Tcalc Tdht Hum V");
}
unsigned long impulseTime=0;
void loop()
{
// READ DATA
//Serial.print("DHT21, \t");
int chk = DHT.read21(DHT21_PIN);
float DHTtemp = 10;
float DHThum = 50;
switch (chk)
{
case DHTLIB_OK:
// Serial.print("OK,\t");
DHTtemp =DHT.temperature;
DHThum = DHT.humidity;
break;
default:
Serial.print("DHT Error,\t");
break;
}
// DISPLAY DATA
// Serial.print(DHThum, 1);
// Serial.print(",\t");
//Serial.println(DHTtemp, 1);
sensors.requestTemperatures(); // Send the command to get temperatures DS18820
float dist = 0;
float dist2 = 0;
float temp = sensors.getTempCByIndex(0); //DHTtemp;
unsigned long impulseTime=0;
unsigned long impulseTime2=0;
int N=250;
for (int i = 0; i <N; i++) { digitalWrite(Trig, HIGH); delayMicroseconds(10); digitalWrite(Trig, LOW); impulseTime +=pulseIn(Echo, HIGH); delay(50); digitalWrite(Trig2, HIGH); delayMicroseconds(10); digitalWrite(Trig2, LOW); impulseTime2 +=pulseIn(Echo2, HIGH); delay(50); } //float P = 101325; float P = 761 * 133.3; float M = (28.95-10.934*DHT.humidity/100*(133.3*4.579*exp(17.14*temp/(235.3+temp)))/P)/1000; float R= 8.31447; float X = 1.4 * R/M ; //X = 287; float c = sqrt( X *(temp+273.15)); dist = impulseTime * c / 1e6 /N; dist2 = impulseTime2 * c / 1e6 /N; float Speed_of_sound = defDist*N/impulseTime * 1e6; float Speed_of_sound2 = defDist2*N/impulseTime2 * 1e6; float Tcalc = sq(Speed_of_sound)/X - 273.15; float v = c- Speed_of_sound; float v2 = c- Speed_of_sound2; float v3 = sqrt(sq(v) + sq(v2)); int wd = int(atan(-v/v2)*180/3.1416); if (v>0) {wd+=90;} else {wd+=270;}
//Serial.println("X Distance Tds18820 Tcalc Tdht Hum V");
//Serial.println(String(impulseTime) + char(9) + String(impulseTime2));
Serial.println(String(impulseTime) + char(9) + String(impulseTime2) + char(9) + String(dist, 5) + char(9) + String(dist2, 5) + char(9) + String(temp) + char(9) + String(Tcalc) + char(9) + String(DHTtemp)+ char(9) + String(DHThum) + char(9) + String(v) + char(9) + String(v2) + char(9) + String(v3) + char(9) + String(wd));
Код: Выделить всё
#include <dht.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define Trig 4 // HC-SR04 №1
#define Echo 2
#define Trig2 8 // HC-SR04 №2
#define Echo2 12
#define ONE_WIRE_BUS 7 // DS18B20
#define Steps
dht DHT;
#define DHT21_PIN 0 // DHT21
static const float defDist = .2121; // m
static const float defDist2 = .2121; // m
float Tcalc = 0;
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup()
{
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
pinMode(Trig2, OUTPUT);
pinMode(Echo2, INPUT);
Serial.begin(57600);
// Start up the library
sensors.begin();
Serial.println("X Distance Tds18820 Tcalc Tdht Hum V");
}
unsigned long impulseTime=0;
void loop()
{
float temp = 0;
float DHTtemp = 0;
float DHThum = 50;
// READ DHT DATA
int chk = DHT.read21(DHT21_PIN);
if (chk == DHTLIB_OK)
{
DHTtemp =DHT.temperature;
DHThum = DHT.humidity;
}
if (sensors.getDeviceCount() > 0)
{
sensors.requestTemperatures(); // Send the command to get temperatures DS18820
temp = sensors.getTempCByIndex(0); //DHTtemp;
}
float dist = 0;
float dist2 = 0;
unsigned long impulseTime=0;
unsigned long impulseTime2=0;
int N=50;
for (int i = 0; i <N; i++)
{
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
impulseTime +=pulseIn(Echo, HIGH);
delay(50);
digitalWrite(Trig2, HIGH);
delayMicroseconds(10);
digitalWrite(Trig2, LOW);
impulseTime2 +=pulseIn(Echo2, HIGH);
delay(50);
}
//float P = 101325;
float P = 761 * 133.3;
float M = (28.95-10.934*DHThum/100*(133.3*4.579*exp(17.14*Tcalc/(235.3+Tcalc)))/P)/1000; //M = 0.02895;
float R= 8.31447;
float X = 1.4 * R/M ;
Tcalc = sq((defDist+defDist2)*N/(impulseTime+impulseTime2) * 1e6)/X - 273.15;
float c = sqrt( X *(Tcalc+273.15));
dist = impulseTime * c / 1e6 /N;
dist2 = impulseTime2 * c / 1e6 /N;
float Speed_of_sound = defDist*N/impulseTime * 1e6;
float Speed_of_sound2 = defDist2*N/impulseTime2 * 1e6;
float v = (Speed_of_sound-Speed_of_sound2)/2;
//float v2 = c- Speed_of_sound2;
//float v3 = sqrt(sq(v) + sq(v2));
//int wd = int(atan(-v/v2)*180/3.1416);
//if (v>0) {wd+=90;} else {wd+=270;}
Serial.println(String(impulseTime) + char(9) + String(impulseTime2) + char(9) + String(dist, 5) + char(9) + String(dist2, 5) + char(9)
+ String(temp) + char(9) + String(Tcalc) + char(9) + String(DHTtemp)+ char(9) + String(DHThum)+ char(9) + String(M,5) + char(9) + String(v));
Надоело менять механические расходомеры из Китая.
я не знаю таких измерителей потока - задача измерять литры в минуту.
не надежная конструкция, требует воду без твердых включений -воду из речки не переносит.