atomberg1 — ESP32 simulation

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

Components

Sketch code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define SLIDE_POT   34
#define CURR_PIN    32
#define LED_PIN     14
#define BUZZER_PIN  12

#define DRV_ADDR      0x14
#define CMD_CW        0x02
#define CMD_STOP      0x01
#define CMD_NOT_STBY  0x05
#define MOTOR_CHA     0

// CURRENT BASED OVERLOAD - YOUR REQUIREMENT
#define CURRENT_NORMAL_MAX  2.5  // 0 - 2.5A = Normal
#define CURRENT_OVERLOAD    2.5  // >2.5A = Overload
#define CURRENT_RESET       2.3  // Back to <2.3A = Normal (hysteresis)

int holdLoad = 0;
bool driverOk = false;
bool isOverload = false;
bool buzzerOn = false;

bool i2cExists(byte addr){ Wire.beginTransmission(addr); return Wire.endTransmission()==0; }
void driverCmd(uint8_t cmd, uint8_t ch, uint8_t spd){ Wire.beginTransmission(DRV_ADDR); Wire.write(cmd); Wire.write(ch); Wire.write(spd); Wire.endTransmission(); }
void fanRun(int speed){ speed=constrain(speed,0,100); if(speed==0) driverCmd(CMD_STOP,MOTOR_CHA,0); else driverCmd(CMD_CW,MOTOR_CHA,speed); }
void fanStop(){ driverCmd(CMD_STOP,MOTOR_CHA,0); }

void setup(){
  Serial.begin(115200);
  Wire.begin(21,22);
  lcd.init(); lcd.backlight();
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(CURR_PIN, INPUT);
  if(i2cExists(DRV_ADDR)){ driverOk=true; driverCmd(CMD_NOT_STBY,0,1); driverCmd(CMD_NOT_STBY,1,1); fanStop(); }
  lcd.print("QuietGrind Ready"); delay(1000); lcd.clear();
}
int readSmooth(int pin){ long sum=0; for(int i=0;i<20;i++){ sum+=analogRead(pin); delay(2);} return sum/20; }

void loop(){
  int adcValue = readSmooth(SLIDE_POT);
  int loadPercent = map(adcValue, 0, 4095, 0, 100);
  if(abs(loadPercent - holdLoad) > 2) holdLoad = loadPercent;
  holdLoad = constrain(holdLoad, 0, 100);

  // CURRENT CALCULATION - 0 to 3.5A range
  // In real hardware: read from CURR_PIN
  // int currRaw = readSmooth(CURR_PIN);
  // float current = map(currRaw, 0, 4095, 0, 500) / 100.0; // 0-5A
  // For Wokwi simulation - current based on load:
  float current = 0.20 + (holdLoad * 0.03); // 0.2A at 0% , 3.2A at 100%
  
  int rpm = map(holdLoad, 0, 100, 0, 2900);

  // ===== CURRENT OVERLOAD DETECTION =====
  if(!isOverload && current > CURRENT_OVERLOAD){
    isOverload = true;
    Serial.print("OVERLOAD! Current: "); Serial.print(current); Serial.println("A > 2.5A");
  }

  if(isOverload){
    fanStop();
    digitalWrite(LED_PIN, HIGH);
    if(!buzzerOn){ tone(BUZZER_PIN, 1000); buzzerOn = true; }

    lcd.setCursor(0,0); lcd.print("OVERLOAD! ");
    lcd.setCursor(0,0); lcd.print("I:"); lcd.print(current,1); lcd.print("A >2.5A!    ");
    lcd.setCursor(0,1); lcd.print("MOTOR STOPPED   ");

    // AUTO RESET WHEN CURRENT BACK TO NORMAL <2.3A
    if(current < CURRENT_RESET){
      isOverload = false;
      noTone(BUZZER_PIN);
      buzzerOn = false;
      digitalWrite(LED_PIN, LOW);
      lcd.clear();
      Serial.println("Normal: Current <2.3A - Buzzer OFF");
    }
    delay(150);
    return;
  }

  // NORMAL - 0A to 2.5A
  if(buz

More projects by swethanpinjala8