Categories

CMIS-1 Test Code CT Clamp

WIKI:

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 serial monitor.  Each loop the RED LED will flash.  If a value is read, the GREEN 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 (ditronix.net)
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 Serial Print)
.
Remember!
– 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> // https://github.com/openenergymonitor/EmonLib
#include <driver/adc.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;

void setup() {

// Stabalise
delay(250);

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

// 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);
analogReadResolution(ADC_BITS);

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

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;

// Optional to Filter out the noise, adjust as needed
if (Amps > 0.20) {
// Update the display
Serial.print((int)Watts);
Serial.print(” W “);
Serial.print(Amps);
Serial.println(” A”);

Serial.println(“\n- – – – – – – – – – – – – – – – – – – -“);

// Flash LED
digitalWrite(LED_Green, LOW);
delay(50);
digitalWrite(LED_Green, HIGH);
}

// Heatbeat LED
digitalWrite(LED_Red, LOW);
delay(50);
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.