BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

"Power Monitor" - DC Current and Voltage Sensor (INA219)

NOW ON HACKSTER.IO : https://www.hackster.io/jamin/power-meter-using-blynk-mobile-cf2d3e Please like the project :slight_smile:

I built a simple Power Meter you can use to measure 0-26V and up to 3.2A. Which makes a great addition to your workshop by allowing you to monitor voltage, current, power and energy used over time on almost any DC device.

I used a INA219 (High Side DC Voltage and Current I2C Module). These are very cheap. I got a 5 pack on special for $7.

Right now it just polls at 1second… I tried to set up a slider for the interval but ran in to problems so will sleep on it. I did however just set up a HOLD button so you can pause the polling.

There are many more features I would love to add. But currently this is working perfectly. So it would be a geat place for people to start with a working example for Blynk. So I would love to see what other ideas people can come up with. Please leave comments below.

UPDATE: SEE NEWER CODE ON GITHUB Please give it a star too :smiley:
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB



16 Likes

НCould you please post a photo of your setup? Somebody will find it helpful

2 Likes

It’s just a messy breadboard. The wiring is just a standard I2C connection.

Once I have it in a case it will be photo ready lol

1 Like

Good job @Jamin :clap::clap: ,really loved your work :slight_smile::+1:

1 Like

shouldn’t the if condition be < 1000 ?
You have used the 1024 three times, for load current, load power and energy consumption.

Besides that it’s a really cool project.

Yeah it can be anything… im just used to using 1023/1024 for so many things.
Its bascially in auto-resolution mode. It wouldn’t be hard to add a button widget which turns off that mode.

Done a bit of an update on this.

Additions:

  • Peak value and Average value for Voltages, Current & Power
  • Reset buttons for the above new values. This is so you can get accurate averages etc just handy really
  • Auto-range selection button which is on by default.
  • Fixed Energy calculations so they are more accurate.
  • Added a Price Per kWh slider to the Eneergy consumption section so you can calulate how much your device costs you. I am currently trying to pull my Spot Power Rate from my power company’s API so I will probably remove the slider later and have the price update every minute from the API.
  • When no load is connected it was showing 1.07V & 1.4mA. Now it shows 0.00V / 0mA

UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB

6 Likes

Another update:

  • More accurate data now with 3 decimal places.
  • Consumption area now pulls current the latest rate using a webhook. I have set up a simple GET on an API I set up on a local server.
  • Energy cost and total consumption now work on 6 decimal places for more accurate readings on low powered devices.

To come:

  • Average 5-10 samples instead of 2 to help stabilize the averages.
  • Keep energy cost from previous rates after it updates. Basically right now when the rate changes, it just multiplies the energyPrice and energy. I will change it so that it keeps the cost that has already been added to the total and the rate only affects what is added each second.
  • I want to lower the number of virtualWrite’s made each second as I have noticed my ESP start to disconnect from over working. I will seperate the updates in to a sequence so that the values are updated over 1000ms unstead of all at once at the start.
  • Some sort of timer or stop watch so you know how long you have been monitoring the device.

UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB

3 Likes

Very nice @Jamin
Can you please provide more details on the power companies API?
I see you have a separate server running node.js to pull down the API data at 10 second intervals. Is it not possible to use Blynk’s Webhook widget to obtain the data directly to your MCU?

Does the energy price actually change very often as a 10s loop seems very frequent?

My provider is Flick Electric. They are quiet different from normal power companies because they charge on a spot rate which changes depending on power demand of the local community and country.

Cheap at night and expensive during day and evenings basically.

Watch the video below for a brief look at NZ humor… hahh

https://vimeo.com/123907818

I emailed customer service the other day asking for acess to the API but was told it is officailly un-available.
But a smart person from Wellington, NZ has created an API and put it on Github!

I have a Diskstation (basically a linux server) in my closet. It runs my local Blynk server etc.
I installed Nodejs 4.2 via the Synology Package Center and then connected via SSH.

I followed some commands about how to load npm node_modules, and then how to create and run .js scripts on the server side.

I still havn’t masterd it as I have to reload it manually for it to update the price via the API… looking at the “reload” node_module but its confusing. (if anyone know s node.js and wants to help please msg me!)

I am! I copied the GET example provided by Blynk. Workes a treat!

Yup! I noticed it changes randomly… its on-demand so could change at any time.

1 Like

I was thinking direct from MCU to Energy company without the API call to your node.js server.

Looking at the GitHub I see the API requires JSON web tokens for authentication etc so borrowing the javascript interface was probably the right choice for you.

1 Like

More updates!

  • Averages now take 5 samples over 5 seconds so they are far more stable and smooth.
  • All virtualWrites have been split up 200ms apart. Check out the code for my crude method of starting the timers.
  • Energy Cost is now based on the difference added since the previous poll. This gives more accurate costs over long periods when the spot rate changes.
  • Energy cost now shows 8 decimal places for higher resolution
  • Increased Load Voltage decimal places to 4 for highers accuracy.
  • ADDED: Stopwatch counter from 0. Counts up in DD:HH:MM:SS format. Reset by holding RESET MAX/SW button 1 second.

In progress:

  • Reset energy readings by long press RESET AVG/CON button. (hold both buttons to reset both (stopwatch) in sync)
  • When in HOLD mode, continue to calculate and log energy consumption while showing the paused value.

UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB
UPDATE: SEE NEWER CODE ON GITHUB

5 Likes

Thanks for posting your script. You are a Blynk Guru, you just won that title. All my life I have been searching how to format the output using “Blynk.virtualWrite” to two decimal places using the “Value Display S” widget, I posted a question, never got a reply, no even from the developers, I guess they are too busy.

Anyway, I found the solution from your script: (1,String(loadvoltageMax, 3) + String(" V") Bingo! It works beautifully.

Happy new year!

2 Likes

Awesome man! Glad i could help! I discovered how to do the rounding during this project so it’s new to me too! :smile:

Recommended way is to use labeled value display. As formatted strings like “10 %” not stored to history graph.

Hi @Jamin…thanks for detailed explanation I am new to blynk and trying to implement this project on my home network. I uploaded code onto esp8266 and app says that device is offline.

I am using this code for wifi_credentials.h library

#ifndef CREDENTIALS_H
#define CREDENTIALS_H
char WIFI_SSID[] = “my_wifi”; // SSID
char WIFI_PASS[] = “xxxxxxxxxx”; //Password
#endif

and in settings.h, i just placed my AUTH code.

Please Let me know if i need more changes in code. Thanks

Use

#define WIFI_PASS "xxxx"

Instead and you’re sweet!

Just make sure you put it in your library folder. I also exclude the #ifndef directives etc too. I just have the two lines of credentials.

I’ll update the readme with proper instructions.

1 Like

thank u so much for prompt reply. Really appreciate that

1 Like

Updated docs and used your addition for safety :slight_smile: Cheers

1 Like

Hi @Jamin,
I have been playing with your project and the INA219 sensor, thanks for sharing this amazing project!
The results using my tester and the INA219 are pretty similar, see below:

Voltage: 4.34 V vs 4.3590 V

Current: 640 mA vs 655 mA (feeding a thirsty power-bank)

My set up:

“Plug-and-play” shield (I have cut the board a little bit to be able to do this shield)

Kind regards

1 Like