{"id":499,"date":"2024-06-22T12:05:22","date_gmt":"2024-06-22T12:05:22","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=499"},"modified":"2024-08-10T17:58:29","modified_gmt":"2024-08-10T17:58:29","slug":"relay-control","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=499","title":{"rendered":"Relay Control"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"499\" class=\"elementor elementor-499\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5c1f3f5 e-flex e-con-boxed e-con e-parent\" data-id=\"5c1f3f5\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d072e3b elementor-widget elementor-widget-text-editor\" data-id=\"d072e3b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>I\/O stands for Input\/Output function. Example ATmega8 has 23 Programmable I\/O Lines that can define as both input and output device. The I\/O registers bellow-<\/p><p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-502 size-full\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/GPIO.jpg\" alt=\"\" width=\"977\" height=\"605\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/GPIO.jpg 977w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/GPIO-300x186.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/GPIO-768x476.jpg 768w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/p><p>Let\u2019s build our first program that content<\/p><p><img decoding=\"async\" class=\"alignnone wp-image-503 size-full\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PB0.jpg\" alt=\"\" width=\"1361\" height=\"90\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PB0.jpg 1361w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PB0-300x20.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PB0-1024x68.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PB0-768x51.jpg 768w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-013fa29 elementor-widget elementor-widget-text-editor\" data-id=\"013fa29\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>DDRx(Data Directions Register x) define the I\/O initialization condition. If DDRx-&gt; 1(set) the Output and DDRx-&gt; 0(clear) Input.<\/p><p><img decoding=\"async\" class=\"alignnone wp-image-511\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/port-operation-300x21.jpg\" alt=\"\" width=\"801\" height=\"55\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/port-operation-300x21.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/port-operation-1024x70.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/port-operation-768x53.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/port-operation.jpg 1395w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/p><h5><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-512 size-full\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/C-Structure.jpg\" alt=\"\" width=\"1453\" height=\"559\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/C-Structure.jpg 1453w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/C-Structure-300x115.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/C-Structure-1024x394.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/C-Structure-768x295.jpg 768w\" sizes=\"(max-width: 1453px) 100vw, 1453px\" \/>Conditional operator<\/h5><h6>\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>expression ? True execution : False execution;<\/strong><\/h6><h6>Example:-\u00a0 \u00a0 \u00a0 \u00a0x=(a&gt;b) ? a:b;<\/h6><p>If the expression is true than x=a<\/p><p>If the expression is false than x=b<\/p><p>In C language we can check whether the pin is logic 1 or logic 0. The C format is to check if the bit is set<\/p><h6><strong>C:\\&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (register_name&amp;(1&lt;&lt;bit_number))<\/strong><\/h6><p>Let check how it works-<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Suppose the default value of PINB=0b11110001. Now from the fundamental of C as we know non-zero is true and zero is false.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-4a01a1a e-flex e-con-boxed e-con e-parent\" data-id=\"4a01a1a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-92146f4 elementor-widget elementor-widget-image\" data-id=\"92146f4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"223\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PIN-checking-1024x356.jpg\" class=\"attachment-large size-large wp-image-523\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PIN-checking-1024x356.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PIN-checking-300x104.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PIN-checking-768x267.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/PIN-checking.jpg 1303w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-f71bb70 e-con-full e-flex e-con e-child\" data-id=\"f71bb70\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5c846b5 elementor-widget elementor-widget-text-editor\" data-id=\"5c846b5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Similarly to check if the bit is clear<\/p><h6><strong>C:\\&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 !(register_name&amp;(1&lt;&lt;bit_number))<\/strong><\/h6>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-2784e7a e-grid e-con-full e-con e-child\" data-id=\"2784e7a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5762755 elementor-widget elementor-widget-text-editor\" data-id=\"5762755\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Let\u2019s go to our main program. In real life after we press a switch there is a debouncing effect. So we need some delay function for every time switch is pressed. AVR has build in function that control delay operation.\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0fc1f83 elementor-widget elementor-widget-image\" data-id=\"0fc1f83\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"257\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/SW-debouncing.jpg\" class=\"attachment-large size-large wp-image-527\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/SW-debouncing.jpg 598w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/SW-debouncing-300x129.jpg 300w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-03907a0 e-flex e-con-boxed e-con e-parent\" data-id=\"03907a0\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-22c5b5a elementor-widget elementor-widget-text-editor\" data-id=\"22c5b5a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-543 size-full\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/delay-funtion.jpg\" alt=\"\" width=\"1360\" height=\"159\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/delay-funtion.jpg 1360w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/delay-funtion-300x35.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/delay-funtion-1024x120.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/delay-funtion-768x90.jpg 768w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/p><p>Full Code-&gt;<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-399 size-full\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/First-Program.jpg\" alt=\"\" width=\"1135\" height=\"798\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/First-Program.jpg 1135w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/First-Program-300x211.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/First-Program-1024x720.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/First-Program-768x540.jpg 768w\" sizes=\"(max-width: 1135px) 100vw, 1135px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6136b2e elementor-widget elementor-widget-text-editor\" data-id=\"6136b2e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In programming we use the delay function to avoid noise but in real life we can minimize the noise effect by using capacitor or RC\/LC circuit that is called filter. Noise reduces the lifecycle of the switch so if possible use RC filer circuit.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-88b2fef e-grid e-con-boxed e-con e-parent\" data-id=\"88b2fef\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-c3a74f0 elementor-align-center elementor-widget elementor-widget-button\" data-id=\"c3a74f0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/1.-Load-Control-relay-control.rar\" target=\"_blank\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t<span class=\"elementor-button-icon\">\n\t\t\t\t<svg aria-hidden=\"true\" class=\"e-font-icon-svg e-far-file-archive\" viewBox=\"0 0 384 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M128.3 160v32h32v-32zm64-96h-32v32h32zm-64 32v32h32V96zm64 32h-32v32h32zm177.6-30.1L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM256 51.9l76.1 76.1H256zM336 464H48V48h79.7v16h32V48H208v104c0 13.3 10.7 24 24 24h104zM194.2 265.7c-1.1-5.6-6-9.7-11.8-9.7h-22.1v-32h-32v32l-19.7 97.1C102 385.6 126.8 416 160 416c33.1 0 57.9-30.2 51.5-62.6zm-33.9 124.4c-17.9 0-32.4-12.1-32.4-27s14.5-27 32.4-27 32.4 12.1 32.4 27-14.5 27-32.4 27zm32-198.1h-32v32h32z\"><\/path><\/svg>\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">download<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-31afa5a elementor-widget elementor-widget-heading\" data-id=\"31afa5a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/1.-Load-Control-relay-control.rar\" target=\"_blank\">Download the full program with proteus simulation<\/a><\/h4>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>I\/O stands for Input\/Output function. Example ATmega8 has 23 Programmable I\/O Lines that can define as both input and output device. The I\/O registers bellow- Let\u2019s build our first program that content DDRx(Data Directions Register x) define the I\/O initialization condition. If DDRx-&gt; 1(set) the Output and DDRx-&gt; 0(clear) Input. Conditional operator \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 expression [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,9],"tags":[],"class_list":["post-499","post","type-post","status-publish","format-standard","hentry","category-basic-phepharials","category-i-o-port-operations"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/499","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=499"}],"version-history":[{"count":52,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":2528,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/2528"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}