whereas the condition of for
(pressao>1024
) is an error when typing the code here, the pressure value is being printed as 0, because you after receiving the Arduino reading, assign the value 0 for this variable in the loop for
, see:
pressao=analogRead(pressaoPin);
for (pressao=0; pressao>1024; pressao++) {}
Anyway, this loop seems unnecessary to me. If you just need to show the pressure value within the range [0.1023], just do this:
pressao=analogRead(pressaoPin);
Serial.println(pressao);
However, it is very common to want to turn the [0.1023] value into pressure, the code below is an example of how to do this (for a specific sensor):
//realiza a leitura na porta analica, o valor retornado já é o convertido pelo ADC
pressao=analogRead(pressaoPin);
//converte a leitura acima em tensão (considerando que a tensão de referencia são 5000 mv (ou 5 V).)
float tensao = (pressao * 5000.0) / 1023.0;
//transforma a tensão em pressão (kPa)
float p1 = ((((tensao - 800.0)*100000.0) / 3200.0) / 1000.0);
Note that this is for a specific sensor (code I removed from an old project). I will not go into the merit of the above constants (nor do I remember to tell you the truth), the important thing here is to show how to transform a value read in an analog port into a value that makes sense to your problem (be it pressure, temperature, etc). You will need to read your sensor datasheet for the above conversion.
An excellent response on digital analog conversion (ADC).
Only a correction in the way of seeing the thing, to facilitate its use and understanding of terminology. The potentiometer does not generate a "variable", nor does the gate generate a variable. You have a function that returns a value (so far there is no variable in the process, in the sense of programming). When you do
algumacoisa = função()
, is attributing the value returned to a variable.– Bacco