{"id":7983,"date":"2018-02-23T13:46:07","date_gmt":"2018-02-23T05:46:07","guid":{"rendered":"http:\/\/www.rocketscream.com\/blog\/?post_type=portfolio&#038;p=7983"},"modified":"2018-02-23T13:46:07","modified_gmt":"2018-02-23T05:46:07","slug":"battery-voltage-monitoring-on-mini-ultra-pro","status":"publish","type":"portfolio","link":"https:\/\/www.rocketscream.com\/blog\/docs-item\/battery-voltage-monitoring-on-mini-ultra-pro\/","title":{"rendered":"Battery Voltage Monitoring on Mini Ultra Pro"},"content":{"rendered":"<div  class='tabcontainer av-av_tab_container-cdfb33d025ccce82e3bec7780d128c1e sidebar_tab sidebar_tab_left  avia-builder-el-0  avia-builder-el-no-sibling  border_tabs'>\n<section class='av_tab_section av_tab_section av-av_tab-4f25e9ff9cdfdedbdc69dcc935eacbd8'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-1-tab' class='tab active_tab' role='tab' aria-selected=\"true\" tabindex=\"0\" data-fake-id='#tab-id-1' aria-controls='tab-id-1-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue8a1' data-av_iconfont='entypo-fontello' ><\/span>Overview<\/div><div id='tab-id-1-content' class='tab_content active_tab_content' role='tabpanel' aria-labelledby='tab-id-1-tab' aria-hidden=\"false\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4410 aligncenter\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer.jpg\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-100x100.jpg 100w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-80x80.jpg 80w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-300x300.jpg 300w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-36x36.jpg 36w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2016\/02\/MiniUltraProLithiumPolymer-180x180.jpg 180w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The Mini Ultra Pro was designed to be ultra low power when operating from the Li-Ion or Li-Polymer battery. Starting from V3 of the Mini Ultra Pro, we have added a simple battery voltage monitoring on pin A5. A simple resistor divider circuit (using a pair of high resistance value to reduce current consumption) with a decoupling capacitor (that also helps to hold the voltage as the internal ADC circuitry on the microcontroller has a limited input impedance range) is used.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7984 aligncenter\" src=\"http:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring.jpg\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring.jpg 600w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring-100x100.jpg 100w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring-80x80.jpg 80w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring-300x300.jpg 300w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring-36x36.jpg 36w, https:\/\/www.rocketscream.com\/blog\/wp-content\/uploads\/2018\/02\/PinA5BatteryMonitoring-180x180.jpg 180w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The voltage divider will scale the maximum voltage of 4.2V of battery down to just below 3.3V to fit into the microcontroller ADC input voltage range.<\/p>\n<pre>VADC = (R16\/(R15+R16))*VBAT\r\nVBAT = VADC*((R15+R16)\/R16)\r\nVBAT = VADC*((3.3M+1M)\/1M)\r\nVBAT = VADC*4.3 V<\/pre>\n<\/div><\/div><\/section>\n<section class='av_tab_section av_tab_section av-av_tab-22373daa557e1da20928a6c662ae81af'  itemscope=\"itemscope\" itemtype=\"https:\/\/schema.org\/CreativeWork\" ><div id='tab-id-2-tab' class='tab' role='tab' aria-selected=\"false\" tabindex=\"0\" data-fake-id='#tab-id-2' aria-controls='tab-id-2-content'  itemprop=\"headline\" ><span class='tab_icon avia-iconfont avia-font-entypo-fontello' data-av_icon='\ue84d' data-av_iconfont='entypo-fontello' ><\/span>Code<\/div><div id='tab-id-2-content' class='tab_content' role='tabpanel' aria-labelledby='tab-id-2-tab' aria-hidden=\"true\"><div class='tab_inner_content invers-color'  itemprop=\"text\" ><p>The following will convert the raw ADC voltage on pin A5 into the battery voltage. We perform some averaging here that basically increases the resolution of our reading.<\/p>\n<pre>int adcReading;\r\nunsigned char counter;\r\nfloat batteryVoltage;\r\n\r\nadcReading = analogRead(A5);\r\n\/\/ Discard inaccurate 1st reading\r\nadcReading = 0;\r\n\/\/ Perform averaging\r\nfor (counter = 10; counter &gt; 0; counter--)\r\n{\r\n  adcReading += analogRead(A5);\r\n}\r\nadcReading = adcReading \/ 10;\r\n\/\/ Convert to volts\r\nbatteryVoltage = adcReading * (4.3 \/ 1023.0);<\/pre>\n<p>Do that note that if no valid battery is inserted, the reading will be a random value.<\/p>\n<\/div><\/div><\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":7984,"comment_status":"open","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"tags":[],"portfolio_entries":[183,155],"class_list":["post-7983","portfolio","type-portfolio","status-publish","has-post-thumbnail","hentry","portfolio_entries-mini-ultra-pro","portfolio_entries-products"],"_links":{"self":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/7983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio"}],"about":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/types\/portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/comments?post=7983"}],"version-history":[{"count":1,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/7983\/revisions"}],"predecessor-version":[{"id":7985,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio\/7983\/revisions\/7985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media\/7984"}],"wp:attachment":[{"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/media?parent=7983"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/tags?post=7983"},{"taxonomy":"portfolio_entries","embeddable":true,"href":"https:\/\/www.rocketscream.com\/blog\/wp-json\/wp\/v2\/portfolio_entries?post=7983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}