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

Hey guys

I'm currently on the Love-o-Meter project in the Arduino starter kit. Here's my code (pretty much identical to example file in Arduino):

Code:
const int sensorPin = A0;
const float baselineTemp = 90.0;

void setup()
{
  
  Serial.begin(9600);
  
  for (int pinNumber = 2; pinNumber < 5; pinNumber++)
  {
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void loop()
{
  int sensorVal = analogRead(sensorPin);
  
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
  
  float voltage = (sensorVal/1024.0) * 5.0;
  
  Serial.print(", Volts:");
  Serial.print(voltage);
  
  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  
  if (temperature < baselineTemp)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  
  else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  
  else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }
  
  else if (temperature > baselineTemp + 6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
  
  delay(1);
  
}

So far I'm encountering two problems:

1. The temperature readings are way off. I used the same equations that the book provided: (voltage = (sensorVal/1024.0) * 5.0) and (temperature = (voltage - .5) * 100).
But my Serial.print is outputting values around 100 degrees C.

2. I wanted to test the blinking lights, so I ignored the abnormal temperature reading. I changed my baseline temperature to 90 degrees. However, even as I warm the sensor temperature to 110 degrees C, the lights still doesn't come on.

The logic all seems right to me, but for some reason it just doesn't work. Can you help me?

And just out of curiosity, what is the logic behind these two equations?

voltage = (sensorVal / 1024)
temperature = (voltage - .5) * 100

Thanks in advance
Jimmy

« Last Edit: May 31, 2013, 06:25:19 pm by ThePrince » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

NVM guys, I found out what was the problem. The ground wire wasn't connected to the right pin port.
Logged

Pages: [1]   Go Up
Jump to: