test — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by padma_sri.

Components

Sketch code

#define POT3 34
#define SWITCH_PIN 26
#define FLEX_LED 27
#define ESSENTIAL_LED 25

// Simulated power values
const int MAX_POWER = 4000;
const int ESSENTIAL_POWER = 1000;
const int FLEXIBLE_POWER = 1500;
const int POWER_RESERVE = 500;

void setup() {
  Serial.begin(115200);

  pinMode(SWITCH_PIN, INPUT_PULLUP);
  pinMode(FLEX_LED, OUTPUT);
  pinMode(ESSENTIAL_LED, OUTPUT);

  digitalWrite(ESSENTIAL_LED, HIGH);

  Serial.println("SHEMS Energy Management Started");
}

void loop() {

  // Read flexible load switch
  bool flexibleON = (digitalRead(SWITCH_PIN) == LOW);

  // Read EV demand from POT3
  int potValue = analogRead(POT3);

  int evPower;
  String demand;

  // Classify EV demand
  if (potValue <= 1364) {
    demand = "LOW";
    evPower = 1000;
  }
  else if (potValue <= 2729) {
    demand = "MEDIUM";
    evPower = 2000;
  }
  else {
    demand = "HIGH";
    evPower = 3000;
  }

  // Flexible load indication
  digitalWrite(FLEX_LED, flexibleON ? HIGH : LOW);

  // Calculate available power
  int flexiblePower = flexibleON ? FLEXIBLE_POWER : 0;

  int availablePower = MAX_POWER
                     - ESSENTIAL_POWER
                     - flexiblePower
                     - POWER_RESERVE;

  // EV charging decision
  bool evCharging = false;

  if (!flexibleON && availablePower >= evPower) {
    evCharging = true;
  }

  // Display information
  Serial.println("-----------------------");

  Serial.print("Flexible Load: ");
  Serial.println(flexibleON ? "ON" : "OFF");

  Serial.print("EV Demand: ");
  Serial.println(demand);

  Serial.print("EV Required Power: ");
  Serial.print(evPower);
  Serial.println(" W");

  Serial.print("Available Power: ");
  Serial.print(availablePower);
  Serial.println(" W");

  Serial.print("EV Charging: ");
  Serial.println(evCharging ? "ON" : "OFF");

  delay(1000);
}

More projects by padma_sri