user71323: #include "VernierLib.h"

VernierLib Vernier;

#define led 13

float sensorReading;

void setup() {
  Serial.begin(9600);
  Serial.println(Vernier.sensorName());
  Vernier.autoID();
}

void loop() {
  float base_temp;
  base_temp = Serial.parseFloat();   
  sensorReading = Vernier.readSensor();
  Serial.print(sensorReading);
  Serial.print(" ");
  Serial.println(Vernier.sensorUnits());
  Serial.println(base_temp);
  if (base_temp > sensorReading) {
    digitalWrite(led, HIGH);
  } else {
    digitalWrite(led, LOW);
  }
  delay(3000);
}

That's the code, I have a question. When I write the temperature to Serial, it lasts only until the end of one loop.
How to keep the same temperature in the next loop?

user4143: There are two things here you need to consider.
First is that your variable is a "local" variable. This kind of variable is created at the start of each iteration, then discarded at the end of that iteration.
There's two things you can do to "fix" this:

Make the variable "global" - that is, move the definition out of loop() to the "global" scope (put it at the top of your program). It is then only created once and never discarded.
Make the variable "static" - that is, add the static keyword to it. It is then created on the first iteration only, and never discarded.

The second thing to consider is that you have no "There is no value" concept. Every iteration you parse a new float, whether there is one there or not. And if there isn't one then it just gives you 0. So you need to come up with some way of saying "I have entered a number, so parse it". The simplest thing is just to assume that all values of 0 are "no number entered", but that of course prevents you ever entering 0 as a valid input.

71323: <pre class="lang-cpp prettyprint-override"><code>#include &quot;VernierLib.h&quot;

VernierLib Vernier;

#define led 13

float sensorReading;

void setup() {
  Serial.begin(9600);
  Serial.println(Vernier.sensorName());
  Vernier.autoID();
}

void loop() {
  float base_temp;
  base_temp = Serial.parseFloat();   
  sensorReading = Vernier.readSensor();
  Serial.print(sensorReading);
  Serial.print(&quot; &quot;);
  Serial.println(Vernier.sensorUnits());
  Serial.println(base_temp);
  if (base_temp &gt; sensorReading) {
    digitalWrite(led, HIGH);
  } else {
    digitalWrite(led, LOW);
  }
  delay(3000);
}
</code></pre>
<p>That's the code, I have a question. When I write the temperature to Serial, it lasts only until the end of one loop.</p>
<p>How to keep the same temperature in the next loop?</p>
 4143: <p>There are two things here you need to consider.</p>
<p>First is that your variable is a &quot;local&quot; variable. This kind of variable is created at the start of each iteration, then discarded at the end of that iteration.</p>
<p>There's two things you can do to &quot;fix&quot; this:</p>
<ol>
<li>Make the variable &quot;global&quot; - that is, move the definition out of <code>loop()</code> to the &quot;global&quot; scope (put it at the top of your program). It is then only created once and never discarded.</li>
<li>Make the variable &quot;static&quot; - that is, add the <code>static</code> keyword to it. It is then created on the first iteration only, and never discarded.</li>
</ol>
<p>The second thing to consider is that you have no &quot;There is no value&quot; concept. Every iteration you parse a new float, whether there is one there or not. And if there isn't one then it just gives you <code>0</code>. So you need to come up with some way of saying &quot;I have entered a number, so parse it&quot;. The simplest thing is just to assume that all values of 0 are &quot;no number entered&quot;, but that of course prevents you ever entering 0 as a valid input.</p>
