{"id":2386,"date":"2024-08-04T17:06:21","date_gmt":"2024-08-04T17:06:21","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=2386"},"modified":"2024-08-12T12:55:42","modified_gmt":"2024-08-12T12:55:42","slug":"load-control-using-sim","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=2386","title":{"rendered":"Load Control using SIM"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-763b663629b4ca50d69dadd2fd8ba3ee wp-block-paragraph\" style=\"color:#5c5c5c\">In GSM networking topology SIM (Subscriber Identity Module) is the key. In this article we use sms (short message service) to control load. For SIM reading we use module SIM900A GSM module. First look the connection diagram-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"282\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/SIM-Interface-1024x282.jpg\" alt=\"\" class=\"wp-image-2389\" style=\"width:800px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/SIM-Interface-1024x282.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/SIM-Interface-300x83.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/SIM-Interface-768x211.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/SIM-Interface.jpg 1203w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-a372feb559eef2e1da77a0138c684252 wp-block-paragraph\" style=\"color:#5c5c5c\">For transmission data the basic format is-<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"75\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-8-1024x75.jpg\" alt=\"\" class=\"wp-image-2392\" style=\"width:614px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-8-1024x75.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-8-300x22.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-8-768x56.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-8.jpg 1190w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-3879fd85931bbd3414e6bef7978d15f0 wp-block-paragraph\" style=\"color:#5c5c5c\">Here, &lt;CR&gt; Carriage Return (\u2018\\r\u2019 or 0x0D) \u2013 moves the cursor to the beginning of the line without advancing to the next line.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-62d7bc90f50badb0cb498cbbdf287567 wp-block-paragraph\" style=\"color:#5c5c5c\">&lt;LF&gt; &nbsp;&nbsp;Line feed (\u2018\\n\u2019 or 0x0A) \u2013 moves the cursor down to the next line without returning to the beginning of the line.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-16160b29ae8cfb0aa7d14c6d8376017d wp-block-paragraph\" style=\"color:#5c5c5c\">There are different commands for different function. We need only some. The SIM900 module come with default 9600 baud rate, 8 bit characters, no parity bit and one stop bit. First look at some basic commands.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"192\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-13-1024x192.jpg\" alt=\"\" class=\"wp-image-2396\" style=\"width:757px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-13-1024x192.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-13-300x56.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-13-768x144.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-13.jpg 1344w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-f193aeeeecb9c866e60b19db1b2f861a wp-block-paragraph\" style=\"color:#5c5c5c\">Let\u2019s first start with SIM9000 and send some call in\/call out function. We check the SIM is working or not and generate or received a call.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-a270f2a0c889704b8cef1106fc854994 wp-block-paragraph\" style=\"color:#6c8a97\">void sim_check(void) -&gt; Check if SIM900A is present or not<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nBEGAIN:\n    usart_puts(&quot;AT\\r\\n&quot;);\/\/Response OK\n\t_delay_ms(500);\n\tbuffer=strstr(receive,&quot;OK&quot;);\n\tif(buffer&#x5B;0]==&#039;O&#039; &amp;&amp; buffer&#x5B;1]==&#039;K&#039;)\n\tLCD_write_string(1,1,&quot;GSM Module found&quot;);\n\telse \n\tgoto BEGAIN;\n\tcont=0; \/\/initial counter\n\tusart_puts(&quot;ATE0\\r\\n&quot;);\/\/Echo mode deactivate\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-bc4c894151aea5e48acdd4987fa2a8c1 wp-block-paragraph\" style=\"color:#6c8a97\">void SM_CALL_IN(char *mobile_number) -&gt; call in function<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvolatile char display&#x5B;17];\nsprintf(display,&quot;ATD%s;\\r\\n&quot;,mobile_number);\nusart_puts(display);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-aec74375926d13a3b0413268324a2edb wp-block-paragraph\" style=\"color:#6c8a97\">void SM_CALL_HALT(void) -&gt; Terminate call<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nusart_puts(&quot;ATH\\r\\n&quot;);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-41601bede47d1cd02deeea5ed1b7a662 wp-block-paragraph\" style=\"color:#6c8a97\">void SM_CALL_RECEIVE(void) -&gt; Receive all call<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nusart_puts(&quot;ATA\\r\\n&quot;);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-5b343c23a87fea7e518c4b5cd8a962e3 wp-block-paragraph\" style=\"color:#5c5c5c\">Whenever we transmit a string the device response with final 0x0D 0x0A character. Initialize UART with Rx transmission interrupt enable. In Rx interrupt service routine use a global variable to received context.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-b60315f4f67f17ef0136359689e67f7f wp-block-paragraph\" style=\"color:#6c8a97\">ISR(USART_RXC_vect) -&gt; Rx service routine global variable receive, cont<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nreceive&#x5B;cont++] = UDR; \/\/Read the data from buffer\nUCSRA|=(1&lt;&lt;RXC); \/\/Clear the interrupt flag\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-cb387edfcae0a77a23e3a0871b3bab4b wp-block-paragraph\" style=\"color:#5c5c5c\">Our main target is to control load using SMS, so let look at the command need for SMS function.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"192\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-14-1024x192.jpg\" alt=\"\" class=\"wp-image-2409\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-14-1024x192.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-14-300x56.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-14-768x144.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/table-14.jpg 1342w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-0641cbd72682455be839347865cee2bc wp-block-paragraph\" style=\"color:#5c5c5c\">Whenever a massage received the device with +CMTI: &#8220;SM&#8221;,1 \u2013 a massage received response number 1 and &#8220;SM&#8221; is the SIM memory. To read the massage just send &#8220;AT+CMGR=1\\r\\n&#8221; string. Function to display SMS and Number on the LCD display-<\/p>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-cd7588cd3a90f220ee50a32c8789d366 wp-block-paragraph\" style=\"color:#6c8a97\">void SM_READ_MSG(void) -&gt; Read SMS and shows the SMS received number<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvolatile uint8_t len,num_msg;\nvolatile char test&#x5B;20],*buffer,display&#x5B;120],number&#x5B;12],msg&#x5B;80];\n  if(strstr(receive,&quot;CMTI&quot;)){\n      LCD_Clear();\n      cont=0; \/\/initial counter\n      sprintf(test,&quot;AT+CMGR=%d\\r\\n&quot;,num_msg);\n      usart_puts(test);\/\/Read SMS\n      sprintf(display,&quot;%s&quot;,receive);\n      if(strstr(display,&quot;READ&quot;)){\n            for(uint8_t i=0;i&lt;=120;i++){\n                 if(display&#x5B;i]==&#039;+&#039; &amp;&amp; display&#x5B;i+1]==&#039;8&#039; &amp;&amp; display&#x5B;i+2]==&#039;8&#039;){\n                      for(uint8_t j=0;j&lt;11;j++)\n                      number&#x5B;j]=display&#x5B;i+3+j]; \/\/11 digit number\n                      }\n                 if(i&gt;40 &amp;&amp; display&#x5B;i]==&#039;\\r&#039;){\n                      for(uint8_t k=0;k&lt;40;k++)\n                      msg&#x5B;k]=display&#x5B;i+k+2];        \/\/sms display\n                      break;\n                }\n            }\n    }\n  LCD_write_string(1,1,number);\n  LCD_write_string(1,2,msg);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-676bf30c28cbf5561232bd7b5fd0f15d wp-block-paragraph\" style=\"color:#5c5c5c\">In the function you get the mobile number and the text of the massage. You can do any function according to the number and text massage. Connect SIM900A module with ATmega8, use a SIM. Send &#8220;Load1 on&#8221; to turn on load 1 and &#8220;Load1 off&#8221; to off the load1. Send &#8220;Load2 on&#8221; to turn on load 2 and &#8220;Load2 off&#8221; to off the load2.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"87\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/image.png\" alt=\"\" class=\"wp-image-2412\" style=\"width:450px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/image.png 851w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/image-300x31.png 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/image-768x79.png 768w\" sizes=\"(max-width: 851px) 100vw, 851px\" \/><\/figure>\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-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\/GSM-Based-SMS-System.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)\">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-text-color has-link-color has-medium-font-size wp-elements-0719abbce81ad7a32db1d9296cc44d3d wp-block-paragraph\" style=\"color:#252525\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/GSM-Based-SMS-System.rar\">Load Control using SIM<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-bb7ded419f83de98400a1a7ce6a4eed9 wp-block-paragraph\" style=\"color:#5c5c5c\">You can simulate in proteus COMPIM terminal. The terminal is same as PuTTy or realturm terminal. Just connect the SIM module with PC via CP2101 or similar device. Then in proteus you can see the real time tracking.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In GSM networking topology SIM (Subscriber Identity Module) is the key. In this article we use sms (short message service) to control load. For SIM reading we use module SIM900A GSM module. First look the connection diagram- For transmission data the basic format is- Here, &lt;CR&gt; Carriage Return (\u2018\\r\u2019 or 0x0D) \u2013 moves the cursor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-2386","post","type-post","status-publish","format-standard","hentry","category-uart"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2386","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=2386"}],"version-history":[{"count":14,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2386\/revisions"}],"predecessor-version":[{"id":2663,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2386\/revisions\/2663"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}