Hello everyone,I am newbie in Programming.I trying to develop code for my needs.I need to read two analog sensors(Pressure,Temp) and monitor values via Serial Plotter,manage to connect two sensor readings at same plot,but need to calibrate temp sensor to show correct temp.
I use temp sensor wich can measure temp from 0-150C,sensor resistance 25C=221R, 50*C=245R,temp sensor supply 5V trought 250R. Also if possible to scale Y axis to see much clear graph beacuse need pressure from 0-4bar.
Picture show room temp. then heat with flame
Thanks in advance,for help
int input = A1; //connected to analog pin A0
int output;
int led = 2;
double temperature;
void setup() {
Serial.begin(9600); // Communication speed
pinMode(13, OUTPUT);
}
void loop() {
output = analogRead(input);
temperature = thermistor(output);
Serial.print("Raw output: "); Serial.print(output);
Serial.print(" Temperature, C: "); Serial.println(temperature);
if (temperature > 30) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
int sensorVal = analogRead(A0);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
float voltage = (sensorVal * 5.0) / 1024.0;
Serial.print("Volts: ");
Serial.print(voltage);
float pressure_pascal = (3.0 * ((float)voltage - 0.62)) * 1000000.0;
float pressure_bar = pressure_pascal / 10e5;
Serial.print("Pressure = ");
Serial.print(pressure_bar);
Serial.println(" bars");
Serial.print("Pressure = ");
delay(1000); // Slow down the output for easier reading
}
double thermistor(int RawADC) { //Function to perform the fancy math of the Steinhart-Hart equation
double temperature;
temperature = log(((10240000 / RawADC) - 10000));
temperature = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temperature * temperature )) * temperature );
temperature = temperature - 273.15; // Convert Kelvin to Celsius
//temperature = (temperature * 9.0)/ 5.0 + 32.0; // Celsius to Fahrenheit - comment out this line if you need Celsius
return temperature;
}
You can put the sensor in boiling water to get a reading on the high end value (212F) you can put the sensor in ice water (32F) to get the low reading value, and then you can use those values to define your sensors curve.
245ohm@50C sounds like a car oil/water temp sensor (thermistor).
If so, then returned A/D values are not linear with temp, so just calibrating at 0C and 100C won't work.
Might have to use a Steinhart-Hart equation.
Can't see your code. Please post according to the forum guidelines.
Leo..
(50-25)/(2.47-2.35) = (T-25)/(V-2.35)
==> T = 208.3*V - 464.58
Codes:
analogReferece(INTERNAL); //1.1V
float T = 208.33*(1.1/1023)*analogRead(sensorPin) - 464.58;
Serial.print(T, 2); //T is in degree centigrade with 2-digit after decimal point
Verification: (1) Put the sensor in a beaker of normal water. Check the reading -- should be close to 400C. (2) Put the sensor in a beaker of boiling water. Check the reading -- should be close to 1000C.