# Arduino Forum

## Products => The Arduino Starter Kit and Basic Kit => Topic started by: mortslrak on Oct 31, 2013, 10:10 pm

Title: Math for Project 3 Love-o-Meter
Post by: mortslrak on Oct 31, 2013, 10:10 pm
Hello everyone, I'm going through the Arduino starter kit projects and I have a quest about project number 3. I have tried to find the answer online, but have been unable to do so as of yet. I was able to get the project to work without an issue. I'm mostly curious why we did the math like we did.

I'm wondering why we are doing the math that we do. We take the Sensor Value and divide it by 1024.0, then multiply by 5.0. I'm trying to understand why we are doing this. More importantly, how I can find this information for future projects.

I looked at the datasheet for my tmp36gz sensor and sort of understand why (but not really) we are using the
Code: [Select]
` float temperature = (voltage - .5) * 100;` but I cannot find any reason why we would divide the sensor value by 1024.0 then multiply by 5.0

Here is a larger portion of the code that does the math:

Code: [Select]
`void loop(){  int sensorVal = analogRead(sensorPin);  Serial.print("Sensor Value: ");  Serial.print(sensorVal);  //convert the ADC reading to voltage  float voltage = (sensorVal/1024.0) * 5.0;  Serial.print(" , Volts: ");  Serial.print(voltage);  Serial.print(", degrees C: ");  //convert the voltage to temp in degrees  float temperature = (voltage - .5) * 100;  Serial.println(temperature);`

Any insight for this would be greatly appreciated.
Title: Re: Math for Project 3 Love-o-Meter
Post by: Magicj on Nov 01, 2013, 12:47 am
This should help explain things https://learn.sparkfun.com/tutorials/analog-to-digital-conversion/relating-adc-value-to-voltage.

The few pages before and after this page are also useful :)