SO I have this Zk -5KX dc dc buck boost convertor and I want to configure it via Arduino. I have a Arduino UNO. Now I also want to set parameter, Swtich off and ON the buck boost via arduino. Up until now I am successfull in connecting it and also reading from it But I am not able to set anything or configure anything. I am attaching the code here. Could anyone help me out in this? Thank you
include <SoftwareSerial.h>
// Define UART pins for ZK-5KX connection (adjust based on your Arduino)
// If using an Arduino Mega/Every/Leonardo, prefer using Serial1 hardware pins instead!
SoftwareSerial ZKSerial(10, 11, true); // RX, TX
// --- BATTERY CHARGING PROFILE VALUES (12V Exide Flooded Tabular) ---
const float ABS_VOLTAGE_TARGET = 14.40; // Absorption/Bulk max limit (Volts)
const float FLOAT_VOLTAGE_TARGET = 13.80; // Trickle/Float maintenance voltage (Volts)
const float MAX_SAFE_CURRENT = 4.500; // Constrained to 4.5A to protect the 80W module
const float FLOAT_TRIGGER_CURRENT = 0.500; // Drop to float when current falls below 500mA in CV mode
// --- SYSTEM STATE TIMERS ---
unsigned long lastQueryTime = 0;
const unsigned long queryInterval = 2000; // Query module every 2 seconds
enum ChargeState { BULK_ABSORPTION, FLOAT, FAULT };
ChargeState currentMode = BULK_ABSORPTION;
void setup() {
Serial.begin(9600); // Debug output to PC
ZKSerial.begin(9600); // Interface connection to ZK-5KX module
delay(1000);
Serial.println("--- Exide 6SBZ150 Smart Charger Initializing ---");
// 1. Establish structural safety limits on the module first
setChargingParameters(ABS_VOLTAGE_TARGET, MAX_SAFE_CURRENT);
// 2. Power up the charging rail
sendZKCommand("ON");
}
void loop() {
// Non-blocking telemetry evaluation loop
if (millis() - lastQueryTime >= queryInterval) {
lastQueryTime = millis();
// Request current stats from module
sendZKCommand("STATUS");
// Read and print telemetry feedback
handleTelemetry();
}
}
// Function to calculate and update parameters over UART runtime
void setChargingParameters(float voltage, float current) {
char vCmd[16];
char iCmd[16];
// Format variables cleanly to match ZK ASCII requirements (e.g. V14.40)
dtostrf(voltage, 4, 2, vCmd);
dtostrf(current, 5, 3, iCmd);
String finalVCmd = "V" + String(vCmd);
String finalICmd = "I" + String(iCmd);
sendZKCommand(finalVCmd);
delay(150); // Small delay to let the buffer process safely
sendZKCommand(finalICmd);
Serial.print("[CONFIG] Targets updated -> ");
Serial.print(finalVCmd); Serial.print(" | "); Serial.println(finalICmd);
}
// Low-level sender appending required standard terminations
void sendZKCommand(String command) {
ZKSerial.print(command + "\r\n");
}
// Process incoming feedback from the buck-boost unit
void handleTelemetry() {
String response = "";
while (ZKSerial.available()) {
char c = ZKSerial.read();
response += c;
delay(2); // Wait briefly for full string generation
}
if (response.length() > 0) {
response.trim();
Serial.print("\[TELEMETRY\]: ");
Serial.println(response);
// Simple state-machine parser for Bulk vs Float transition
// Standard status format: "XX.XXV X.XXXA XX.XXW"
if (response.indexOf('V') > 0 && response.indexOf('A') > 0) {
float currentVoltage = response.substring(0, response.indexOf('V')).toFloat();
// Isolate current chunk
int spaceIdx = response.indexOf(' ') + 1;
float currentAmps = response.substring(spaceIdx, response.indexOf('A')).toFloat();
// Logical check for state switching
if (currentMode == BULK_ABSORPTION && currentVoltage >= (ABS_VOLTAGE_TARGET - 0.1) && currentAmps <= FLOAT_TRIGGER_CURRENT) {
Serial.println("\[STATE CHANGE\]: Battery Full. Dropping to Float Mode.");
currentMode = FLOAT;
setChargingParameters(FLOAT_VOLTAGE_TARGET, 1.000); // Reduce current ceiling for safety float
}
}
// Emergency hardware alert parsing
else if (response.indexOf("OVP") >= 0 || response.indexOf("OCP") >= 0 || response.indexOf("OTP") >= 0) {
Serial.println("\[ALERT ERROR\]: Hardware fault flagged by ZK module!");
currentMode = FAULT;
}
}
}
