{"id":1022,"date":"2014-03-16T16:53:13","date_gmt":"2014-03-16T15:53:13","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=1022"},"modified":"2014-03-16T16:53:13","modified_gmt":"2014-03-16T15:53:13","slug":"arduino-play-with-a-potentiometer","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=1022","title":{"rendered":"Arduino : play with a potentiometer"},"content":{"rendered":"<p>I got myself a <a href=\"http:\/\/dx.com\/p\/204178\" target=\"_blank\">rotary potentiometer<\/a> at dx.com and decided to come up with a basic article.<\/p>\n<p>First, lets have a quick look at the below schematic to understand how a potentiometer works.<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/analogin_potentiometer.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1023\" alt=\"analogin_potentiometer\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/analogin_potentiometer-300x156.jpg\" width=\"300\" height=\"156\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/analogin_potentiometer-300x156.jpg 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/analogin_potentiometer.jpg 738w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Now, <strong>lets plug it to our arduino<\/strong> and while we are it, lets use its retrieved value (thru analogread) to dim a led (thru analogwrite).<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/potentiemter_bb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1024\" alt=\"potentiemter_bb\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/potentiemter_bb-256x300.png\" width=\"256\" height=\"300\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/potentiemter_bb-256x300.png 256w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/potentiemter_bb-874x1024.png 874w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2014\/03\/potentiemter_bb.png 1197w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Now lets have a look at the arduino sketch<\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre>\r\nbyte potPin=0; \/\/Analog 0 connected to the potentiometer\r\nbyte LEDPin=6; \/\/Connected to LED on Pin 6\r\nfloat potValue=0; \/\/Value returned from the potentiometer\r\nfloat v=0; \/\/voltage (0-5v)\r\n\r\nvoid setup(){\r\n  Serial.begin(9600);\r\n  pinMode(LEDPin, OUTPUT); \/\/Set Pin 6 as an Output\r\n}\r\n \r\nvoid loop(){\r\n  \r\n  potValue = analogRead(potPin)\/4; \/\/Read the potentiometer, convert it to 0 - 255\r\n  Serial.println(potValue,0);\r\n  v=potValue*5\/255; \/\/to calculate the voltage send out on pin6\r\n  Serial.println(v, 2);\r\n  analogWrite(LEDPin, potValue); \/\/Write the converted potentiometer value to LED pin\r\n  delay(100);\r\n}\r\n<\/pre>\n<p>here we go : rotate your potentiometer and see your led dim in and out<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got myself a rotary potentiometer at dx.com and decided to come up with a basic article. First, lets have a quick look at the below schematic to understand how a potentiometer works. &nbsp; Now, lets plug it to our arduino and while we are it, lets use its retrieved value (thru analogread) to dim <a href='https:\/\/labalec.fr\/erwan\/?p=1022' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-1022","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1022"}],"version-history":[{"count":1,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1022\/revisions"}],"predecessor-version":[{"id":1025,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/1022\/revisions\/1025"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}