{"id":23,"date":"2014-04-26T21:22:33","date_gmt":"2014-04-26T21:22:33","guid":{"rendered":"http:\/\/daqdesign.wordpress.com\/?p=23"},"modified":"2024-10-23T20:19:41","modified_gmt":"2024-10-23T20:19:41","slug":"minmax-detection","status":"publish","type":"post","link":"https:\/\/daq-design.co.uk\/blog\/?p=23","title":{"rendered":"Min\/Max detection"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This routine will be useful where you need to take readings from any sensor and use the previous reading as a comparison for an action to be taken. Nothing special about this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I use an LDR connected in a voltage divider configuration to pin A0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\nThis application will read the light level from the LDR\non power-up and will use that initial value as the first reference\nfor the min\/max light levels.\nIt will then continually compare that initial stored value\nwith the next reading and update the min\/max levels accordingly\n*\/\n\nint ldr=A0;\nint tempmin,tempmax;\nint initreading;\n\nvoid setup()\n{\nSerial.begin(9600);\npinMode(ldr,INPUT);\ndelay(200);\ninitreading=analogRead(ldr); \/\/ take an initial reading\ntempmin=initreading; \/\/ assign the initial reading to the min\ntempmax=initreading; \/\/ and the max readings\nSerial.print(&amp;quot;Initial light level: &amp;quot;);\nSerial.println(initreading);\nSerial.println(&amp;quot;This is lux(min) and lux(max)&amp;quot;);\n}\n\nvoid loop()\n{\nint reading=analogRead(ldr);\ndelay(1000);\n\nif (reading&amp;lt;tempmin)\n{\ntempmin=reading;\n\nSerial.print(&amp;quot;New minimum of: &amp;quot;);\nSerial.print(reading);\nSerial.println(&amp;quot; read from the sensor&amp;quot;);\n}\nif (reading&amp;gt;tempmax)\n{\ntempmax=reading;\nSerial.print(&amp;quot;New maximum of: &amp;quot;);\nSerial.print(reading);\nSerial.println(&amp;quot; read from the sensor&amp;quot;);\n}\nelse\n{\nSerial.print(&amp;quot;Current mimimum is: &amp;quot;);\nSerial.print(tempmin);\nSerial.print(&amp;quot; and the maximum is: &amp;quot;);\nSerial.print(tempmax);\nSerial.print(&amp;quot; with a current lux of: &amp;quot;);\nSerial.println(reading);\n}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This routine will be useful where you need to take readings from any sensor and use the previous reading as a comparison for an action to be taken. Nothing special about this. I use an LDR connected in a voltage &hellip; <a href=\"https:\/\/daq-design.co.uk\/blog\/?p=23\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-arduino"],"_links":{"self":[{"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":2,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":468,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions\/468"}],"wp:attachment":[{"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daq-design.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}