Hello,
Working on a project here, so hope somebody can help me:)
I've got a 10 Liters tank, using a HC-SR05 ultrasonic sensor to measure level, and a controller valve that operates with with 0-10vDC. The valve is placed at the outlet of the tank. The inlet is variable.
The way I calculated the liter measurement:
Y = -0,392157x + 11,1765
X = centimeter value
Y = litervalue
11,17 is what the tank can hold maximum, but then the ultrasonic would get wet. So i'm using 10 as max.
This is what my program looks like:
// Define cho and trig pin
const int echoPin = 2;
const int trigPin = 3;
//define variables
long duration; // duration of soundwave traveltime
float distance;
//Scaling CM to liters
float liter; //also works as a current value
void setup() {
//Ultrasound
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);//
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//Reads echoPin, and returns the soundwaves traveltime in microseconds
duration = pulseIn(echoPin, HIGH);
//calculation of distance
distance = duration * 0.034 / 2;
//Converting CM to liters. 2.65 cm = 1 liter.
liter = -0.3921 * distance + 11.17;
Serial.print("Distanse: ");
Serial.print(distance);
Serial.print("cm");
Serial.print( "Liter: ");
Serial.println(liter);
delay(1000);
}
My question is, how to i put this together with an PI regulator on my arduino uno?
My controlvalve is operating on 0-10vDC, 0=closed, 10= fully open.
I have a pwm to voltage converter, so that is taken care of.
Thanks.