Go Down

### Topic: Project 3 - Love-o-Meter Temperature Sensor (Read 3928 times)previous topic - next topic

#### ThePrince

##### Jun 01, 2013, 12:58 amLast Edit: Jun 01, 2013, 01:25 am by ThePrince Reason: 1
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: [Select]
`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

Jimmy

#### ThePrince

#1
##### Jun 01, 2013, 01:44 am
NVM guys, I found out what was the problem. The ground wire wasn't connected to the right pin port.

Go Up

Please enter a valid email to subscribe