{"id":1499,"date":"2020-09-20T19:33:19","date_gmt":"2020-09-20T17:33:19","guid":{"rendered":"https:\/\/pa3csg.nl\/?page_id=1499"},"modified":"2020-09-20T19:33:48","modified_gmt":"2020-09-20T17:33:48","slug":"ina226-current-voltage-power-meter-using-arduino-nano","status":"publish","type":"page","link":"https:\/\/pa3csg.nl\/?page_id=1499","title":{"rendered":"INA226 current \/ voltage \/ power meter, using Arduino Nano"},"content":{"rendered":"\n<p>Having tried several Chinese building blocks in my power supply. I decided to use the &#8220;new&#8221;  INA226 from TI. There are breakout boards available from the usual sources for almost nothing. A good reason to try one.<\/p>\n\n\n\n<p>The INA226 breakout boards are capable of 3A and a maximum voltage of 36V. In case of a higher voltage there is an application note available from TI, to solve this problem. Another solution would be to put the shunt in the minus of your power supply.<\/p>\n\n\n\n<p>I used the description of Giovanni Carera, adapted because it had a push-button and a SD card to write to.<\/p>\n\n\n\n<p>A full description can be found <a rel=\"noreferrer noopener\" href=\"https:\/\/www.hackster.io\/ArduPic\/the-arduina226-power-monitor-80d641\" target=\"_blank\">HERE<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"550\" src=\"https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-1024x550.jpg\" alt=\"\" class=\"wp-image-1503\" srcset=\"https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-1024x550.jpg 1024w, https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-300x161.jpg 300w, https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-600x322.jpg 600w, https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-1536x825.jpg 1536w, https:\/\/pa3csg.nl\/wp-content\/uploads\/2020\/09\/DSC_5333-2048x1101.jpg 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>The simple build-up.<\/figcaption><\/figure>\n\n\n\n<p>The adapted code for the current meter can be downloaded below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/* Program ArduINA226 to current, voltage and power\n with Arduino Nano and INA226 module\nuses Korneliusz Jarzebski Library for INA226 (modified)\nsave measurements on SD if present\nGiovanni Carrera, 14\/03\/2020\nModified (a little) Geert Stams PA3CSG 15 sept 2020\nTNX ON6NL\n*\/\n\n#include &lt;LiquidCrystal.h>\n#include &lt;Wire.h>\n#include &lt;INA226.h>\n\/\/ LCD pins\n#define rs 7\n#define en 6\n#define d4 5\n#define d5 4\n#define d6 A2\n#define d7 A3\n\/\/ initialize the library by associating any needed LCD interface pin\nLiquidCrystal lcd(rs, en, d4, d5, d6, d7);\nINA226 ina;\n\nchar bline&#91;17] = \"                \";\/\/ blank line\nconst int deltat= 200;\/\/ sampling period in milliseconds\nunsigned long cmilli, pmilli;\nboolean SDOk = true, FileHeader = true, ACQ = false;\nunsigned int ns=0;\n\nvoid setup() {\n  \/\/ set up the LCD's number of columns and rows:\n  lcd.begin(16, 2);\n  \/\/ Default INA226 address is 0x40\n  ina.begin(0x40);\n  lcd.setCursor ( 0 , 0);\n  lcd.print(\"INA226 PWR meter\");\n  lcd.setCursor ( 3 , 1);\n  lcd.print(\"  PA3CSG\");\n  delay (2000);\n  lcd.clear ();\n  \n  ina.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);\n\n  \/\/ Set shunt resistance ann max current to Calibrate INA226. Example Rshunt = 0.1  ohm, Max expected current = 3 A\n  \n  ina.calibrate(0.1, 1);\n    \n}\n\n\nvoid loop()  {\n  cmilli = millis();\n  if (cmilli - pmilli > deltat) {\n    pmilli = cmilli;\n    float volts = ina.readBusVoltage();\n    float current = ina.readShuntCurrent();\n    lcd.print(volts,3); \n    float power = ina.readBusPower();\/\/ INA calculate power\n    float Vshunt = ina.readShuntVoltage();\n    \n  lcd.setCursor ( 0 , 0);\n  lcd.print(bline);\n  lcd.setCursor ( 0 , 0);\n  lcd.print(volts , 1);\n  lcd.setCursor ( 6 , 0);\n  lcd.print(\"V\");\n  lcd.setCursor ( 9 , 0);\n  lcd.print(current , 2);\n  lcd.setCursor ( 15 , 0);\n  lcd.print(\"A\");\n  lcd.setCursor ( 0 , 1);\n  lcd.print(bline);\n  lcd.setCursor ( 6 , 1);\n  lcd.print(power , 2);\n  lcd.setCursor ( 12 , 1);\n  lcd.print(\"W     \");      \n   }\n  }<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Having tried several Chinese building blocks in my power supply. I decided to use the &#8220;new&#8221; INA226 from TI. There are breakout boards available from <a class=\"mh-excerpt-more\" href=\"https:\/\/pa3csg.nl\/?page_id=1499\" title=\"INA226 current \/ voltage \/ power meter, using Arduino Nano\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1503,"parent":0,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1499"}],"collection":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1499"}],"version-history":[{"count":1,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1499\/revisions"}],"predecessor-version":[{"id":1505,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1499\/revisions\/1505"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/media\/1503"}],"wp:attachment":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}