Turn a Current Sensor into a Remote Power Tracker – A DIY Guide

Ever wondered how much power your coffee maker really sips while you’re scrolling through memes? I did, and that curiosity sparked a tiny project that now lets me see the exact draw of any plug‑in device from my phone. If you’ve got a current sensor lying around and a bit of soldering patience, you can build a remote power tracker in an afternoon. Let’s walk through it step by step.

Why a Remote Power Tracker Matters

Most of us look at the electricity bill and shrug. The numbers are there, but we have no clue which gadget is the culprit. A remote power tracker gives you real‑time data, so you can spot energy hogs, trim waste, and maybe even lower that monthly cost. Plus, it’s a neat way to learn about IoT, sensors, and a dash of cloud work—all without buying a pricey commercial unit.

What You’ll Need

Hardware

  • Current sensor – I used a cheap ACS712 5A module. It outputs a voltage proportional to the current flowing through the wire.
  • Microcontroller – An ESP‑32 works great because it has Wi‑Fi built in and plenty of pins.
  • Breadboard and jumper wires – For quick prototyping.
  • Power supply – 5 V USB or a small wall wart.
  • A plug‑in device – Anything from a lamp to a phone charger.
  • A small enclosure – Optional, but it keeps the project tidy.

Software

  • Arduino IDE – To flash code onto the ESP‑32.
  • MQTT broker – I use the free public broker at test.mosquitto.org.
  • Dashboard – A simple web page or a mobile app like MQTT Dashboard can subscribe to the data.

Step 1: Wire the Current Sensor

The ACS712 has three pins: VCC, GND, and OUT. Connect VCC to the 5 V rail on the breadboard, GND to ground, and OUT to one of the ESP‑32’s analog inputs (GPIO34 works well). The sensor also needs the wire you want to measure to pass through its hole. Cut the live (hot) wire of your device’s power cord, strip the ends, and thread them through the sensor’s opening. Make sure the connections are solid; a loose wire will give erratic readings.

Step 2: Set Up the ESP‑32

Plug the ESP‑32 into the breadboard and connect its 5 V and GND pins to the same rails as the sensor. Hook up the USB cable to your computer – this powers the board and lets you upload code.

Step 3: Write the Firmware

Open the Arduino IDE and install the ESP32 board package if you haven’t already. Then paste the sketch below. It reads the analog voltage, converts it to current, calculates power (assuming you know the voltage of your mains, usually 120 V or 230 V), and publishes the result via MQTT.

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid     = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

const char* mqtt_server = "test.mosquitto.org";
const int   mqtt_port   = 1883;
const char* mqtt_topic  = "techpulse/power";

WiFiClient espClient;
PubSubClient client(espClient);

const int sensorPin = 34;          // analog input
const float Vref = 3.3;            // ESP32 ADC reference voltage
const float sensorSensitivity = 0.185; // V/A for ACS712 5A version
const float mainsVoltage = 120.0; // change to 230 if needed

void setupWifi() {
  delay(10);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void reconnect() {
  while (!client.connected()) {
    if (client.connect("PowerTracker")) {
      // nothing to subscribe
    } else {
      delay(2000);
    }
  }
}

void setup() {
  Serial.begin(115200);
  setupWifi();
  client.setServer(mqtt_server, mqtt_port);
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  int raw = analogRead(sensorPin);
  float voltage = (raw / 4095.0) * Vref;          // convert ADC reading to voltage
  float current = (voltage - Vref/2) / sensorSensitivity; // sensor outputs Vref/2 at 0 A
  if (current < 0) current = 0;                  // ignore negative values

  float power = current * mainsVoltage;           // simple P = I * V

  char payload[50];
  snprintf(payload, sizeof(payload), "{\"current\":%.2f,\"power\":%.1f}", current, power);
  client.publish(mqtt_topic, payload);

  delay(2000); // publish every 2 seconds
}

A few notes:

  • The ACS712 outputs half the supply voltage (about 2.5 V) when no current flows. That’s why we subtract Vref/2.
  • The sensor’s sensitivity (0.185 V/A for the 5 A version) is printed on the module’s label.
  • If you’re measuring a 230 V system, just change mainsVoltage to 230.

Step 4: Test the Setup

Power the ESP‑32, then plug the device you want to monitor into the sensor‑wrapped cord. Open the Serial Monitor – you should see current and power values scrolling every two seconds. If the numbers look wild, double‑check the wiring and make sure the sensor’s hole is fully occupied by the live wire.

Step 5: Visualize the Data

Now that the ESP‑32 is publishing JSON payloads to the MQTT broker, you can pull them into any dashboard. I like to use a simple HTML page with the Paho MQTT JavaScript client:

<!DOCTYPE html>
<html>
<head>
  <title>Power Tracker</title>
</head>
<body>
  <h2>Live Power Consumption</h2>
  <div id="data">Waiting for data...</div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/mqtt.min.js"></script>
  <script>
    var client = new Paho.MQTT.Client("test.mosquitto.org", 8080, "webclient");
    client.onMessageArrived = function(msg) {
      document.getElementById('data').innerText = msg.payloadString;
    };
    client.connect({onSuccess: function() {
      client.subscribe("techpulse/power");
    }});
  </script>
</body>
</html>

Save it, open it in a browser, and watch the numbers update as you turn the device on and off. You can also set up alerts – for example, if power spikes above a threshold, send a push notification to your phone.

Step 6: Put It in a Box

A tidy enclosure makes the tracker look less like a lab experiment and more like a finished gadget. Drill a small hole for the power cord, mount the ESP‑32 and sensor inside, and seal everything with hot glue. I used a small project box from a hobby store; it fits nicely on a shelf next to my router.

Tips and Tricks

  • Calibration – The sensor’s output can drift a bit. Measure a known load (like a 60 W bulb) and adjust the sensorSensitivity value in the code until the reported power matches.
  • Safety first – You’re dealing with mains voltage. Keep the live wire insulated, and never work on the circuit while it’s plugged in.
  • Multiple sensors – Want to track several devices? Add more ACS712 modules on separate analog pins and publish each as a separate MQTT topic.
  • Battery power – If you want the tracker to be portable, power the ESP‑32 with a Li‑Po cell and add a step‑up converter for the sensor’s 5 V.

What I Learned

Building this tracker reminded me why I love tinkering: a handful of cheap parts can give you insight into something as invisible as electricity. It also showed how easy it is to bridge hardware and cloud services with just a few lines of code. The best part? Seeing the coffee maker’s power dip to almost nothing when I brew a cold brew instead of a hot cup. Small changes add up, and now I have the data to prove it.

Reactions