ESP8266 Current Monitor

Basic energy monitor using the ESP8266 and the ATMega328

Similar projects worth following
As soon as I heard of the ESP8266 and how cheap it was, I immediately said "I want one" and began to come up with ideas for projects that would genuinely be useful. It just so happened that my senior year of high school required me to complete a science project, so there was the added incentive of graduating high school that led me to make the creatively-named EnergyMonitor system.

I'd dabbled around with arduinos for almost three years without ever making anything truly worthwhile. The 8266 seemed like the perfect motivator to get something made that I could actually use. I began researching just how you can sense current with an arduino, and eventually I settled on a non-invasive clip-on current sensor. Once all the parts arrived, the much more difficult task of making it all work began. This is where the project log starts.

What I wanted was simple: a small device that would measure how much current a circuit was using and send that data to a web database where it could be viewed through a web interface. It sounded simple enough at the time, but of course when you're dealing with electronics nothing works right the first time.

I always play around in EagleCAD, designing boards and hardware for things I know I'll never actually get around to making. It was just another way to pass time if I was board. Because of this, I was well prepared to lay out a simple board that connected the ATMega328P-PU chip to both the clip-on sensor and the ESP8266. It took me about 15 minutes to get a first-revision board done.

In hindsight I probably should have paid a bit more attention while making the boards. When they arrived, I noticed that I had the footprint for my voltage regulator backwards. Unfortunately, I didn't notice this until after I fried the regulator that had just taken a week to ship. After ordering six more just to be safe, I tried to think up a solution that didn't require me waiting another month to get more boards from china made.

The fix was stupidly simple. If you flipped the SO-223 package upside down, the pins aligned properly with the Vin, Vout, and GND pads. I grabbed my pliars and bent all the pins backward, and when I plugged it in this time the magic smoke stayed inside the regulator and the leds sprang to life.

Now that I had a working module, it was on to the website.

Web design was another one of my hobbies that never really went anywhere. Using the amazing highcharts system along with MySQL and javascript, I had a working graph in a day and a nice-looking interface soon afterwards. For now, the website only displays data for a single module, but I plan on changing it in the future to support an unlimited number of sensors.

Not much security has been implemented for the website at this point, as it is a local site and is not accessible from the internet. All the protection comes from the security of whatever network you are running the board on. Additionally, there is no protection implemented yet for the communication between sensor and website, and anyone on the network with a computer could very easily impersonate the sensor to send data.

For the most part, though, the website does what I need it to do. Everything in this project is still in very early testing stages and the whole thing is one big learning experience.

Of course, what's a beautiful board and website without beautiful firmware to go with it?

The firmware for the board is the youngest part of the project. While basic features like wifi communication have been fully implemented and working since the initial flashes, things like power measurement and accurate calculation of current are still barely implemented and barely functional.

The ESP8266 makes wifi communication really, super easy. I was able to get connected and communicating with the module in about five minutes, and I was able to send data to the monitor website within an hour. The ESP8266 uses AT commands for all of its communication, and unlike when I started using the module there are now heaps of different documentations for anything and everything about this module.

There are many, many things that I would love to include in this project. I keep coming up with more features, more ideas, and more things I could mess around with. The only thing stopping me is my lack of free time.

Here are a few of the planned features:

  • Encrypted/more secure module communication
  • Support for multiple modules on one web panel
  • Support for more measurement options - frequency, power factor, and voltage
  • Battery-powered version for easier setup / charging via power line?

Thanks for reading! Feel free to leave comments, suggestions, and point out anything I'm doing badly wrong.

  • 1 × Non-invasive current sensor module Or your preferred method of measuring high-voltage current without dying
  • 1 × ESP8226 The new best friend for the IoT
  • 1 × ATMega328 In any flavor you prefer
  • 1 × Board to connect everything together Like a mixing bowl for hardware
  • 1 × Webserver So you can put all your delicious data somewhere

  • Updates and Good News

    Patrick McDonnell08/15/2015 at 03:24 0 comments

    Hey all,

    Just a quickie for now, and I know I haven't posted much in a while, but I'm here to tell you that the project is not dead by any means.

    Recently I picked up working on the current monitor after an extended break to work on other projects (like my VHF radio project as well as various small projects around the house).

    Today was an especially good day. I completely overhauled the code on both the website and the device itself. It now has much more comprehensive debugging as well as a more efficient communication process with the ESP8266.

    Additionally, I wrote custom functions for reading and calculating the current (finally) and it has been tested and works well!

    Stay tuned for when I hopefully get a full writeup posted, but for now just know that I'm not dead and neither is the project.

  • C'est un Update!

    Patrick McDonnell07/11/2015 at 18:55 0 comments

    With the summer kicking off and school over, I've decided to continue work on the current monitor now that I have (slightly) more free time.

    I was hesitant to work inside my breaker box for the longest time, but I'm finally ready to open that baby up and connect the meter directly to my mains supply so I can actually read something useful with it.

    I'm also planning on updating the code so that you will be able to read both real-time current usage as well as current over time. Most likely this will mean shifting the timing from hardware to software. Currently measurements are sent every 15 minutes based on the time elapsed on the current monitor itself. The new system I would like to implement would make the webserver itself send a request for a reading every ten seconds or so, making both the timing more accurate and shifting some of the load off of the monitor.

    Both of these changes should be happening very soon barring any major setbacks, and I'll try to remember to post an update when I get it done.

    That's all this week. As always, stay tuned!

  • The Webserver

    Patrick McDonnell01/21/2015 at 03:51 1 comment

    Things have been pretty busy on my end and I haven't had too much time to work on the current monitor. Apologies to all the two people who are anxiously awaiting to hear more. I thought I'd take some time to show you guys just how the web interface works and how data gets from the arduino to the website.

    The main page of the current monitor, branded for my school because I can and because I was too lazy to remove that part of the code.

    The basic flow of the data transmission is as follows:

    Timer on board sends a GET request to the webserver's special php GET page via the ESP8266.
    GET Page on webserver takes data from URL and inserts it into a MySQL table
    Website polls MySql data from the past two hours and displays data on the website.

    I'll give a more detailed description of the process as soon as I can make some handy graphics to show it.

    That's all for now!

  • Watts Up?

    Patrick McDonnell01/07/2015 at 17:44 0 comments

    Today has already been a very good day for the energy monitor. I've got a very basic current sensing system running off of a basic circuit, and it seems to be within +/- 7% accuracy. Using an old set of christmas lights as a load, I was able to see the ac current fluctuate by 30mV, which equates out to 0.21A, or 24.8 watts, which is right around what google said is the wattage of a string of 50 lights.

    Today I will be attempting to come up with a function that calculates the RMS amperage of the alternating current. I'll most likely be taking the average difference between the high and low voltages and calculating amperage that way.

    The arduino and breadboard circuit, consisting of a 1k resistor, 4.7uf capacitor, and a 3.3v connection from the arduino board.

    The CT sensor and festive holiday decorations made a perfect match. I needed something with separated live and neutral wires, and these fit the bill.

    The raw analogRead values coming from the arduino. 688 - 655 = 33 * 4.8mv/unit = 0.15V /1000KΩ * 2000:1 CT ratio = 0.31A / sqrt(2) = 0.22 A * 120V = 26.4W! Math, dawg!

    Stay tuned for more complex math and other fun things.

  • Quick Updates

    Patrick McDonnell01/06/2015 at 20:31 0 comments

    Both the current sensor and the remaining few bits and pieces have arrived for me to finally finish up the hardware side of the build.

    I've updated the OP to include pictures of the schematics and the board, but I'm not releasing the actual source files yet because I'm not 100% sure everything will work yet.

    Additionally, I will need to begin the task of programming just how the arduino senses the AC current. The board converts the current into a voltage that fluctuates greatly, so I will need to devise some form of sampling that averages the samples over several wavelengths of the AC frequency (60hz here in America for anybody who doesn't know that).

    Everything else works well. The 8266 can communicate with my webserver and the site displays data very cleanly and neatly, as seen in the screenshot in the OP. Stay tuned as I try to get my current sensor sensing some current finally.

View all 5 project logs

Enjoy this project?



Nazwa wrote 04/14/2022 at 16:27 point

please make a fuzix os on esp and make a week working time in one charge

  Are you sure? yes | no

BYQ wrote 01/25/2016 at 15:59 point


Great project! I was looking for some solution on how to measure current/power using simple ESP8266 module instead of openenergymonitor shield and found yours. Any chance to have the code for ESP posted, please? How do you manage to keep info about current usage before uploading it to remote server? Is it stored somehwere to prevent it from losing data after power outage?

  Are you sure? yes | no

BYQ wrote 01/25/2016 at 16:03 point

Oh - I just looked at your PCB design and noticed there is only one sensor socket available - is it possible to connect 3 of them? Or 3 different PCBs needs to be used?

  Are you sure? yes | no

Patrick McDonnell wrote 03/14/2016 at 17:45 point

To use more sensors you would need more modules. The goal is to make them cheap enough to be able to build several for a low cost and deploy them all over, reporting back to a central server.

  Are you sure? yes | no

Backis wrote 03/24/2015 at 11:47 point

I'm doing the same think just using easyiot. :D. I would like to get more info on how you created the website. Now i'm taking easyiot created localhost server and using ngrok.exe making it accessible from everywhere.

  Are you sure? yes | no

redag2 wrote 01/06/2015 at 19:13 point

Sweet project. Are you planning on posting the schematics?

Also, is the web server running on the ESP8266? Or is the ESP8266 only used to transmit the ATMega's data sensing? This part isn't clear.

  Are you sure? yes | no

Patrick McDonnell wrote 01/06/2015 at 20:23 point

Sorry, I should have put down that the OP is still being added to. The 8266 just sends the data to a separate webserver. I contemplated running one off of the module but I wanted graphics and frameworks that just wouldn't have been able to run on the tiny chip.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates