{"id":940,"date":"2024-06-23T14:20:30","date_gmt":"2024-06-23T14:20:30","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=940"},"modified":"2024-08-11T14:52:34","modified_gmt":"2024-08-11T14:52:34","slug":"water-level-indicator","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=940","title":{"rendered":"Water Level Indicator"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Water level indicator indicates the level of water in a source. Let\u2019s build a simple program that indicate the level of water of a reserve tank and auto full when the level of water is less than 25%. We use ULN2003A driver IC that we already introduce in stepper motor. Let\u2019s look at the connection diagram<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"342\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/water-level-1024x342.jpg\" alt=\"\" class=\"wp-image-941\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/water-level-1024x342.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/water-level-300x100.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/water-level-768x256.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/water-level.jpg 1444w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In this connection if water reaches that level the corresponding pin will low otherwise high. So we need to enable the internal pull-up for the input pin. The main control logic as follow-<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"padding-right:0;padding-left:0;flex-basis:33.33%\">\n<figure class=\"wp-block-image alignright size-full is-resized\"><img decoding=\"async\" width=\"41\" height=\"40\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float.jpg\" alt=\"\" class=\"wp-image-944\" style=\"width:29px;height:auto\"\/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"wp-block-paragraph\">float sensor(void) -&gt; return the level of water &amp; also turn on\/off the motor.<\/p>\n<\/div>\n<\/div>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nfloat sensor(void)\n{\n     float water_level=0;     \/\/variable declear\n\tif(!(PINB&amp;(1&lt;&lt;PINB0)))\n\t{\n\t water_level=100;           \/\/dipaly 100%\n\t PORTC&amp;=~(1&lt;&lt;PORTC0);       \/\/load off\n\t}\n\telse if(!(PINB&amp;(1&lt;&lt;PINB1))) water_level=87.5;        \/\/dipaly 87.5%\n\telse if(!(PINB&amp;(1&lt;&lt;PINB2))) water_level=75;          \/\/dipaly 75%\n\telse if(!(PINB&amp;(1&lt;&lt;PINB3))) water_level=62.5;        \/\/dipaly 62.5%\n\telse if(!(PINB&amp;(1&lt;&lt;PINB4))) water_level=50;          \/\/dipaly 50%\n\telse if(!(PINB&amp;(1&lt;&lt;PINB5))) water_level=37.5;        \/\/dipaly 37.5%\n\telse if(!(PINB&amp;(1&lt;&lt;PINB6)))\n\t{\n\t water_level=25;          \/\/dipaly 25%\n\t PORTC|=(1&lt;&lt;PORTC0);       \/\/relay on\n\t}\n\treturn water_level;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The function returns a floating value type and On\/Off the Motor but in LCD there is a problem to display floating point variable. So we need to modify in MFile that-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"207\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/mfile-change-1024x207.jpg\" alt=\"\" class=\"wp-image-953\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/mfile-change-1024x207.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/mfile-change-300x61.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/mfile-change-768x155.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/mfile-change.jpg 1466w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We can use sprintf function or can use standard library function under<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"303\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float-to-char-1024x303.jpg\" alt=\"\" class=\"wp-image-957\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float-to-char-1024x303.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float-to-char-300x89.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float-to-char-768x227.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float-to-char.jpg 1288w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">format: dtrostrf(float_value, minimum_width, num_digits_after_decimal, string);<\/p>\n\n\n\n<p class=\"has-upper-heading-font-size wp-block-paragraph\">i.e dtostrf(float, 6, 3, string); -&gt; xxxxxx.xxx -&gt; [6 digits].[3 decimal]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main program as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;avr\/io.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&lt;stdlib.h&gt;\n#define INPUT_DDR     DDRB\n#define INPUT_PORT    PORTB\n#include&quot;lcd.h&quot;        \/\/ PORTD as LCD port\n#include&quot;input.h&quot;      \/\/ PORTB as input with internal pull-up\nchar level&#x5B;6];\nint main(void)\n{\nDDRC|=(1&lt;&lt;DDC0);      \/\/output pin for relay control\nLCD_INIT();\nLCD_Clear();\nINPUT_DDR=0x00;       \/\/ All port are input\nINPUT_PORT=0xff;      \/\/ Internal pull-up activate\nfloat Value=0.00;\nwhile(1)\n\t{\n      Value=sensor();\n\t  dtostrf(Value,3,2,level);\n\t  LCD_write_string(1,1,&quot; Resorver Water &quot;);\n\t  LCD_write_string(1,2,&quot;water level=&quot;);\n\t  LCD_write_string(13,2,level);\n\t}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Water-Level-Indicator.rar\" style=\"border-radius:10px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Water-Level-Indicator.rar\">Download the full program with proteus simulation<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Water level indicator indicates the level of water in a source. Let\u2019s build a simple program that indicate the level of water of a reserve tank and auto full when the level of water is less than 25%. We use ULN2003A driver IC that we already introduce in stepper motor. Let\u2019s look at the connection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry","category-i-o-port-operations"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=940"}],"version-history":[{"count":13,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":2545,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/940\/revisions\/2545"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}