CMIS-1 Test Code CT Clamp with OLED Display


CMIS (Current Monitor IoT Sensors), SDK Kit is based on an Espressif ESP32 WROOM and the board has a CT Clamp Input.

The example code will read a voltage from the CT Current Clamp (or Current Transformer), and output to the OLED Display.  Each loop the RED LED will flash.

Note, depending on your CT Clamp, it may, or not, have a Burden resistor included.  This Burden resistor is connected across the CT Clamp output in order to produce a voltage output which is proportionate to the current flowing through the clamp.  This voltage is what the ADC in the ESP32 uses to measure current flow.

The CMIS board has a solder jumper next to the CT 3.5mm socket.  For the most part when using CT clamps such as the commonly used Blue SCT013 (Typical input up to 100A), you WILL need to solder this pad (shorting the link), as shown below.

Further reading on Current Transformers.


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 – 2nd September 2022

Simplified Board Bring Up Test – CT Clamp (Output sent to the OLED Display)
– 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.
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.

// Libraries
#include <EmonLib.h> //
#include <driver/adc.h>
#include <GyverOLED.h>

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

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

// Variables
double Irms;

// **************** OUTPUTS ****************
#define LED_Red 2 // Red LED
#define LED_Green 4 // Green LED

// **************** INPUTS ****************
#define CT_IN 34 //GPIO 34 (Analog ADC1_CH6)

// Force EmonLib to use 1bit ADC resolution
#define ADC_BITS 12
#define ADC_COUNTS (1<<ADC_BITS)
#define Home_Voltage 249.0
#define emonTxV3 //Force the library to use 3v3 as supply voltage

// EnergyMonitor Instance.
EnergyMonitor emon1;

// OLED Instance. You will need to select your OLED Display.
// Uncomment/Comment as needed.
GyverOLED<SSD1306_128x32, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x32, OLED_NO_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_BUFFER> oled;
//GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
//GyverOLED<SSH1106_128x64> oled;

void setup() {

// Stabalise

// LEDs
pinMode(LED_Red, OUTPUT);
pinMode(LED_Green, OUTPUT);

// LEDs Default Off State
digitalWrite(LED_Red, HIGH);
digitalWrite(LED_Green, HIGH);

adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_11);

// Initialize emon library (30 = calibration number, adjust as needed)
emon1.current(CT_IN, 23.50);

oled.setCursor(18, 0);

// Draw Battery
void drawBattery(byte percent) {
for (byte i = 0; i < 100 / 8; i++) {
if (i < (100 – percent) / 8) oled.drawByte(0b10000001);
else oled.drawByte(0b11111111);

void loop() {

// Calculate Irms only, adjust as needed
double Amps = emon1.calcIrms(1676); //5588, adjust as needed

// Calculate Watts (Power)
double Watts = Amps * Home_Voltage;

// May be useful to filter out below preset wattage

oled.setCursor(0, 0);
oled.println(” W”);
drawBattery(Watts / 10);

// Heatbeat LED
digitalWrite(LED_Red, LOW);
digitalWrite(LED_Red, HIGH);

// Loop Delay
delay(LoopDelay * 1000);


Leave a Reply

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