Using Data from existing Sketch

Greetings,
Existing code from lm35 temp sensor...My question is which part of the code can I use for an 'if' statement? ie: Is 'temperatureF' an actual variable (or can I define it at the begining and == it...) or is 'temperature F' only human language and I need to use the math part?

And on a related note...all of a sudden my serial started giving me 3 digit returns of the lm35??? I had my nano breadboarded correctly and was getting normal returns but unplugged it and did some stuff but DIDNT CHANGE A THING to the program or the hardware but started getting three hundered degrees or whatever...

Any help on either question would be great,
LLOYD

// Define the analog pin, the LM35's Vout pin is connected to
#define sensorPin A0

void setup() {
  // Begin serial communication at 9600 baud rate
  Serial.begin(9600);
}

void loop() {
  // Get the voltage reading from the LM35
  int reading = analogRead(sensorPin);

  // Convert that reading into voltage
  float voltage = reading * (5.0 / 1024.0);

  // Convert the voltage into the temperature in Celsius
  float temperatureC = voltage * 100;

  // Print the temperature in Celsius
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print("\xC2\xB0"); // shows degree symbol
  Serial.print("C  |  ");
  
  // Print the temperature in Fahrenheit
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF);
  Serial.print("\xC2\xB0"); // shows degree symbol
  Serial.println("F");

  delay(1000); // wait a second between readings
}

Yes, it's declared and a value is assigned to it in this line

float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;

Its declared inside loop() and so is local to loop(). You can use it in an if() as long as the if() comes after the above line. You can't use it outside loop() or even inside loop() before the above line.

Sounds like a loose connection. What voltage does your multimeter measure at A0 pin?

Thanks for quick response. Can I define temperatureF at the top of the sketch so it is not local? I will re check my connections. I dont have a multimeter...

Yes, you can define it as a global, but have you asked yourself why you would want to?

Get a multimeter! Just one costing £10~20 will be fine, and last many years and be useful for other household jobs even if you decide not to continue with electronics as a hobby.

Even a multimeter in the outlet for 1 or 2 works fine enough..everybody should have one, IMHO

Why convert ADC value to voltage, which you don't display, then voltage to temperature?
I do:

float temperatureC = reading * 500.0 / 1024;

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.