Overview

This is a fun and simple beginner project that turns the Circuit Playground into a cold temperature indicator. It uses the on board temperature sensor to read the current temperature. The coldest temperature measured is indicated on the NeoPixels.

An additional sketch is provided which turns the Circuit Playground into a temperature data logger.

Required Parts

This project uses the sensors already included on the Circuit Playground so no additional electronics or soldering are required. You will also need some batteries and a holder for the batteries.

Before Starting

If you are new to the Circuit Playground, you may want to first read these overview guides.

This project will use the Arduino IDE. Make sure you have added the board support for the Circuit Playground as well as installed the Circuit Playground library. MUST DO BOTH. This is covered in the guides linked above.

Hello Temperature

Since this project uses the temperature sensor, let's start by exploring how it works and behaves. You can read some technical details in the Lesson #0 Guide. And for reference, here is where the temperature sensor is located on the Circuit Playground.

There is an example sketch included with the Circuit Playground library that we can use to play around with the temperature sensor. It can be found in the following location:

File -> Examples -> Adafruit Circuit Playground -> Hello_CircuitPlayground -> Hello_Temperature

With this sketch loaded and running on the Circuit Playground, open the Serial Monitor.

Tools -> Serial Monitor

The current value from the temperature sensor will be printed once a second.

Try breathing on the temperature sensor. You should see the value increase, and then slowly decrease when you stop. Now try holding your finger on the sensor. Did the temperature go up?

Another way to watch the values of the temperature sensor is to use the Serial Plotter. To do this, let's first modify the code slightly. The code below changes the format of the output to work with the Serial Plotter and increases the rate at which the values are displayed.

#include <Adafruit_CircuitPlayground.h>

float tempC, tempF;

void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
}

void loop() {
  tempC = CircuitPlayground.temperature();
  tempF = CircuitPlayground.temperatureF();

  // Uncomment one of the following.
  //Serial.println(tempC);
  Serial.println(tempF);

  delay(100);
}

With this sketch loaded and running on the Circuit Playground, open the Serial Plotter.

Tools -> Serial Plotter

The temperature sensor value will now be plotted like a strip chart as shown below. Again, try breathing on the sensor to watch the value increase and then decrease.

Cold Temperature Display

This is a simple sketch that displays the coldest temperature measured on the NeoPixels.

With this sketch loaded and running on the Circuit Playground, you can place it somewhere and let it sit. It will continuously read the current temperature and keep track of the coldest (minimum) temperature measured.

The freezer compartment of your refrigerator is a convenient place to try. Leave the Circuit Playground in the freezer for at least 30 minutes to insure it cools all the way down.

When you retrieve the Circuit Playground, it will show the minimum temperature seen on the NeoPixels. You can select either Fahrenheit (+, left) or Celsius (-, right) using the slide switch. Then, use the diagram below to determine the value.

You come up with the temperature by adding up the value shown for each NeoPixel that is lit. For example:

-6 °C

Slide switch = - (Celsius)

Blue light is on, so negative.

2 + 4 = 6

19 °F

Slide switch = + (Fahrenheit)

Blue light is off, so positive.

1 + 2 + 16 = 19

To clear the minimum temperature value and start over, just press RESET.

Temperature Data Logger

This is a more complex sketch which logs the temperature values to the EEPROM. This is a special memory space on the Circuit Playground that remains even if power is lost. Total storage space allows for a little over 500 readings to be stored (511 if you must know). The stored values can be sent over the serial port in one of several formats.

There are two settings you can change to configure the temperature logger. They are found on the following lines of code near the top of the sketch.

// OK to change these
#define LOG_WRAP    false // Set log wrapping
#define LOG_RATE    1000  // Set log rate in milliseconds

Use these to change whether the log buffer wraps when full and how often to measure the temperature as follows:

  • LOG_WRAP: If true, the log buffer will wrap when full and start overwriting older data. If false, logging will stop when the log buffer is full.
  • LOG_RATE: Sets how often the temperature is measured and saved to the log. The value is in milliseconds.

With this sketch loaded and running on the Circuit Playground, you choose between one of two modes using the slide switch.

  • LOGGING MODE (Slide switch = +): Use this mode to start/stop/clear temperature log.
  • READOUT MODE (Slide switch = -): Use this mode to output current log contents to serial port.

Logging Mode

With the slide switch in the left (+) position, the Circuit Playground is in logging mode. The NeoPixels on the left half will be lit green to indicate this mode. To control logging, use the two push buttons as follows:

  • Left Button: Press to start/stop logging. The #2 NeoPixel, next to the left button, will change to show stopped (red) or running (green).
  • Right Button + Left Button: Press both together to clear the log buffer and reset logging. All NeoPixels will temporarily light red.

Logging Mode Indicator Lights

The NeoPixels on the left indicate logging mode and whether the log is running or not. When the log is running, the red LED next to the USB connector will blink. The NeoPixels on the right indicate data buffer status.

Log is running. Buffer is 4/5 full.

  • #2 NeoPixel is green.
  • Red LED is blinking.
  • 4 of 5 white lights on right are lit indicating log space used.

Log is stopped. Buffer is full. (wrap off)

  • #2 NeoPixel is red.
  • Red LED is not blinking.
  • All lights on right red, indicating full buffer.

Log is running. Buffer is full. (wrap on)

  • #2 NeoPixel is green.
  • Red LED is blinking.
  • All lights on right red, indicating full buffer.
  • White light indicates current wrap position.

Readout Mode

With the slide switch in the right (-) position, the Circuit Playground is in readout mode. The NeoPixels on the left half will be lit light blue to indicate this mode. To control readout, use the two push buttons as follows:

  • Right Button: choose output format (see figure below).
  • Left Button: output to serial port using current output format.

Readout Mode Indicator Lights

The NeoPixels on the left indicate readout mode. The NeoPixels on the right indicate the currently selected output format.

The first two format options are meant to be used with the Serial Plotter. The last three format options are meant to be used with the Serial Monitor.

Logger Example

In this example, the logger sketch was uploaded with the following settings.

// OK to change these
#define LOG_WRAP    true  // Set log wrapping
#define LOG_RATE    5000  // Set log rate in milliseconds

The slide switch was set to the left (+) for logging mode. Both the right and left buttons were pressed at the same time to clear the log. Then the left button was pressed to start logging and the Circuit Playground was placed in the freezer.

Press the left button and place in freezer.

Lights on left are all green. Red LED should blink indicating logging. Buffer is starting to fill.

Lights on right are all red indicating the log buffer is full. However, since wrapping was enabled, it is still logging. Red LED is flashing. White NeoPixel is progressing through buffer.

Remove from freezer. Move slide switch to the right (-) position for Readout Mode. Attach to computer with USB cable.

Looking at Data with Serial Plotter

Open the Serial Plotter:

Tools -> Serial Plotter

Use the right button to select one of the plotting output modes: Celsius Plot or Fahrenheit Plot. Then press the left button and the data should be plotted.

In the example below, the Fahrenheit Plot option was used.

Several cooling cycles can be seen as indicated by the gradual up and down temperature trends. The rapid rise in temperature at the end occurred when the freezer door was opened to take a photo before removing the Circuit Playground.

Looking at Data with Serial Monitor

Open the Serial Monitor:

Tools -> Serial Monitor

Select the Summary output option and press the left button. You should see a brief summary of the log data.

You can also dump the entire contents in a tabular format using one of the Table output options. This is mainly meant to be used for downloading the data as described in the next section.

Downloading Data with Serial Monitor

Open the Serial Monitor

Tools -> Serial Monitor

Select one of the tabular format output options: Table No Headers or Table With Headers. Press the left button and the entire contents of the log buffer will be dumped to the serial port.

Click on the text in the Serial Monitor to make sure it is selected and press <CTRL>-<A> to select all the contents.

Now press <CTRL>-<C> to copy the selection into the clipboard. Open a text editor and paste the contents into a text file using <CTRL>-<V>.

Save the file, giving it a name like data.csv or similar. You can now open that file in other applications, like a spreadsheet, for further analysis and plotting.

Questions and Code Challenges

The following are some questions related to this project along with some suggested code challenges. The idea is to provoke thought, test your understanding, and get you coding!

While the sketch provided works, there is room for improvement and additional features. Have fun playing with the provided code to see what you can do with it.

Questions

  • Which is colder, the refrigerator or the freezer?
  • How cold is it outside?

Code Challenges

  • Change the Cold Temperature Display into a Warm Temperature Display.
  • Add an audio alarm to the Cold Temperature Display that sounds when the temperature goes below freezing.