Pages: [1]   Go Down
Author Topic: Math for Project 3 Love-o-Meter  (Read 1637 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
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
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:

void loop(){
  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.

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

This should help explain things

The few pages before and after this page are also useful smiley

Pages: [1]   Go Up
Jump to: