sagar saini
Published © GPL3+

I Made a 30W Digitally Controlled Electronic Load

This is the second version of my electronic load, it has a PID controller and web interface, we can control the load digitally upto 30W.

IntermediateFull instructions provided5 hours132
I Made a 30W Digitally Controlled Electronic Load

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1

Software apps and online services

NextPCB
Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

GERBER

BOM

PICK AND PLACE (CPL)

Schematics

Circuit diagram

Code

Code for ELOAD v3

Arduino
// PID controller will be updated soon

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char* ssid = "OPPO A15s";
const char* password = "987654321v";

ESP8266WebServer server(80);

/* ---------- HARDWARE ---------- */
const int pwmPin = 4;     // GPIO4 (D2)
const int PWM_MAX = 261;

/* ---------- CALIBRATION ---------- */
float CAL_SLOPE = 0.00885;   // A per PWM (TWEAK THIS)

/* ---------- STATE ---------- */
bool loadEnabled = false;
float setCurrentA = 0.0;
int pwmValue = 0;

/* ---------- APPLY PWM ---------- */
void applyLoad() {
  if (!loadEnabled) {
    pwmValue = 0;
  } else {
    pwmValue = (int)(setCurrentA / CAL_SLOPE);
    pwmValue = constrain(pwmValue, 0, PWM_MAX);
  }
  analogWrite(pwmPin, pwmValue);
}

/* ---------- WEB PAGE ---------- */
String webPage() {
  String html = R"rawliteral(
<!DOCTYPE html><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{font-family:Arial;text-align:center;margin-top:20px;}
h2{color:#333;}
button{font-size:16px;padding:10px 14px;margin:4px;}
input[type=range]{width:80%;}
.toggle{font-size:18px;}
</style>
</head>
<body>

<h2>ELECTRONIC LOAD V3</h2>

<p>Status: <b><span id="state">OFF</span></b></p>
<button class="toggle" onclick="toggle()">ON / OFF</button>

<hr>

<p>Set Current: <b><span id="cur">0.00</span> A</b></p>

<input type="range" id="slider" min="0" max="2.3" step="0.01"
       oninput="setCurrent(this.value)">

<hr>

<button onclick="preset(0.1)">100 mA</button>
<button onclick="preset(0.25)">250 mA</button>
<button onclick="preset(0.5)">500 mA</button><br>
<button onclick="preset(1.0)">1 A</button>
<button onclick="preset(1.5)">1.5 A</button>
<button onclick="preset(2.0)">2 A</button>

<script>
function updateUI(s){
  document.getElementById("cur").innerHTML = s.current.toFixed(2);
  document.getElementById("slider").value = s.current;
  document.getElementById("state").innerHTML = s.on ? "ON" : "OFF";
}

function refresh(){
  fetch("/state").then(r=>r.json()).then(s=>updateUI(s));
}

function setCurrent(v){
  fetch("/set?i="+v).then(refresh);
}

function preset(v){
  fetch("/set?i="+v).then(refresh);
}

function toggle(){
  fetch("/toggle").then(refresh);
}

refresh();
</script>

</body></html>
)rawliteral";
  return html;
}

/* ---------- HANDLERS ---------- */
void handleRoot() {
  server.send(200, "text/html", webPage());
}

void handleSet() {
  if (server.hasArg("i")) {
    setCurrentA = server.arg("i").toFloat();
    setCurrentA = constrain(setCurrentA, 0.0, 2.3);
    applyLoad();
  }
  server.send(200, "text/plain", "OK");
}

void handleToggle() {
  loadEnabled = !loadEnabled;
  applyLoad();
  server.send(200, "text/plain", "OK");
}

void handleState() {
  String json = "{";
  json += "\"current\":" + String(setCurrentA, 3) + ",";
  json += "\"on\":" + String(loadEnabled ? "true" : "false") + ",";
  json += "\"pwm\":" + String(pwmValue);
  json += "}";
  server.send(200, "application/json", json);
}

/* ---------- SETUP ---------- */
void setup() {
  Serial.begin(115200);
  pinMode(pwmPin, OUTPUT);
  analogWrite(pwmPin, 0);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(300);

  server.on("/", handleRoot);
  server.on("/set", handleSet);
  server.on("/toggle", handleToggle);
  server.on("/state", handleState);
  server.begin();
}

/* ---------- LOOP ---------- */
void loop() {
  server.handleClient();
}

Credits

sagar saini
97 projects • 100 followers
I am Sagar Saini an electronic hardware enthusiast

Comments