2.2 Sensors

This exercise builds upon the hardware setup from the previous, but now we add a temperature and humidity sensor to the ensemble.

a) Read the temperature

Again, we start easy. After the website button is pressed, read the temperature sensor information every five seconds and print it to the console!

Possible solution:

b) Read the temperature and humidity

Now also print the humidity sensor value to the console. Let the user know which value is currently printed, including a short sentence with the correct unit.

Possible solution:

c) Temperature warnings with threshold

We slowly become familiar with the sensors. Let’s try to light up the LED in red when the temperature exceeds a threshold - say 30° Celsius. Let the user enter the threshold.

Optional: Add a permanent display area for the temperature that changes its background color from green to red as the threshold exceeds the limit.

Possible solution:

d) Threshold requires human interaction

Build upon the result of c), but now also make the button blink slowly in white color when the threshold exceeds a limit. This is to indicate that we need some user interaction to fix the situation.

Possible solution:

e) Human interaction

Build upon the result of d) and turn the light off again when the hardware button is pressed. The button should stop blinking, too. Make sure that the LED only turns red again when the temperature falls below the threshold and exceeds it again afterwards. When the temperature stays > 30° C and the hardware button was already pressed, the LED should not turn red again.

Possible solution:

f) Traffic light warning system

Now, instead of turning red, make the LED light up in green (OK), yellow (WARNING), and red (CRITICAL) depending on the temperature. Find useful ranges for the thresholds and assign the colors accordingly. The human interaction from e) should only be prompted when the critical threshold is exceeded!

Possible solution:

Last updated

Was this helpful?