16x16 NeoPixel Weather Station — Esp32 Devkit C V4 simulation

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by tareq-neoaz.

Components

Sketch code

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <DHT.h>

#define PIN 4
#define DHT_PIN 15
#define DHT_TYPE DHT22

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS    + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);

DHT dht(DHT_PIN, DHT_TYPE);

const byte font[11][5] = {
  {0b111, 0b101, 0b101, 0b101, 0b111}, // 0
  {0b010, 0b110, 0b010, 0b010, 0b111}, // 1
  {0b111, 0b001, 0b111, 0b100, 0b111}, // 2
  {0b111, 0b001, 0b111, 0b001, 0b111}, // 3
  {0b101, 0b101, 0b111, 0b001, 0b001}, // 4
  {0b111, 0b100, 0b111, 0b001, 0b111}, // 5
  {0b111, 0b100, 0b111, 0b101, 0b111}, // 6
  {0b111, 0b001, 0b010, 0b010, 0b010}, // 7
  {0b111, 0b101, 0b111, 0b101, 0b111}, // 8
  {0b111, 0b101, 0b111, 0b001, 0b111}, // 9
  {0b111, 0b100, 0b100, 0b100, 0b111}  // C
};

void drawSun() {
  matrix.fillCircle(8, 4, 2, matrix.Color(255, 150, 0)); // Deep orange sun
  matrix.drawLine(8, 0, 8, 1, matrix.Color(255, 150, 0));
  matrix.drawLine(8, 7, 8, 8, matrix.Color(255, 150, 0));
  matrix.drawLine(0, 4, 2, 4, matrix.Color(255, 150, 0));
  matrix.drawLine(13, 4, 15, 4, matrix.Color(255, 150, 0));
  matrix.drawPixel(3, 1, matrix.Color(255, 150, 0));
  matrix.drawPixel(13, 1, matrix.Color(255, 150, 0));
  matrix.drawPixel(3, 7, matrix.Color(255, 150, 0));
  matrix.drawPixel(13, 7, matrix.Color(255, 150, 0));
}

void drawSnow() {
  matrix.drawLine(8, 1, 8, 7, matrix.Color(0, 255, 255)); 
  matrix.drawLine(4, 4, 12, 4, matrix.Color(0, 255, 255));
  matrix.drawLine(5, 1, 11, 7, matrix.Color(0, 255, 255));
  matrix.drawLine(5, 7, 11, 1, matrix.Color(0, 255, 255));
}

void drawChar(int x, int y, int charIndex, uint16_t color) {
  for (int row = 0; row < 5; row++) {
    for (int col = 0; col < 3; col++) {
      if (font[charIndex][row] & (1 << (2 - col))) {
        matrix.fillRect(x + col, y + row, 1, 1, color); 
      }
    }
  }
}

void setup() {
  matrix.begin();
  matrix.setBrightness(40);
  dht.begin();
}

void loop() {
  float temp = dht.readTemperature();
  if (isnan(temp)) temp = 20.0; 

  matrix.fillScreen(0); 

  uint16_t textColor;
  
  // Weather Logic & Colors
  if (temp < 15.0) {
    drawSnow();
    textColor = matrix.Color(0, 255, 255); // Cyan text for cold
  } else if (temp > 25.0) {
    drawSun();
    textColor = matrix.Color(255, 0, 0);   // Red text for hot
  } else {
    drawSun(); // Draw sun for moderate weather
    textColor = matrix.Color(0, 255, 0);   // Green text for perfect weather
  }

  int displayTemp = (int)temp;
  if (displayTemp < 0) displayTemp = 0; 

  int tens = displayTemp / 10;
  int ones = displayTemp % 10;

  // Draw text perfectly centered
  if (displayTemp < 10) {
    drawChar(5, 11, ones, textColor);    
    drawChar(10, 11, 10, textColor);     
  } else {
    drawChar(3, 11, tens, textColor);    
    drawChar(8, 11, ones, textColor);    
    drawChar(13, 11, 10, textColor);     
  }

  matrix.show();
  de

More projects by tareq-neoaz