Wind genenerator shunt controller

hi there not sure if anyone be interested. but here an sketch for wind generator shunt controller.

it is voltage adjustable . it set to work with both normally closed SSRs and normally opened SSRs. but the preferred is normally closed . that way if power is lost to the controller it automatically brakes the wind generator. I am dumping into to my hotwater buffer tanks. I have my 48v 4k wind gen connected to grid tie inverters, but with climate change my wind speeds have dropped dramatically . to compensate I dropped my inverters to 22-45 volt inverters from 44- 90volt . so the kick in voltage is much lower . which effectively halved the maximum power output of my wind generator. as the blade spin slower and can never get up to full speed.. but I gain power production and I produce twice as much power since it produces more power constantly at my now more common lower wind speeds .

anyways my wind GTI ( grid tie inverts) their built in shunt controls failed and I am using some normal solar GTI. this shunt control allows me to either control over voltage for the GTI’s ( by setting maximum limit) or as generally wind shunt control for the wind generator. for the winter I turned down the voltage setting to just below the start up voltage of the GTI (22v). and dumping energy into the heat buffer tank that heats my house. it working well and currently at these mildly cool temps( 5c) and cloudy with a slight breeze it enough to keep my house warm as my heat buffer tanks sit at 35C or warmer just from the wind input ( 11km/h WIND produces ~ 50 to 100watts) if I set it to the normally 44volt kick in. then I would only produce power around 18km wind speed

//based on wavgat uno and analog resolution of 4096 
//windgenerator shunt control -parts,10k and 470k resistor (voltage divider) Potentiometers ( for setting working voltage ) 30 amp current sensor (hall effect) 
// normally closed ssr (preferred) but will work with normally open ssr if you have a an gridtie inverter connected  and a  secondary brake relay installed if the power goes out.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
uint32_t runTime = -99999; 
uint32_t runTime2 = -99999;
// Define the I2C address of the LCD (0x27 is common, but check your specific LCD)
#define LCD_ADDRESS 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
//int Step =0;
float bufferV =0;
float bufferC =0;
int cnt =0;
int pulse =0;
int pulse2nd =0;
// Define the analog pins
const int voltagePin = A0;  // Pin for reading voltage
const int currentPin = A1;  // Pin for reading current
const int configPin = A2;  //pin for Potentiometers to set working voltage
// Define the relay pins
const int relay1Pin = 6; // Relay to trigger at working overvoltage / normally open ssr
const int relay2Pin = 7; // Relay to trigger at working / normally open ssr
const int relay3Pin = 5; // Relay to trigger at working / normally closed ssr


// Function to read voltage from the analog pin
float readVoltage() {
    int analogValue = analogRead(voltagePin); // Read the analog value  voltage divider 10k and 440k maximum voltage 230 volts 
    return (analogValue * (231 / 4095.0));
  
}

float readconfig() {
    int analogValue = analogRead(configPin); // Read the analog value maximum set at 60volt for my wind generator
     float converted = map(analogValue, 0, 4095, 0,60); 
     return (converted);

}


// Function to read current from the Hall effect sensor -- 30 amp current sensor
float readCurrent() {
    int analogValue = analogRead(currentPin); // Read the analog value
     float converted = map(analogValue, 0, 4040, -3000,3000);  ///4095 was offset to 4040 to set reading at zero amps 
     return (converted/100);  // divided by 100 to get proper amperage reading

}

// Function to calculate power in watts
float calculateWattage(float voltage, float current) {
    return voltage * current; // Power (W) = Voltage (V) * Current (A)
}

LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
void setup() {
    // Initialize the LCD
    Wire.begin();
    Serial.begin(115200);
    lcd.init();
    lcd.backlight();


analogWrite(relay3Pin, 0); // makes sure normally closed ssr is  closed
    // Print initial message
    lcd.setCursor(0, 0);
    lcd.print("SHUNT");
    delay(500);
}

void loop() {
  cnt=(cnt+1);
    // Read voltage and current and put in buffer
    float voltage = readVoltage();
    bufferV= (bufferV + voltage);
    float current = readCurrent();
    bufferC = (bufferC + current);
   
    int setting = readconfig();
if (millis() - runTime >= 1000L) { // Execute every 1s
    runTime = millis();    
Serial.print("set_voltage ");Serial.println(setting);
Serial.print("instantaneous-volt  ");Serial.println(voltage);
Serial.print("instantaneous-current  ");Serial.println(current);

Serial.print("count  ");Serial.println(cnt);
 float volt = (bufferV/cnt);
 float amp = (bufferC/cnt);
 Serial.print("volt  ");Serial.println(volt);
 Serial.print("current  ");Serial.println(amp);
 cnt=0;
 bufferV=0;
 bufferC=0;
 float wattage = calculateWattage(volt, amp);
    // Display voltage, current and wattage on LCD
    lcd.setCursor(9, 0);
    lcd.print(" V:");
    lcd.print(setting);
    lcd.setCursor(0, 1);
    lcd.print("V:");
    lcd.print(volt, 0); // Print voltage with 2 decimal places
    lcd.print(" A:");
    lcd.print(amp, 0); // Print current with 2 decimal places
    lcd.print(" W:");
    lcd.print(wattage, 0); // Print wattage with 2 decimal places
    lcd.print(" ");
}
    // Control relay group 1 based on voltage
    if (voltage > setting) {
      pulse = (pulse + 1);
      if ( pulse > 254 ) { pulse = 255;}
      analogWrite(relay2Pin, pulse);
       int pulse2 = (255 - pulse);
       //Serial.print(pulse);
        analogWrite(relay3Pin, pulse2);
        if (millis() - runTime2 >= 1000L) { // Execute every 1s to print to display
        Serial.print("pulse1 "); Serial.println(pulse);  
        Serial.print("pulse2 ");Serial.println(pulse2);  
        runTime2 = millis(); 
        lcd.setCursor(5, 0);
        lcd.print(" ON ");
        }
    }else if (voltage < setting) {
      pulse = (pulse - 1 );
      if ( pulse < 0 ) { pulse = 0;}
      analogWrite(relay2Pin, pulse);
       
       int pulse2 = (255 - pulse);
        analogWrite(relay3Pin, pulse2);
        if (millis() - runTime2 >= 1000L) { // Execute every 1s
        Serial.print("pulse1 "); Serial.println(pulse);  
        Serial.print("pulse2 ");Serial.println(pulse2); 
        runTime2 = millis(); 
        lcd.setCursor(5, 0);
        lcd.print(" OFF ");
        }

    }

    // Control relay 2 based on voltage
    if (voltage > (setting + 5)) {
      pulse2nd = (pulse2nd + 1);
      if ( pulse2nd > 254 ) { pulse2nd = 255;}
      analogWrite(relay1Pin, pulse2nd);    
        if (millis() - runTime2 >= 1000L) { // Execute every 1s 
        runTime2 = millis(); 
        lcd.setCursor(14, 0);
        lcd.print(" *");
        }     
        
    } else {

          pulse2nd = (pulse2nd - 1 );
      if ( pulse2nd < 0 ) { pulse2nd = 0;}
      analogWrite(relay1Pin, pulse2nd); 
        if (millis() - runTime2 >= 1000L) { // Execute every 1s
        runTime2 = millis(); 
        lcd.setCursor(14, 0);
        lcd.print("  ");
        }
 
    }

    // Delay for stability
    //delay(5); // Delay for .005 second before next reading
}