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
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:
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
//convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(" , Volts: ");
Serial.print(", degrees C: ");
//convert the voltage to temp in degrees
float temperature = (voltage - .5) * 100;
Any insight for this would be greatly appreciated.
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 :)