ARDUINO CODING TO DISPLAY MILIVOLTS FOR TEMPERATURE VALUES CONVERSION

Thread Starter

Nurruzaini Mnasir

Joined May 13, 2018
2
anyone can help me to check my coding regarding to my project? actually i am developing temperature sensor using fiber optic and using the Arduino as the conversion medium. what here is my coding but the temeprature display is over the range. i want only until 100 degree Celcius. the voltage range just in millivolts. By the way i am using my own device to replace LM358. the output of the device just the same as LM 358 and i am using pin A0 to connect with Arduino. below is my coding

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensor=A1; // Assigning analog pin A1 to variable 'sensor'
float temp; //variable to store temperature in degree Celsius
//float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
void setup()
{
pinMode(sensor,INPUT); // Configuring pin A1 as input
//Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
vout=analogRead(sensor);
vout=(vout*500)/1023;
temp=vout; // Storing value in Degree Celsius
//tempf=(vout*1.8)+32; // Converting to Fahrenheit

lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.setCursor(0,1);
delay(1000); //Delay of 1 second for ease of viewing in serial monitor
}
 

ebeowulf17

Joined Aug 12, 2014
2,978
anyone can help me to check my coding regarding to my project? actually i am developing temperature sensor using fiber optic and using the Arduino as the conversion medium. what here is my coding but the temeprature display is over the range. i want only until 100 degree Celcius. the voltage range just in millivolts. By the way i am using my own device to replace LM358. the output of the device just the same as LM 358 and i am using pin A0 to connect with Arduino. below is my coding

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensor=A1; // Assigning analog pin A1 to variable 'sensor'
float temp; //variable to store temperature in degree Celsius
//float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
void setup()
{
pinMode(sensor,INPUT); // Configuring pin A1 as input
//Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
vout=analogRead(sensor);
vout=(vout*500)/1023;
temp=vout; // Storing value in Degree Celsius
//tempf=(vout*1.8)+32; // Converting to Fahrenheit

lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.setCursor(0,1);
delay(1000); //Delay of 1 second for ease of viewing in serial monitor
}
I have no idea what temperature sensor you're using, or what its output characteristics are like.

If I'm reading your code correctly, it looks like it would work for a sensor that outputs 10mV/degC, with 0C at 0mV. Is that what your temperature sensor does?

What temperature sensor are you using, and what conditioning are you doing to the sensor output before the ADC, if any? Does it run through an op amp, a voltage divider, any other scaling or shifting circuits? Without knowing what the input signal to the ADC looks like, we have no way of knowing what your code needs to look like.
 

Sensacell

Joined Jun 19, 2012
2,522
Consider using only integer math.
For this application, floating point is a big fat unnecessary hog of resources.

Just multiply all your values by a binary factor like 512, 1024 etc.
Then you can divide the result down with a simple bit-shift to get the final result.
 
The code that you posted is typical for an LM35 temperature sensor and not an LM358 Op Amp (as already stated).

If you include a schematic with some details (length of leads, data output, responsiveness when increasing temperature, and the like), we might be able to advise you as to why you are not getting the values you think that you should be getting. Sometimes a simple capacitor is all that is needed to improve performance (see here and a zillion other places).

Edit: Since you say "By the way i am using my own device to replace LM358.", you need to identify the device that you are using.
 
Last edited:
Top