Loading...

Temperature sensor

__info__

Your BOB3 microcontroller has an integrated temperature sensor.

__info__

Now we're going to take the temperature sensor out for a drive:

The microcontroller measures the temperature when being turned on, then BOB3s eyes are green.


If you warm the microcontroller, for example by using your finger, the temperature rises and the eyes turn red.

If, for example, you put BOB3 into the fridge, it'll be a bit colder and the eyes will turn blue.

__info__

In this example we're going to use one of the global variables: start_temp

A global variable is a variable that is available throughout he whole programmeme.

This is why we need to declare it outwith the setup funktion and outwith the loop!

Underneath the #include command, we're going to declare our global variable in line 4:

int start_temp;

__info__

When turning BOB3 on, the temperature is measured in the setup() funktion and the value is stored in our global variable start_temp.

Each time the loop() function is run, the current temperature is measured in line 17 and stored in the local variable current_temp.

The difference between the temperatures is calculated and stored in line 20.

__info__

In lines 22 to 28, the eyes' colours is controlled according to the temperature:

The variable difference has a negative value if BOB3 turns colder than when he was turned on, for example if he's in the fridge.

The variable difference has a positive value if BOB3 is warmer than when he was turned on.

If the current temperature is nearly equal to the temperature when he BOB3 was turned on, then they eyes are green.

__task__

  • Compile and transfer
  • Disconnect BOB3
  • Remove the jumpers and reconnect them (BOB3 reset)
  • The eyes should now light green.
  • If BOB3 gets warmer, the eyes will turn red.
  • If BOB3 gets colder, the eyes will turn blue.

Tipp:

__quiz__

1: What would happen if the variable start_temp were declared and initialised locally in the setup() function? 
 You haven’t completed anything yet!
 Super, so far so good…
 Super, you got it all right!
 Sadly not correct…
 One answer is correct
 A couple are correct…
Fahre mit der Maus über die Symbole!