user49762: Thank you everyone for help on my last post, i managed to make it work.  I still keep trying to craft my skill with the arduino.  This time I need to make a coffee hot plate simulation.  When the sensor is not up to temp an LED will blink, once the sensor gets up to temp the LED will blink but turn off (go to low) after five seconds. This is the code i am working on.  The sensor is at temp and the LED is still blinking instead of turning off.  When its low it blinks as should.  I think the bug is in the millis() portion of code.  Any ideas would be greatly appreciated.  I also ran the println screen, and the temp is consistantly around 210-220. 
const int led         =  11;       // hot plate led on pin 11  
const int sensor      =   9;       // temp sensor on pin 9
const int LOWER_BOUND = 174;       // lower temp
const int UPPER_BOUND = 220;       // upper temp

int val = 0;                       // analog reading

unsigned const long period = 5000; // time it takes to turn led off at temp

unsigned long startMillis;
unsigned long currentMillis;

void setup() {
    Serial.begin(9600);
    pinMode(led, OUTPUT);
    pinMode(sensor, INPUT);
    startMillis = millis();
}

void loop() {

    val = analogRead(sensor);      // temp recorder
    Serial.println(val);
    currentMillis = millis();

    if (val == UPPER_BOUND){
        digitalWrite(led, HIGH);
    }

    else if (val == UPPER_BOUND && currentMillis - startMillis == period) {
        digitalWrite(led, LOW);
    }   

    else (val <= LOWER_BOUND); {
        digitalWrite(led, LOW); 
        delay(200);
        digitalWrite(led, HIGH);
        delay(200);    
    }
}


user7508: First, let me point out a few technical issues with your program:

const int sensor = 9; is wrong. On an Uno, you can only use
analogRead() on the pins labeled A0 through A5.
if (val == UPPER_BOUND). Never test an analog reading for exact
equality. The reading is noisy, and you shouldn't expect continuity.
It can very well jump from UPPER_BOUND-1 on one reading to
UPPER_BOUND+1 on the next one. Instead, test for
val >= UPPER_BOUND.
currentMillis - startMillis == period. Again, you should not test
for exact equality. This time it's for a more subtle reason that has
to do with the implementation of millis(): some values (roughly one
every 42) are skipped over. Here again, test for >= period.

There is also the issue, already pointed out by PhoenixRevealed, of
your code defining two thresholds, while your prose only mentions one.
This may well be just you being sloppy and not describing your
requirements precisely enough.
Next, and since you are interested in perfecting your learning process,
let me advise you on two techniques that are worth learning, because
they are extremely useful for mostly any Arduino project more complex
than just blinking an LED:

Avoid using delay(). While the Arduino is busy delaying, it can
do nothing else. For instance, it cannot monitor the temperature
changes on the hot plate. In this particular case, it may well be the
case that you don't care, because the hot plate is so slow that you
can afford to be 400 ms late. But if you get into the habit of
relying on delay(), it will bite you sooner or later. So the sooner
you learn to blink an LED without using delay(), the
better.
Learn to program a finite state machine. This is a programming
concept that is very well suited for describing reactive systems,
i.e. systems that have to react to external “events”. It is a very
useful concept for writing most programs that are meant to control
hardware. There are quite a few tutorials out there. I would
recommend The Finite State Machine, by Majenko.

Here is my interpretation of your requirements in terms of a finite
state machine: your Arduino can be in any of 3 states: COLD (initial
state, the plate has not reached the required temperature), WAITING
(the plate reached the temperature and we are delaying five seconds),
DONE (the five seconds have elapsed). The rules for changing states
are:

COLD → WAITING: when in the COLD state, if the temperature
reaches a specified threshold, go to the WAITING state.
WAITING → DONE: when in the WAITING state, once five seconds
have elapsed since we entered the state, go to the DONE state.
When we are in the DONE state... nothing more ever happens.

Here is the corresponding state diagram:

Notice that once we reach the DONE state, the system gets stuck. This
situation can only be recovered from by rebooting the Arduino. You may
want to revise your specification in order accommodate a DONE → COLD
transition in some way. But from your specification as written in your
question, I assume you are fine with the system getting stuck.
I tried to implement this state diagram in code, using the traditional
switch/case construct. But then I got lazy and noticed that calling
exit() is the easiest way of implementing the DONE state, as
this function is precisely designed to get the program stuck in a
do-nothing state. Then, since there are only two states left to care
about, a boolean can be used as a state variable. In the end, the code I
propose may not look like a finite state machine. However, it is
important to notice that, event if such case, the finite state machine
is a very useful concept for thinking about your program and writing
down its requirements.
// Pinout
const uint8_t LED = 11;
const uint8_t SENSOR = A0;

// Threshold temperature reading.
const int THRESHOLD_TEMP_READING = 220;

// Timing.
const uint32_t LED_TOGGLE_PERIOD = 200;
const uint32_t WAIT_TIME = 5000;

bool is_hot = false;
uint32_t last_led_toggle;
uint32_t wait_started;

void setup()
{
    pinMode(LED, OUTPUT);
    pinMode(SENSOR, INPUT);
}

void loop()
{
    // Read the time once per loop.
    uint32_t now = millis();

    // Toggle the LED state.
    if (now - last_led_toggle >= LED_TOGGLE_PERIOD) {
        digitalWrite(LED, !digitalRead(LED));
        last_led_toggle = now;
    }

    if (is_hot) {
        // If the plate is hot, keep blinking during WAIT_TIME.
        if (millis() - wait_started >= WAIT_TIME) {
            digitalWrite(LED, LOW);  // turn off the LED
            exit(0);                  // stop everything
        }
    } else {
        // If the plate is cold, take note when it gets hot.
        if (analogRead(SENSOR) >= THRESHOLD_TEMP_READING) {
            is_hot = true;
            wait_started = now;
        }
    }
}


49762: <p>Thank you everyone for help on my last post, i managed to make it work.  I still keep trying to craft my skill with the arduino.  This time I need to make a coffee hot plate simulation.  When the sensor is not up to temp an LED will blink, once the sensor gets up to temp the LED will blink but turn off (go to low) after five seconds. This is the code i am working on.  The sensor is at temp and the LED is still blinking instead of turning off.  When its low it blinks as should.  I think the bug is in the millis() portion of code.  Any ideas would be greatly appreciated.  I also ran the println screen, and the temp is consistantly around 210-220. </p>

<pre><code>const int led         =  11;       // hot plate led on pin 11  
const int sensor      =   9;       // temp sensor on pin 9
const int LOWER_BOUND = 174;       // lower temp
const int UPPER_BOUND = 220;       // upper temp

int val = 0;                       // analog reading

unsigned const long period = 5000; // time it takes to turn led off at temp

unsigned long startMillis;
unsigned long currentMillis;

void setup() {
    Serial.begin(9600);
    pinMode(led, OUTPUT);
    pinMode(sensor, INPUT);
    startMillis = millis();
}

void loop() {

    val = analogRead(sensor);      // temp recorder
    Serial.println(val);
    currentMillis = millis();

    if (val == UPPER_BOUND){
        digitalWrite(led, HIGH);
    }

    else if (val == UPPER_BOUND &amp;&amp; currentMillis - startMillis == period) {
        digitalWrite(led, LOW);
    }   

    else (val &lt;= LOWER_BOUND); {
        digitalWrite(led, LOW); 
        delay(200);
        digitalWrite(led, HIGH);
        delay(200);    
    }
}
</code></pre>
 7508: <p>First, let me point out a few technical issues with your program:</p>

<ol>
<li><p><code>const int sensor = 9;</code> is wrong. On an Uno, you can only use
<code>analogRead()</code> on the pins labeled <code>A0</code> through <code>A5</code>.</p></li>
<li><p><code>if (val == UPPER_BOUND)</code>. Never test an analog reading for exact
equality. The reading is noisy, and you shouldn't expect continuity.
It can very well jump from <code>UPPER_BOUND-1</code> on one reading to
<code>UPPER_BOUND+1</code> on the next one. Instead, test for
<code>val &gt;= UPPER_BOUND</code>.</p></li>
<li><p><code>currentMillis - startMillis == period</code>. Again, you should not test
for exact equality. This time it's for a more subtle reason that has
to do with the implementation of <code>millis()</code>: some values (roughly one
every&nbsp;42) are skipped over. Here again, test for <code>&gt;= period</code>.</p></li>
</ol>

<p>There is also the issue, already pointed out by PhoenixRevealed, of
your code defining two thresholds, while your prose only mentions one.
This may well be just you being sloppy and not describing your
requirements precisely enough.</p>

<p>Next, and since you are interested in perfecting your learning process,
let me advise you on two techniques that are worth learning, because
they are extremely useful for mostly any Arduino project more complex
than just blinking an LED:</p>

<ol>
<li><p><strong>Avoid using <code>delay()</code></strong>. While the Arduino is busy delaying, it can
do nothing else. For instance, it cannot monitor the temperature
changes on the hot plate. In this particular case, it may well be the
case that you don't care, because the hot plate is so slow that you
can afford to be 400&nbsp;ms late. But if you get into the habit of
relying on <code>delay()</code>, it will bite you sooner or later. So the sooner
you learn to <a href="https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay" rel="nofollow noreferrer">blink an LED without using <code>delay()</code></a>, the
better.</p></li>
<li><p>Learn to program a <strong>finite state machine</strong>. This is a programming
concept that is very well suited for describing reactive systems,
i.e. systems that have to react to external “events”. It is a very
useful concept for writing most programs that are meant to control
hardware. There are quite a few tutorials out there. I would
recommend <a href="https://hackingmajenkoblog.wordpress.com/2016/02/01/the-finite-state-machine/" rel="nofollow noreferrer">The Finite State Machine</a>, by Majenko.</p></li>
</ol>

<p>Here is my interpretation of your requirements in terms of a finite
state machine: your Arduino can be in any of 3 states: <code>COLD</code> (initial
state, the plate has not reached the required temperature), <code>WAITING</code>
(the plate reached the temperature and we are delaying five seconds),
<code>DONE</code> (the five seconds have elapsed). The rules for changing states
are:</p>

<ul>
<li><code>COLD</code> → <code>WAITING</code>: when in the <code>COLD</code> state, if the temperature
reaches a specified threshold, go to the <code>WAITING</code> state.</li>
<li><code>WAITING</code> → <code>DONE</code>: when in the <code>WAITING</code> state, once five seconds
have elapsed since we entered the state, go to the <code>DONE</code> state.</li>
<li>When we are in the <code>DONE</code> state... nothing more ever happens.</li>
</ul>

<p>Here is the corresponding state diagram:</p>

<p><a href="https://i.stack.imgur.com/7ZGQL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ZGQL.png" alt="state diagram"></a></p>

<p>Notice that once we reach the <code>DONE</code> state, the system gets stuck. This
situation can only be recovered from by rebooting the Arduino. You may
want to revise your specification in order accommodate a <code>DONE</code> → <code>COLD</code>
transition in some way. But from your specification <em>as written in your
question</em>, I assume you are fine with the system getting stuck.</p>

<p>I tried to implement this state diagram in code, using the traditional
<code>switch</code>/<code>case</code> construct. But then I got lazy and noticed that calling
<a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga137096a48cc0c731052cadfb69c39b34" rel="nofollow noreferrer"><code>exit()</code></a> is the easiest way of implementing the <code>DONE</code> state, as
this function is precisely designed to get the program stuck in a
do-nothing state. Then, since there are only two states left to care
about, a boolean can be used as a state variable. In the end, the code I
propose may not look like a finite state machine. However, it is
important to notice that, event if such case, the finite state machine
is a very useful concept for <em>thinking</em> about your program and writing
down its requirements.</p>

<pre class="lang-c++ prettyprint-override"><code>// Pinout
const uint8_t LED = 11;
const uint8_t SENSOR = A0;

// Threshold temperature reading.
const int THRESHOLD_TEMP_READING = 220;

// Timing.
const uint32_t LED_TOGGLE_PERIOD = 200;
const uint32_t WAIT_TIME = 5000;

bool is_hot = false;
uint32_t last_led_toggle;
uint32_t wait_started;

void setup()
{
    pinMode(LED, OUTPUT);
    pinMode(SENSOR, INPUT);
}

void loop()
{
    // Read the time once per loop.
    uint32_t now = millis();

    // Toggle the LED state.
    if (now - last_led_toggle &gt;= LED_TOGGLE_PERIOD) {
        digitalWrite(LED, !digitalRead(LED));
        last_led_toggle = now;
    }

    if (is_hot) {
        // If the plate is hot, keep blinking during WAIT_TIME.
        if (millis() - wait_started &gt;= WAIT_TIME) {
            digitalWrite(LED, LOW);  // turn off the LED
            exit(0);                  // stop everything
        }
    } else {
        // If the plate is cold, take note when it gets hot.
        if (analogRead(SENSOR) &gt;= THRESHOLD_TEMP_READING) {
            is_hot = true;
            wait_started = now;
        }
    }
}
</code></pre>
