Pick up a hardware variable and play in a software

0

I have a potentiometer (hardware) that generates a variable that will oscillate from 0 to 1023. I need to read this variable

void atualizaDados(){
  int valorpress;
  int valortemp;
  valortemp=analogRead(temperaturaPin);
  temperatura=valortemp/5;  
  pressao=analogRead(pressaoPin);
  for ( pressao=0; pressao>1024; pressao++) {
  //valorpress = analogRead(pressaoPin);
  //pressao=map(valorpress,0,50,0,40);
  Serial.println(pressao);  
  }
  vazao = analogRead(vazaoPin); 
}

The code you were using is this, the pressure is giving the value 0 and it is not oscillating.

    
asked by anonymous 21.07.2016 / 15:23

2 answers

1

Considering that the for ( pressao>1024 ) condition is an error typing the code here, the pressure value is being printed as 0, since after reading the Arduino, you assign the value 0 to this variable in the for loop, 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 transform the value [0.1023] 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 that I removed from an old project). The important thing here is to show how to transform a read value into an analog port into a value that makes sense for your problem (be it pressure, temperature, etc.) . You will need to read the datasheet of your sensor for the above conversion.

An excellent response over digital analog conversion ( ADC ).

    
21.07.2016 / 23:20
0

Nathalia,

I may be clouded, but I believe the error is in your for loop.

for ( pressao=0; pressao>1024; pressao++) {
  //valorpress = analogRead(pressaoPin);
  //pressao=map(valorpress,0,50,0,40);
  Serial.println(pressao);  
}

you are assigning the value 0 to the variable pressao and after that you are running for as pressao > 1024 . What never happens because the value of pressao is 0.

Maybe you were looking for this:

for ( pressao=0; pressao < 1024; pressao++) {
  //valorpress = analogRead(pressaoPin);
  //pressao=map(valorpress,0,50,0,40);
  Serial.println(pressao);  
}
    
21.07.2016 / 15:54