yettiz
Published

Easy Voltmeter with ESP8266 mini D1 Pro with Oled Display

In this project I will show you a simple voltmeter with an ESP8266 mini D1 pro with an OLED screen SH1106 with 2 resistors.

BeginnerFull instructions provided1 hour8,020
Easy Voltmeter with ESP8266 mini D1 Pro with Oled Display

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
1.3 Inch 4Pin White OLED LCD Display 12864 IIC I2C Interface Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 100k ohm
Resistor 100k ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Simple Easy ESP8266 Voltmeter with Display

Code

Simple Easy ESP8266 Voltmeter with Display

Arduino
// Easy Voltmeter with ESP8266 and Oled SH1106 and 2 Resistors 100k + 10k
// This can be used to messure up to 33V

#include <Arduino.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <SoftwareSerial.h>

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

int analogInput = A0;

float vout = 0.0;
float vin = 0.0;
float R1 = 100300;                // Resistor R1 100k 
float R2 = 10140;                 // Resistor R2 10k
int value = 0;
String $vin = "0";

void setup() {
  pinMode(analogInput, INPUT);
  u8g2.begin();                   // init Display 
  Serial.begin(115200);
}

void loop(void) {
 value = analogRead(analogInput);
 vout = (value * 3.3) / 1023.0;   // mybe u must change the 3.3 to 5 and 
                                  // *** work not correct with ESP32 ***
                                  //for the ESP32 u have to change the 1023 to 4095
                                  // ***********************************
 vin = vout / (R2/(R1+R2));
 $vin = String(vin);
 Serial.print("INPUT V= ");
 Serial.println(vin,4);
  
 showonoled();

}

//=========== Funktion init Display ========
void u8g2_prepare(void) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

//=========== Funktion show on Display =====
void showonoled() {
  Serial.println("Display on external");
  u8g2.clearBuffer();
  u8g2_prepare();
  
  u8g2.drawStr(0,36, "Voltage");
  u8g2.drawStr(70, 36, $vin.c_str());

  u8g2.sendBuffer();  
  delay(500);
}

Credits

yettiz
2 projects • 0 followers

Comments