Pages: [1]   Go Down
Author Topic: Math for Project 3 Love-o-Meter  (Read 1493 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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.
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Pages: [1]   Go Up
Jump to: