CMIS-1 Test Code Calibrate DC SensorZeroVoltage


CMIS (Current Monitor IoT Sensors), SDK Kit is based on an Espressif ESP32 WROOM and the board has four AC/DC ACS758 100A (ACS758LCB-100B-PFF-T), Hall Effect based, Linear Current Sensors.

These bi-directional current sensors will read +/- 100A and have a sensitivity of typically 20mV/A.


The example code below will enable you to calibrate the DC SensorZeroVoltage for each current sensor.  This value is then used in the CMIS-1 Test Code CT Clamp with OLED Display

As the sensor can read +/- current, but the output remain DC positive for zero current, the output will sit centre around 50% of VCC which is 5V, so the expected zero current voltage will be 2.5V.  As we are using the ESP32 ADC, we need to reduce 5V to a maximum of 3.3V and to do this a simple potential divider (10K and 18K), is included on the sensor output.  Our Zero current voltage will now be based on around 3.3V / 2 = 1.65V.

The reason for 3.2V and not 3.3V, is that the ESP32 ADC is reported not to be quite linear at the top end.  This means that the ESP32 is not able to distinguish 3.2 V from 3.3 V and you may get the same ADC value for both voltages.  Our input voltage range is based on 0 to 3.2V and using the ESP32 12 bit ADC, this will output a value of  0 – 4095.

Remember, you must power the SDK from an external DC power source, when measuring current.

Other useful advanced ESP32 ADC functions are listed here


Example Arduino code below.

Dave Williams, DitroniX 2019-2022 (
CMIS-1 Current Monitor IoT Sensors v1.0
Features include ESP32 MODBUS EEPROM CT Clamp Multi-Current Voltage
PCA v1.00 – Test Code Firmware v1 – 9th September 2022

Simplified Board Bring Up Test – Calibrate DC Current Sensor SensorZeroVoltage
– Set the BOARD to ESP32 DEV Module (or similar).
– You can also set the BAUD rate up to 921600 to speed up flashing.
– The SDK does NOT need external power to flash. It will take Power from the USB 5V.
– You MUST power the SDK from an external DC power source, when measuring current.
– You can have the USB and external DC power connected at the same time.
Note that in the default state, upon first power up and during reset, the Green LED will be partially lit. Once programmed and the GPIO defined, the Green LED will go off after power up.
The purpose of this test code is to cycle through the various main functions of the board as part of bring up testing.
This test code is OPEN SOURCE and although is is not intended for real world use, it may be freely used, or modified as needed.
It is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

// **************** VARIABLES / DEFINES / STATIC ****************

// Constants
const int LoopDelay = 1; // Loop Delay in Seconds

// Variables
float SensorRatioFactor = 0.0132;// 20mV/A is the factor @ 5V
float ADCFactorVoltage = 3.3 / 4095.0; // 0.0008058
float SensorZeroVoltage;
float SensorVoltage;
float SensorCalculatedCurrent;
int CurrentSensor;

// **************** INPUTS ****************
#define Current_1 35 //GPIO 35 (Analog ADC1_CH7)
#define Current_2 32 //GPIO 32 (Analog ADC1_CH4)
#define Current_3 33 //GPIO 33 (Analog ADC1_CH5)
#define Current_4 27 //GPIO 27 (Analog ADC2_CH7)

void setup() {
// Stabalise

// Initialise UART:
Serial.begin(115200, SERIAL_8N1); //115200
while (!Serial);

// Setup Current Sensor Channel
CurrentSensor = Current_1; // Change channel as needed

void loop() {

// Run this code with 0A flowing. Note SensorZeroVoltage and update the variable. Retest under current.

// Raw ADC Output
Serial.print(“ADC Raw: “);

// Read the average voltage from sensor and then calculate SensorZeroVoltage @ 0A
SensorZeroVoltage = ADCFactorVoltage * analogRead(CurrentSensor);
Serial.print(“\tZero Current Voltage: “);
Serial.print(SensorZeroVoltage, 3);

//Place Average Zero Voltage Here (from SensorZeroVoltage @ 0A)
SensorZeroVoltage = 1.484; //
Serial.print(“\tSensorZeroVoltage: “);
Serial.print(SensorZeroVoltage, 3);

// Calculate SensorVoltage Reading
SensorVoltage = ADCFactorVoltage * analogRead(CurrentSensor);
SensorVoltage = SensorVoltage – SensorZeroVoltage;
Serial.print(“\t\tV: “);
Serial.print(SensorVoltage, 3);

// Calculate Sensor Current Based on Calculation
SensorCalculatedCurrent = SensorVoltage / SensorRatioFactor;
Serial.print(“\tI: “);
Serial.print(SensorCalculatedCurrent, 2); Serial.println(“A”);

// Loop Delay
delay(LoopDelay * 1000);



Important Foot Note.

These Wiki pages are MOVING to the GitHub Wiki.   Simply select a repository pertaining to the board and click Wiki.


Other Details

Further information on this product may be found in our downloads and Wiki pages.  Other technical information and code examples are also shared in our GitHub Pages.  Project information may also be found on

We value our customers and should you have any other questions, please feel free to contact us.

Leave a Reply

This site uses User Verification plugin to reduce spam. See how your comment data is processed.