Visual Thermometer - Circuit Playground Express

Image
temp 79
Author
Date published

This project uses the Circuit Playground Express to create a visual thermometer. The current temperature is measured and represented with LEDS.

Using Circuit Playground Express is a great way to start programming a microcontroller and components. The Playground Express contains components on one small board; including 10 NeoPixels, motion sensor, temperature sensor, light sensor, sound sensor, mini speaker, pushbuttons, slide switch, infrared receiver/transmitter, and capacitive touchpads. Without wiring and soldering, you can write programs that interact with one or all of these components.

 

Image
Adafruit playground

This project uses the temperature sensor and all ten RGB LEDs (aka NeoPixels), Every ten seconds, a temperature reading is taken and represented by lighting the LEDs. First, the tens are displayed in blue followed by the ones in yellow. 79 degrees Fahrenheit is displayed as seven blue lights, followed by nine yellow lights.

Image
Adafruit playground

 

The Code

The current version of this code is available on Github.

# Import Libraries
import board
import time
from adafruit_circuitplayground.express import cpx

# LED Settings
cpx.pixels.brightness = 0.2
cpx.pixels.auto_write = True
RED = (255,0,0)
NONE = (0,0,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)

# Defaults
led_degree_delay = .1  # Seconds between LED degree display
led_tens_delay = 2. # Seconds between display tens and ones of temperature
measurement_delay = 10  # Seconds between temperature measurements

# led_temp - display temperature with LEDS.  First tens, and ones.
def led_temp (temp_f):
    # Light an LED for each 10th dgree of temp, 72 degrees has 7 LEDs
    tens = int(abs(temp_f // 10)) * 10
    ones = int(abs(temp_f)) - tens
    cpx.pixels.fill(NONE)
    print("Update LEDs display")
    # Display tens
    for x in range(tens / 10):
        cpx.pixels[x] = BLUE
        time.sleep(led_degree_delay)
    time.sleep(led_tens_delay)
    cpx.pixels.fill(NONE)
    # Display ones
    for x in range(ones):
        cpx.pixels[x] = YELLOW
        time.sleep(led_degree_delay)
    time.sleep(led_tens_delay)
    cpx.pixels.fill(NONE)

while True:
    # Take temperature measurement and convert for fahrenheit
    temperature_f = cpx.temperature * 1.8 + 32
    print(temperature_f)
    led_temp(temperature_f)
    time.sleep(measurement_delay

 

Temperature Sensor

From the Circuit Playground Express datasheet, "There is an NTC thermistor (Murata NCP15XH103F03RC) that we use for temperature sensing. While it isn't an all-in-one temperature sensor, with linear output, it's easy to calculate the temperature based on the analog voltage on analog pin#A9. There's a 10K resistor connected to it as a pull-down."

Based on my testing, the starting temperature is not accurate, but the changes to temperature are. This project is not about getting an accurate room temperature, it's about interacting with the components.

UPDATE 5/2/2021

After writing this post I continued testing with an additional temperature sensor, the AS2302. I connected it to the Playground Express and updated the to program take an additional reading from the AS2303. The reading was about 3 degrees lower than the Playground's onboard sensor. It took about ten minutes for the AS2303 to settle in, it's initial readings were five degrees higher.

Image
playground wired to temperature sensor

Updated output including both temperature readings:

Temp: 74.8 F, DHT22 71.8 F
Update LEDs display
Temp: 74.8 F, DHT22 71.8 F
Update LEDs display
Temp: 74.8 F, DHT22 71.8 F
Update LEDs display

Updated Program

# Import Libraries
import board
import time
from adafruit_circuitplayground.express import cpx
# For DHT22 (AM2302)
import adafruit_dht

# LED Settings
cpx.pixels.brightness = 0.2
cpx.pixels.auto_write = True
RED = (255,0,0)
NONE = (0,0,0)
BLUE = (0,0,255)
YELLOW = (255,255,0)

# Defaults
led_degree_delay = .1  # Seconds between LED degree display
led_tens_delay = 2. # Seconds between display tens and ones of temperature
measurement_delay = 10  # Seconds between temperature measurements

# Initial HST22(AM2302) device
dht = adafruit_dht.DHT22(board.A7)

# led_temp - display temperature with LEDS.  First tens, and ones.
def led_temp (temp_f):
    # Light an LED for each 10th dgree of temp, 72 degrees has 7 LEDs
    tens = int(abs(temp_f // 10)) * 10
    ones = int(abs(temp_f)) - tens
    cpx.pixels.fill(NONE)
    print("Update LEDs display")
    # Display tens
    for x in range(tens / 10):
        cpx.pixels[x] = BLUE
        time.sleep(led_degree_delay)
    time.sleep(led_tens_delay)
    cpx.pixels.fill(NONE)
    # Display ones
    for x in range(ones):
        cpx.pixels[x] = YELLOW
        time.sleep(led_degree_delay)
    time.sleep(led_tens_delay)
    cpx.pixels.fill(NONE)

while True:
    # Take temperature measurement and convert for fahrenheit - 1.8 + 32
    temperature_f = cpx.temperature * 1.8 + 32
    # Temp from DHT22 (AM2302)
    dht22_temperature_f = dht.temperature * 1.8 + 32
    # print(temperature_f)
    print("Temp: {:.1f} F, DHT22 {:.1f} F".format(
                temperature_f, dht22_temperature_f
            )
    )
    led_temp(temperature_f)
    time.sleep(measurement_delay)