Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created July 5, 2025 17:07
Show Gist options
  • Save maxpromer/19b48daa94ce955393316b708c9e2f79 to your computer and use it in GitHub Desktop.
Save maxpromer/19b48daa94ce955393316b708c9e2f79 to your computer and use it in GitHub Desktop.
Example code for AS-Energy
#include "MCM_BL0940.h"
BL0940 bl0940;
void setup() {
Serial.begin(115200);
bl0940.begin(Serial1, 25, 26); // RX, TX pin
bl0940.Reset();
bl0940.setFrequency(50); // 50[Hz]
bl0940.setUpdateRate(800); // 400[ms]
}
void loop() {
float voltage;
bl0940.getVoltage( &voltage );
Serial.printf("%.2f [V]\n", voltage );
float current;
bl0940.getCurrent( &current );
Serial.printf("%.4f [A]\n", current );
float activePower;
bl0940.getActivePower( &activePower );
Serial.printf("%.2f [W]\n", activePower );
float activeEnergy;
bl0940.getActiveEnergy( &activeEnergy );
Serial.printf("%.6f [kWh]\n", activeEnergy );
float powerFactor;
bl0940.getPowerFactor( &powerFactor );
Serial.printf("%.1f [%%]\n", powerFactor );
float temperature;
bl0940.getTemperature( &temperature );
Serial.printf("%.1f [deg C]\n", temperature );
Serial.println("");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment