Introduction: DC Power Meter / Logger Using ESP8266

About: someone who likes electronics

In this article I will make a DC power meter / logger using the ESP8266. This tool can be used to measure voltage, current, power and electrical capacity of a power supply. The measurement results will be displayed on the OLED display and sent to the Server via MQTT for the Logger. data sent to the server can be displayed in various forms, for example charts, tables, and others.

My main goal in making this device is to measure battery capacity. With this device I can find out the original capacity of the battery, see the voltage/current chart of the charging and discharging process of the battery and know the charging and discharging process time accurately.

for now, the progress of making this device has not been fully completed. even so this tool is enough to meet the needs that I currently need (above paragraph). in future i will upgrade this tool with some features like :

  • User-friendly Menu interface
  • Error handling for WiFi and MQTT connections
  • Automatic 3.5V or 12V battery detection
  • Battery charging system
  • Battery discharge system


Supplies

This is a list of the components needed to make a DC Power Meter / Logger:

  • 1*IC INA219 => current and voltage sensors
  • 1*ESP-12E
  • 1*Display OLED 128x64 I2C
  • 1*Relay 5V
  • 1*Rotary Encoder
  • 1*micro USB type B
  • 1*togle switch SMD
  • 1*3mm Red LED
  • 1*3mm Green LED
  • 2*T-Block 2 PIN
  • 1*Transistor BC847 SMD
  • 1*Transistor BC857 SMD
  • 2*Push Button TS342A4P SMD
  • 4*Capacitor 100n SMD
  • 2*Elcap 100u SMD
  • 12*Resistor 10k SMD
  • 1*Resistor 0R1 SMD
  • 1*Resistor 1k SMD
  • 1*Capacitor 1n SMD
  • 1*Diode 4148 SMD
  • 1*IC LM1117 SMD


I have also provided a Bill of Materials along with the installation location in the csv file below

Step 1: PCB Schematic and Layout

The electronic schematic and PCB design of this DC Power Meter / Logger can be seen in the image above. I used the free version of the Eagle application to make it.

To manufacture electronic modules with industrial quality. I am addicted to PCBWay service to print this PCB DC Power Meter / Logger. Because by making PCB on PCBway you can get High Quality 10 PCs PCBs for only $ 5 & new member First order Free: www.pcbway.com

For those who want to print the PCB, I have provided a gerber file which you can download at the following link: Gerber File

If anyone needs a schematic (.sch) and PCB layout (.brd) file, you can download it at the following link: coming soon

Step 2: Insert Components Into PCB

Insert the components one by one according to the diagram on the PCB. I suggest to install SMD components first. after that install components that have a larger size. for components with large sizes such as OLED, Relay and rotary can be installed last.

Step 3: Flash Firmware Test

After all the components are installed, it is necessary to do some tests to find out whether the hardware that has been made can function properly. The tests I did included:

  1. Test flash: to find out that the hardware can be loaded with the program
  2. [picture 1] Rotary encoder test: to find out whether the rotary encoder is working or not
  3. [picture 2] OLED test: to find out if OLED can display images / text
  4. [picture 3] Relay Test: to find out if the Relay can be ON / OFF
  5. [picture 4] INA219 Sensor Test: to find out if the sensor can measure voltage and current

The program for each test can be seen on the following link: coming soon

Step 4: Ubidots Configurastion

To store (logger) sensor measurement data, I use a service from Ubidots via MQTT. You can visit the website via the following link: Ubidots

Ubidots is an Internet of Things (IoT) platform and data solution for collecting, analyzing, and visualizing data from various connected IoT devices. For the free version, you can use it for two devices.

To connect to Ubidots, I use the MQTT protocol. to configure MQTT to Ubidots the following are the parameters needed:

  1. Ubidots Token (MQTT username) : [picture 1]
  2. Ubidots MQTT Server : "industrial.api.ubidots.com"
  3. PORT : "1883"

For data formats and MQTT topics, see the reference API provided by Ubidots at the following linkt : LINK

Step 5: Flash Firmware DC Power Meter

If each piece of hardware is functioning properly. now proceed to the DC Power Meter Flash firmware stage. As I said in the introduction that this tool is not completely finished. With this firmware, DC Power Meter / Logger can only send voltage, current, power and capacity data to the ubidots web service at selectable intervals. for more complete results can be seen later in step 9: Logger Results At Ubidots.

I made the firmware using the Arduino Framework and I wrote the program using the IO platform in VS Code.


The firmware section that needs to be adjusted is the Wifi setup and Ubidots Configuration section, here is an example:

const char* ssid = "your-SSID";
const char* password = "your-Pass-SSID";
const char* mqtt_server = "industrial.api.ubidots.com";
const char* port = "1883";
const char* token = "your-Ubidots-Token";


For the Arduino library used is as follows:

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_INA219.h>
#include "AiEsp32RotaryEncoder.h"
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <string.h>


Make sure all libraries are added first so the program can work

Firmware can be downloaded on my github page : LINK



Step 6: Configuration

Examples of using this device are:

  1. Used to measure and logger battery charging process
  2. Used to measure and logger the battery discharge process

Description of installation configuration diagrams for each application

  1. [figure 1] : configuration diagram for the battery charger process. The "SUPPLY" connector is connected to the Power supply while the "BEBAN (LOAD)" connector is connected to the Battery
  2. [figure 2] : configuration diagram for the battery discharge process. The "SUPPLY" connector is connected to the Battery while the "BEBAN (LOAD)" connector is connected to Lights or other loads.

Step 7: Device Installation

Install according to the configuration you want to use. use a screwdriver (-) to loosen and tighten the connector bolts.

Step 8: Device Setup

The following is the setup for operating the DC Power Meter:

  1. Turn on the device by moving the switch
  2. Certain words will appear, at this stage the device is in the process of connecting to Wifi and MQTT Server
  3. After the page changes to "INPUT PARAMETERS", it means the device is connected.
  4. Then press the rotary button once
  5. Select the duration of the data transmission interval then press the rotary button again
  6. The relay will turn on and the OLED will display the results of measuring voltage, current, power and capacity.

the interval for sending data to Ubidots adjusts to the selected duration

Step 9: Logger Results at Ubidots

The measurement results sent to Ubidots can be seen in the image above

Step 10: Conclusion

conclusion :

1. The device is functioning properly

2. Existing features are as needed


constraint :

1. In the process of using it, sometimes after the switch is ON, the device can't work. characterized by OLED that displays nothing


Improvements to be made:

1. add features

2. Overcoming the problem of the device not working