Klausj
Published © GPL3+

UNO R4 Wifi as a digital thermometer

What can you do with 96 LEDs? Just show a three-digit number, in this case the most expensive thermometer.

BeginnerFull instructions provided1 hour1,520
UNO R4 Wifi as a digital thermometer

Things used in this project

Story

Read more

Code

Sketch to measure and display temperature on the UNO R4 LED matrix.

Arduino
Just upload the sketch, insert the sensor and have fun.
/*
  Das teuerste Thermometer der Welt

  Zeichenanzeige auf Matrix:
  https://arduinogetstarted.com/tutorials/arduino-uno-r4-led-matrix-displays-number-character
*/

// Temperatursensor:
#include <DS18B20.h>

DS18B20 ds(A0);

// UNO-R4 Wifi LED Matrix:
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;

byte fonts[][8] = {
  { 0, 7, 5, 5, 5, 7, 0, 0}, // 0
  { 0, 2, 6, 2, 2, 7, 0, 0}, // 1
  { 0, 7, 1, 7, 4, 7, 0, 0}, // 2
  { 0, 7, 1, 7, 1, 7, 0, 0}, // 3
  { 0, 5, 5, 7, 1, 1, 0, 0}, // 4
  { 0, 7, 4, 7, 1, 7, 0, 0}, // 5
  { 0, 7, 4, 7, 5, 7, 0, 0}, // 6
  { 0, 7, 1, 1, 1, 1, 0, 0}, // 7
  { 0, 7, 5, 7, 5, 7, 0, 0}, // 8
  { 0, 7, 5, 7, 1, 7, 0, 0}, // 9
};

byte empty[8][12], frame[8][12];

void setup() {
  Serial.begin(9600);
  Serial.println(__FILE__);
  delay(1500);
  matrix.begin();
  empty[6][7] = 1; // decimal dot
}

void loop() {
  int th, tz, te;
  while (ds.selectNext()) {
    byte address[8];
    ds.getAddress(address);
    float t = ds.getTempC();
    int ti = 10 * t;
    th = ti / 100;
    tz = ti % 100 / 10;
    te = ti % 10;
  }
  memcpy(frame, empty, sizeof empty);
  add_to_frame(th, -2);
  add_to_frame(tz, 2);
  add_to_frame(te, 7);
  matrix.renderBitmap(frame, 8, 12);
}

void add_to_frame(int index, int pos) {
  for (int row = 0; row < 8; row++) {
    long temp = fonts[index][row] << (7 - pos);
    for (int col = 0; col < 12; col++) {
      frame[row][col] |= (temp >> (11 - col)) & 1;
    }
  }
}

Sketch to measure and display temperature on the UNO R4 LED matrix.

Arduino
Just upload the sketch, insert the sensor an have fun.
/*
  Das teuerste Thermometer der Welt

  Zeichenanzeige auf Matrix:
  https://arduinogetstarted.com/tutorials/arduino-uno-r4-led-matrix-displays-number-character
*/

// Temperatursensor:
#include <DS18B20.h>

DS18B20 ds(A0);

// UNO-R4 Wifi LED Matrix:
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;

byte fonts[][8] = {
  { 0, 7, 5, 5, 5, 7, 0, 0}, // 0
  { 0, 2, 6, 2, 2, 7, 0, 0}, // 1
  { 0, 7, 1, 7, 4, 7, 0, 0}, // 2
  { 0, 7, 1, 7, 1, 7, 0, 0}, // 3
  { 0, 5, 5, 7, 1, 1, 0, 0}, // 4
  { 0, 7, 4, 7, 1, 7, 0, 0}, // 5
  { 0, 7, 4, 7, 5, 7, 0, 0}, // 6
  { 0, 7, 1, 1, 1, 1, 0, 0}, // 7
  { 0, 7, 5, 7, 5, 7, 0, 0}, // 8
  { 0, 7, 5, 7, 1, 7, 0, 0}, // 9
};

byte empty[8][12], frame[8][12];

void setup() {
  Serial.begin(9600);
  Serial.println(__FILE__);
  delay(1500);
  matrix.begin();
  empty[6][7] = 1; // decimal dot
}

void loop() {
  int th, tz, te;
  while (ds.selectNext()) {
    byte address[8];
    ds.getAddress(address);
    float t = ds.getTempC();
    int ti = 10 * t;
    th = ti / 100;
    tz = ti % 100 / 10;
    te = ti % 10;
  }
  memcpy(frame, empty, sizeof empty);
  add_to_frame(th, -2);
  add_to_frame(tz, 2);
  add_to_frame(te, 7);
  matrix.renderBitmap(frame, 8, 12);
}

void add_to_frame(int index, int pos) {
  for (int row = 0; row < 8; row++) {
    long temp = fonts[index][row] << (7 - pos);
    for (int col = 0; col < 12; col++) {
      frame[row][col] |= (temp >> (11 - col)) & 1;
    }
  }
}

Credits

Klausj
86 projects • 7 followers
Contact

Comments

Please log in or sign up to comment.