{"id":461,"date":"2016-07-24T19:56:24","date_gmt":"2016-07-24T18:56:24","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=461"},"modified":"2016-08-12T21:23:51","modified_gmt":"2016-08-12T20:23:51","slug":"voltmeter-using-arduino","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/arduino\/voltmeter-using-arduino\/","title":{"rendered":"Voltmeter using Arduino"},"content":{"rendered":"<p>Using precisely calculated resistors and a stable power supply, Arduino can be used to work as a voltmeter.<\/p>\n<p><strong>Below is the schematic<\/strong><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-462\" src=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter-1024x476.png\" alt=\"Arduino Voltmeter\" width=\"604\" height=\"281\" srcset=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter-1024x476.png 1024w, https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter-300x139.png 300w, https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter-768x357.png 768w, https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2016\/07\/Arduino-Voltmeter.png 1518w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p>Though I used an Arduino Uno, but any Arduino can be used. (If the 3.3v versions are used then calculations will have to be done accordingly).<\/p>\n<p>The resister for voltage divider has been chosen such that at 20 volts (measurement) supply the voltage at Arduino input pin is 5.0v. Greater than 5v at the input pin can damage the pin.<\/p>\n<p><strong>Here is the code<\/strong><\/p>\n<pre class='wp-code-highlight prettyprint'>#define READINGS 5\r\n\r\nint sensorPin = A0;\r\nshort int readingsTaken = 0;\r\nfloat voltage = 0.0, readingTotal = 0.0;\r\n\r\nvoid setup() {\r\n\u00a0 \/\/ put your setup code here, to run once:\r\n\u00a0 pinMode(sensorPin, INPUT);\r\n\u00a0 Serial.begin(9600);\r\n}\r\n\r\nvoid loop() {\r\n\u00a0 \/\/ put your main code here, to run repeatedly:\r\n\u00a0 readingTotal = 0.0;\r\n\u00a0 readingsTaken = 0;\r\n\u00a0 \r\n\u00a0 \/\/ we will take 5 readings at 1 sec interval and then do an average of that\r\n  while(readingsTaken &lt; READINGS) \r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 readingTotal += analogRead(sensorPin);\r\n\u00a0\u00a0\u00a0 readingsTaken++;\r\n\u00a0\u00a0\u00a0 delay(1000); \/\/at every 1 second interval\r\n\u00a0 }\r\n\r\n\u00a0 voltage = (readingTotal\/READINGS) * (5.0\/1024); \/\/ the value in voltage at this point is what Arduino read based on input from voltage divider network. Need to calculate the original \/\/ 5.0 - is the ref voltage used by ADC. It is the default configuration and uses the voltage supplied to the board. To change the ref voltage\/source please see <a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/arduino\/arduino-voltmeter-2-more-precise\/\">this article<\/a>\r\n\r\n\u00a0 voltage = (20\/4.992) * voltage; \/\/unitary method to calculate the actual voltage that is read. When voltage read is 4.922 (or 5.0v), the input is 20v. With the resistor divider at the input, the voltage at I\/O will be 4.992\r\n\r\n\u00a0 Serial.println(voltage);\r\n}<\/pre>\n<p>This is a simple and basic way. Where the precision will not be very good. Because the reference voltage being used by the ADC, which is actually the supply voltage can vary depending on the load to the circuit. To make it more precise an external reference voltage can be supplied to the Arduino. How to use an external reference voltage and the use of the AREF pin has been described in <a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/arduino\/arduino-voltmeter-2-more-precise\/\">this article<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using precisely calculated resistors and a stable power supply, Arduino can be used to work as a voltmeter. Below is the schematic Though I used an Arduino Uno, but any Arduino can be used. (If the 3.3v versions are used then calculations will have to be done accordingly). The resister for voltage divider has been&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/arduino\/voltmeter-using-arduino\/\">Continue reading <span class=\"screen-reader-text\">Voltmeter using Arduino<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[13,73,74],"class_list":["post-461","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-arduino","tag-arduino-analog-input","tag-arduino-voltmeter","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":4,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"predecessor-version":[{"id":498,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/461\/revisions\/498"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}