Hi, I'm Vitandin I am learning to code and my main interst is arduino.
I'm trying to
use a HC-SR04 to count the volume of water contained in a bucket,
the shape of the bucket is not regular so i put liter by liter and took note,
then I made an array with this info in which the position on the array matches with the quantity of liters i did not have the sensor first, so I made an adaptation to C++ until they worked but then i adapted it to arduino I.E Serial.println insteado of cout, and it gave me this error:
invalid operands of types 'int()' and 'double' to binary 'operator>'
i first tried by converting the int number to be compared (the medir_distancia variable) into a float
but it was the same but:
invalid operands of types 'float()' and 'double' to binary 'operator>'
I did not find anything like this on google,
So I tried several things, and what """"worked"""" was cutting off the floating number I.E 77 instead of 77.7 , but it does not let me have a 1 liter precision , for example 63.7 and 63.1 are in different "liter steps" .
Could yo please give me an orientation or help me to solve this??
Thank you so much!
const byte trigg = 3;
const byte echo = 2;
float litros[] = {77.7,76.6,75.8,75.0,74.3,73.5,72.8,72.1,71.4,70.7,70.0,69.4,68.1,67.4,66.8,66.2,65.6,65.1,64.4,63.7,63.1,62.4,61.8,61.1,60.5,60.0,59.4,58.8,58.2,57.7,57.1,56.6,56.0,55.4,54.8,54.3,53.7,53.1,52.6,52.0,51.4,50.8,50.3,49.7,49.2,48.6,48.0,47.4,46.8,46.2,45.6,45,44.5,44.0,43.5,42.5};
void setup(){
Serial.begin(9600);
pinMode(trigg, OUTPUT);
pinMode(echo, INPUT);
digitalWrite(trigg,LOW);
}
void loop(){
Serial.println(mide_distancia());
int n=0;
if ( mide_distancia > 77.7){
Serial.println("VACÍo");
}
else
{
while (mide_distancia<litros[n])
{
n=n+1;
}
}
if (litros[n] < 42.5)
{
Serial.println("musho");
}
else{
Serial.println(n);
Serial.println("litros");
}
}
int mide_distancia(){
gatilla();
long tiempo = pulseIn(echo,HIGH);
int distancia = tiempo / 58;
return distancia;
}
void gatilla(){
digitalWrite(trigg,HIGH);
delayMicroseconds(10);
digitalWrite(trigg,LOW);
}
ps: sorry for my bad English