Displaying temperature and pressure at the same time using java

wildbill: Just divide your c variable by 100000.0 before displaying it.

BTW, single letter variable names are fine when your program is twenty lines long, but it's not a good habit to get into.

Thanks a lot, really!!!

PaulS:   long a =1023 - analogRead(analogPin);   float sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;

I hope a never equals 10.

Can you explain, please? ahah

Guys, I am now with another problem. I connected now 3 sensors to the arduino mega, 2 thermistors and 1 barometer and I wanted to display the data in the same format than the previous one (value, value, value). I tried writing on the code Serial.print (", , ") but it didnt worked. Also I tried writing Serial.print (", ") one time between the sensor 1 and 2 and the other between the sensor 2 and 3 but it isnt working. Does anyone know what to do?

#include 
#include "Seeed_BMP280.h"
BMP280 bmp280;


#define analogPin A0 //the thermistor attach to 
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistor

#include 
#include                        // main hd44780 header
#include  // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip



// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{

  Serial.begin(9600);
   if(!bmp280.init())
    Serial.println("Device error!");

    
int status;

  status = lcd.begin(LCD_COLS, LCD_ROWS);
  if(status) // non zero status means it was unsuccesful
  {
    status = -status; // convert negative status value to positive number

    // begin() failed so blink error code using the onboard LED if possible
    hd44780::fatalError(status); // does not return
  }

  
}

void loop() {

  // sensor1 = thermistor number 1 ; sensor2 = thermistor number 2 ; sensor3 = barometer 
  long a =1023 - analogRead(analogPin); 
   float sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
long d = 1023 - analogRead (A7);
float sensor2 = beta /(log((1025.0 * 10 / d - 10) / 10) + beta / 298.0) - 273.0;
 float sensor3 =  bmp280.getPressure();
 Serial.print(sensor1);
 Serial.print(", ");
 Serial.println(sensor2);
 Serial.print (", ");
 Serial.println (sensor3);

  delay (500);
lcd.setCursor(0, 0);
lcd.print("Temp1:");
lcd.print(sensor1);// Print a centigrade temperature to the LCD.
lcd.print(" C");
 lcd.setCursor(0, 1);
  lcd.print("Temp2:");
  lcd.print(sensor2);
  lcd.print (" C");

This:

 Serial.println(sensor2);

Needs to change now to:

 Serial.print(sensor2);

brunopeniche: Can you explain, please? ahah

Because then you'll have a division by zero:

float sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;

neiklot: Because then you'll have a division by zero:

Yes that I understood gladly eheh :D. What I dont understood was why a could be equal to 10. I even dont know what a stands for ahah (I copied this equation for the temperature from another code on the internet)

long a =1023 - analogRead(analogPin);If analogRead returns 1013.

note to self: must check what an Arduino actually does with a runtime error like that.

wildbill: This:

 Serial.println(sensor2);

Needs to change now to:

 Serial.print(sensor2);

wow thanks!!! It worked!! So what is the difference of putting Serial.println instead of Serial.print? the "ln" kind of finishes the line where the data is displayed, with the next values being displayed in the next paragraph?

AWOL: long a =1023 - analogRead(analogPin);

If analogRead returns 1013.

So if the analog read of the thermistor gives 1013 the code will have some kind of error, right? Do you guys then think that I should change the code? Because that equation was really the best that I found to display the temperature in degrees celsius

brunopeniche: the "ln" kind of finishes the line where the data is displayed, with the next values being displayed in the next paragraph?

Yes, and more "technically" it inserts a CR carriage return (to go back to the left) and a LF line feed (to click one line ahead) into the stream sent to the monitor.

Have a Google for the ascii table, and you will see character hex 0D, or decimal 13 is the CR and 0A or 10 is the LF.

neiklot: Yes, and more "technically" it inserts a CR carriage return (to go back to the left) and a LF line feed (to click one line ahead) into the stream sent to the monitor.

Have a Google for the ascii table, and you will see character hex 0D, or decimal 13 is the CR and 0A or 10 is the LF.

Thanks!!

brunopeniche: Can you explain, please? ahah

I was seeing parentheses where I would have put them, not where you didn't put them.

You are dividing by a. If a is ever 0, you are doing A BAD THING.

You SHOULD be using parentheses to make it clear how that equation is to be evaluated.

PaulS: I was seeing parentheses where I would have put them, not where you didn't put them.

You are dividing by a. If a is ever 0, you are doing A BAD THING.

You SHOULD be using parentheses to make it clear how that equation is to be evaluated.

Ok, I have put the equation like this now:

 float sensor1 = beta /(log(((1025.0 * 10 / a) - 10) / 10) + beta / 298.0) - 273.0;

instead of:

float sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;

And it seems fine. Do you agree with that?

Do you agree with that?

No. You are still dividing by a, even if a is 0.

PaulS: No. You are still dividing by a, even if a is 0.

Oh yeah. So how you suggest me to change it? I would have to change to another equation?

So how you suggest me to change it?

if(a != 0)
{
   sensor1 = beta /(log(((1025.0 * 10 / a) - 10) / 10) + beta / 298.0) - 273.0;
}
else
{
   sensor1 = someOtherValue;
}

I have no idea what you want to use as someOtherValue, when a is 0.

PaulS: if(a != 0) {   sensor1 = beta /(log(((1025.0 * 10 / a) - 10) / 10) + beta / 298.0) - 273.0; } else {   sensor1 = someOtherValue; }

I have no idea what you want to use as someOtherValue, when a is 0.

I dont know, maybe the result of the equation when a=0.00001? Is it correct?

brunopeniche: I dont know, maybe the result of the equation when a=0.00001? Is it correct?

Since you have declared a to be an integral type, setting it to 0.000001 seems unlikely.

PaulS: Since you have declared a to be an integral type, setting it to 0.000001 seems unlikely.

sorry for not answering sooner but I was out of this project for 2 days. So what value do you recommend? I sincerely dont know ahah