calculating with analog input values
hello,
i've tried create thermometer using arduino temperature sensor.
however, reason can arduino send me value read analog port, using analogread() store in value, , using serial.println() print in serial monitor.
however moment start trying calculate value, sends 0.
here's code used;
the arduino returns; 142 (that's analog read value)
0.00 (obviously did wrong calculation)
-50 ((0 - 0.5) *100 -50 of course)
please help!
i've tried create thermometer using arduino temperature sensor.
however, reason can arduino send me value read analog port, using analogread() store in value, , using serial.println() print in serial monitor.
however moment start trying calculate value, sends 0.
here's code used;
code: [select]
// thermometer: gets voltage sensor connected analog pin 5, calculates temperature this, , sends serial port every second
#define sensor 5
int val = 0;
float voltage = 0;
int temperature = 0;
void setup()
{
serial.begin(9600); //open serial port
}
void loop ()
{
val = analogread(sensor);
serial.println(val);
voltage = ((val/1023)*5);
serial.println(voltage);
temperature = ((voltage - 0.5) * 100);
serial.println(temperature);
delay(1000);
}the arduino returns; 142 (that's analog read value)
0.00 (obviously did wrong calculation)
-50 ((0 - 0.5) *100 -50 of course)
please help!
i suspect calculations running problems because of use of float , int variables in same statements. i'll let stronger software people explain better can, it's common mistake beginners make.
lefty
lefty
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > calculating with analog input values
arduino
Comments
Post a Comment