Display humidity with bar LED

dev board WeMos D1 Mini
chip ESP8266
chip 74HC595
chip Si7021
sensor humidity
features bar LED shift register

Before starting

Description

Display humidity with sensor Si7021 in a bar graph LED display via a 74HC595 shift register.

Code

Download code
#include "Adafruit_Si7021.h"
#define EN 2 // GPIO02 on ESP-01 module, D4 on nodeMCU WeMos

int dataPin = 13; // pin D7 `GPIO13` on NodeMCU boards
int clockPin = 14; // pin D5 `GPIO14` on NodeMCU boards
int latchPin = 15; // pin D8 `GPIO15` on NodeMCU boards

Adafruit_Si7021 sensor = Adafruit_Si7021();

void setup() {
  Serial.begin(115200);

  if (!sensor.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    while (true)
      ;
  }

  pinMode(EN, OUTPUT);
  digitalWrite(EN, LOW); // enable shift register

  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(115200);
}

void loop() {
  Serial.print("Temperature: ");
  Serial.print(sensor.readTemperature());
  Serial.print("\tHumidity:    ");
  Serial.print(sensor.readHumidity());

  int barHumidity = sensor.readHumidity()/20 + 1;
  String sBar = "\tGraph: " + String(barHumidity) + " bars";
  Serial.println(sBar);

 display(pow(2, barHumidity) -1); // Display humidity in LEDs
}

int display(int position) {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, position);
  digitalWrite(latchPin, HIGH);
  Serial.println(position);
}

Makefile

BOARD?=esp8266com:esp8266:d1_mini
PORT?=/dev/cu.wchusbserial1410
BUILD=build
# Arduino CLI version 0.14.0 is used.

.PHONY: default lint all flash clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

flash:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -r build

Schematic

Wire up the hardware accordingly

Display humidity with bar LED schematic

References