{"id":425,"date":"2018-04-01T19:21:40","date_gmt":"2018-04-01T19:21:40","guid":{"rendered":"http:\/\/www.adrian-smith31.co.uk\/blog\/?p=425"},"modified":"2020-11-09T17:10:57","modified_gmt":"2020-11-09T17:10:57","slug":"arduino-6-input-dvm-0-to-50v-range","status":"publish","type":"post","link":"https:\/\/www.adrian-smith31.co.uk\/blog\/2018\/04\/arduino-6-input-dvm-0-to-50v-range\/","title":{"rendered":"Arduino 6 input DVM 0 to +50V range"},"content":{"rendered":"<p>This is a project I built for work as an add on to our battery tester which is able to test up to six batteries at once. The battery tester is controlled by a PLC and does not show voltages in real time so we had no idea how long the battery runtime was remaining. A voltmeter that showed the battery voltage under test was required as our tester cuts off the battery at 10.5V for 12V and 21V for 24V lead acid batteries. At first I planned to use a standard panel meter and a six way switch to select the battery under test. This however proved to be quite (in comparison to alternatives) an expensive way of doing this.<\/p>\n<p><a href=\"http:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-426 size-medium\" title=\"Arduino 6 input voltmeter - measure 6 voltages at the same time.\" src=\"http:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm-300x202.jpg\" alt=\"Arduino 6 input voltmeter\" width=\"300\" height=\"202\" srcset=\"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm-300x202.jpg 300w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm-768x518.jpg 768w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm-1024x691.jpg 1024w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm-445x300.jpg 445w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_ch_dvm.jpg 1298w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I decided to make use of a few spare parts I had laying round in the workshop and make a digital voltmeter that could monitor six battery voltages at once on a single LCD. This would obviously have to be microcontroller based so I chose the Arduino over the 8051 due to it&#8217;s built in ADC and ease of use. As you can see from the photo the project uses a 20&#215;4 character LCD and also monitors the temperature of the heatsink the load resistors are mounted to. A DS18B20 one wire digital thermometer was used for this and the battery voltage monitoring wires were connected to the Arduino&#8217;s ADC ports A0-A5 via a voltage divider.<\/p>\n<p><!--more--><\/p>\n<figure id=\"attachment_427\" aria-describedby=\"caption-attachment-427\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/Arduino-LCD-voltmeter.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-427 size-medium\" title=\"Example voltage divider circuit.\" src=\"http:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/Arduino-LCD-voltmeter-300x160.png\" alt=\"Example voltage divider circuit.\" width=\"300\" height=\"160\" srcset=\"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/Arduino-LCD-voltmeter-300x160.png 300w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/Arduino-LCD-voltmeter-500x267.png 500w, https:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/Arduino-LCD-voltmeter.png 650w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-427\" class=\"wp-caption-text\">Example voltage divider circuit.<\/figcaption><\/figure>\n<p>With the voltage divider the circuit can measure positive voltages from zero to 55 volts although I specified 50V to avoid accidentally overvolting the ADC inputs. The divider gives an approximate 11:1 ratio and due to component tolerances must be calibrated. This is explained in the code but you will require a good quality digital voltmeter to calibrate this circuit. Here is a schematic which this project is based on; the divider resistor values are the same. This only shows 4 channels but you can work out by looking at the code and the example schematic what I did to get the extra 2 channels. I used a nano for the project but you could use a bare ATmega328 chip instead to save on components. I preferred to use a nano for ease of uploading firmware updates and calibration values. They are cheap enough to buy anyway.<\/p>\n<p>Below is an extract of code showing calibration procedure which is done by measuring the input voltage and dividing it by the voltage present at the output of the voltage divider. I used 10.02V as the input voltage to each voltage divider. Do not connect the input voltage to be measured directly to the Arduino as this will destroy it. Note the 5V supply is critical &#8211; the LDO regulators built into the nano tend to be pretty wank so if it&#8217;s <em>above\u00a0<\/em>5V (I&#8217;ve had them output 5.2V) this will result in very inaccurate readings. Best use a 7805 from a reputable manufacturer (not chinese clone) and apply this to the 5V pin directly. These typically have an output of 5V +\/- 0.01V. A third alternative is use a 5V precision reference IC and connect it to the Vref pin modifying code accordingly to get the external vref voltage rather than the default vcc.<\/p>\n<p><span style=\"color: #993300;\"><em>***Calibration***<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em> Use 1% tolerance resistors for the voltage divider and calibrate as below:-<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em> VREF= 5V supply voltage (measured with precision DVM to get best accuracy)<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em> The voltage divider factor is calculated by dividing the first voltage by the second voltage or:<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em> dividing factor = input voltage \u00f7 output voltage<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em> For example, if the first or input voltage measured is 10.02V and the second or output voltage is 0.9V, then the division factor is:<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em> 10.02 \u00f7 0.9 = 11.133<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em> Voltages should be measured with a good calibrated DVM for best accuracy and should be recalibrated once every year.<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em> *\/<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>#include &lt;LiquidCrystal.h&gt;<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#include &lt;OneWire.h&gt;<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#include &lt;DallasTemperature.h&gt;<\/em><\/span><\/p>\n<p><span style=\"color: #993300;\"><em>\/\/ number of analog samples to take per reading, per channel<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define NUM_SAMPLES 10<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>\/\/ voltage divider calibration values<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_1 10.9395<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_2 11.0352<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_3 11.0382<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_4 11.2222<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_5 11.2097<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define DIV_6 11.1602<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>\/\/ ADC reference voltage \/ calibration value<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define V_REF readVcc()\u00a0<span style=\"color: #000000;\"> &#8211;\u00a0I used a readvcc function but you can replace readvcc()<\/span><\/em><\/span><span style=\"color: #000000;\"><em>\u00a0with the actual measured VCC voltage if this is better.<\/em><\/span><br \/>\n<span style=\"color: #993300;\"><em>#define ONE_WIRE_BUS 10 <\/em><\/span><\/p>\n<p>The code also dumps the data to the serial port for a future modification to the windows based battery test software that works in conjunction with the PLC. At the moment this feature isn&#8217;t used but the latest code sends data periodically every 10 seconds for the purpose of data logging if required.<\/p>\n<p>This is intended to be an example of projects I&#8217;ve made &#8211; it&#8217;s fully working but was built to be part of a larger battery testing system. This 6 input voltmeter however can be used standalone for monitoring up to six voltages at once. <a href=\"http:\/\/www.adrian-smith31.co.uk\/blog\/wp-content\/uploads\/2018\/03\/6_channel_DVM_public_ver.zip\" target=\"_blank\" rel=\"noopener noreferrer\">The code can be downloaded here.<\/a><\/p>\n<p>Parts required for this project:-<\/p>\n<ul>\n<li>20&#215;4 LCD<\/li>\n<li>Arduino nano (or bare ATmega328 with Arduino bootloader)<\/li>\n<li>7809 voltage regulator (omit if using a <em>regulated<\/em> 9V wall wart)<\/li>\n<li>7805 voltage regulator (if the nano&#8217;s LDO regulator is wank)<\/li>\n<li>0.1uf capacitors x4<\/li>\n<li>10uf capacitors x2<\/li>\n<li>220 ohm resistor<\/li>\n<li>50K pot<\/li>\n<li>100K resistor x6<\/li>\n<li>1K resistor x6<\/li>\n<li>4.7K resistor x1<\/li>\n<li>DS18B20 IC<\/li>\n<li>Suitable heatsink for the regulator<\/li>\n<li>Suitable case to house it in<\/li>\n<li>Veroboard or make your own PCB.<\/li>\n<\/ul>\n<p>Note that if using a bare &#8216;328 you will need 22pf caps x2, 16Mhz crystal and 5v regulator. LDO type preferred as those switch mode ones introduce too much noise.<\/p>\n<p>Accuracy is to 1 decimal place which was accurate enough for our application. You may be able to modify the code for 2 decimal place accuracy however this wouldn&#8217;t leave enough room on the LCD. I am unable to provide any info on the battery tester itself or the windows based software as this is in house software and cannot be publicly released due to intellectual property reasons. You can however use the Arduino code as you see fit. Just remember if you re-distribute it credit me in the code.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a project I built for work as an add on to our battery tester which is able to test up to six batteries at once. The battery tester is controlled by a PLC and does not show voltages in real time so we had no idea how long the battery runtime was remaining. [&hellip;]<\/p>\n","protected":false},"author":179,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Arduino 6 input DVM 0 to +50V range - Adrian's electronics blog","description":"This is a project I built for work as an add on to our battery tester which is able to test up to six batteries at once. The battery tester is controlled by a P"},"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","hentry","category-microcontrollers","category-projects"],"_links":{"self":[{"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/users\/179"}],"replies":[{"embeddable":true,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":9,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":1057,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/posts\/425\/revisions\/1057"}],"wp:attachment":[{"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.adrian-smith31.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}