{"id":345,"date":"2021-08-04T14:16:53","date_gmt":"2021-08-04T12:16:53","guid":{"rendered":"https:\/\/automatico.freevar.com\/?page_id=345"},"modified":"2021-12-17T10:38:56","modified_gmt":"2021-12-17T09:38:56","slug":"dcf77","status":"publish","type":"page","link":"https:\/\/automatico.freevar.com\/index.php\/arduino\/dcf77\/","title":{"rendered":"DCF77"},"content":{"rendered":"<p><span style=\"font-size: 14pt;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-591 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77-Map-Europe-300x261.jpg\" alt=\"\" width=\"300\" height=\"261\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77-Map-Europe-300x261.jpg 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77-Map-Europe.jpg 659w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><span class=\"VIiyi\" lang=\"en\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"2\">DCF77 refers to a communication protocol that allows the time of a system to be synchronized with that propagated by a radio transmitter near Frankfurt (Germany).<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"2\">The signal is transmitted with the frequency of 77.5 kHz and a power of 50 kW.<\/span><\/span><br \/>\n<\/span><\/p>\n<p><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"1\">On the side we see the range of the signal that reaches 1900 km during the day and 2100 km at night (with better radio signal propagation) (source Wikipedia).<\/span> <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-358 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-04_175609-300x167.png\" alt=\"\" width=\"300\" height=\"167\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-04_175609-300x167.png 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-04_175609-768x426.png 768w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-04_175609.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"4\">The signal is encoded by modulating the carrier wave with the ASK (Amplitude Shift Keying) method.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"4\">The first line of the drawing illustrates a series of logic levels representing the bits, the second line is the carrier wave, the third is the amplitude modulated carrier in ASK.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"2\" data-number-of-phrases=\"4\">This kind of modulation is very sensitive to noise and is no longer used in current equipment.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"3\" data-number-of-phrases=\"4\">The side drawing is not to scale, in fact the modulation depth varies between 100% and 20%.<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/fidocad-dcf77.bmp\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-370 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/fidocad-dcf77-300x213.jpg\" alt=\"\" width=\"300\" height=\"213\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/fidocad-dcf77-300x213.jpg 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/fidocad-dcf77.bmp 440w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"4\">The radio receiver is a very simple circuit composed by a ferrite antenna and an electronic circuit tuned to the transmission frequency of 77.5 kHz.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"4\">The signal output from the receiver is like\u00a0 shown beside.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"2\" data-number-of-phrases=\"4\">One bit is transmitted every second: 0.9 seconds high and 0.1 seconds low means bit 0;<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"3\" data-number-of-phrases=\"4\">0.8 seconds high and 0.2 seconds low means bit 1.<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-959 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/12\/immagine_2021-12-17_103822-300x266.png\" alt=\"\" width=\"300\" height=\"266\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/12\/immagine_2021-12-17_103822-300x266.png 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/12\/immagine_2021-12-17_103822.png 535w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"2\">I didn&#8217;t buy the radio receiver, but I got it from an old radio controlled electronic clock.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"2\">The DCF77 output circuit provides a signal with inverted electrical levels, so I had to build an electronic signal inversion and electrical level adaptation circuit, with a bc547 transistor, to condition the signal and thus adapt it to the input of an Arduino nano.<\/span> <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-347 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio-300x225.jpg\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio-300x225.jpg 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio-1024x768.jpg 1024w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio-768x576.jpg 768w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio-1536x1152.jpg 1536w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/DCF77mio.jpg 1600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"2\">Here is the result after a night of waiting.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"2\">I put the circuit outside the house towards the north and powered it with a battery.<\/span> <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"0\" data-number-of-phrases=\"11\">Now let&#8217;s see how the software is structured.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"1\" data-number-of-phrases=\"11\">Mainly the program uses four libraries:<\/span> <\/span><\/p>\n<ul>\n<li><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"3\" data-number-of-phrases=\"11\">DCF77.h, completely manages the noisy signal of the radio receiver by intervening in the reading of the data through the interrupt technique.<\/span> <span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"4\" data-number-of-phrases=\"11\">This library was written by Udo Klein, to lock a signal even when there is a huge amount of noise and interference on the signal and thus allow easy synchronization.<\/span> <\/span><\/li>\n<li><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"6\" data-number-of-phrases=\"11\">LiquidCrystal_I2C.h to drive an LCD display.<\/span> <\/span><\/li>\n<li><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"8\" data-number-of-phrases=\"11\">Wire.h to communicate with I2C devices.<\/span> <\/span><\/li>\n<li><span class=\"VIiyi\" lang=\"en\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b ChMk0b\" data-language-for-alternatives=\"en\" data-language-to-translate-into=\"it\" data-phrase-index=\"10\" data-number-of-phrases=\"11\">Timelib.h instead provides time and date management functionality.<\/span> <\/span><\/li>\n<\/ul>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &quot;DCF77.h&quot;\r\n#include &lt;TimeLib.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;LiquidCrystal_I2C.h&gt;\r\n\r\n#define DCF_PIEDINO 2      \/\/ Connection pin to the DCF77 radio receiver\r\n#define DCF_INTERRUZIONE 0 \/\/ Interruption number associated with the radio reception pi\r\n#define PIEDINO_LED 13     \/\/ LED Arduino\r\n\r\nint valorePrecedente=0;\r\n\r\n\/\/ i2c Address, columns, lines of the LCD display\r\nLiquidCrystal_I2C lcd(0x27,16,2);\r\n\r\n\/\/ creates DCF77 object and attaches interruption number\r\nDCF77 DCF = DCF77(DCF_PIEDINO, DCF_INTERRUZIONE);\r\n\r\n\/\/ valid signal flag\r\nbool segnaleValido = false;\r\n\r\nvoid setup()\r\n{\r\n      lcd.begin();\r\n      pinMode(PIEDINO_LED, OUTPUT);\r\n      Serial.begin(9600);\r\n      \/\/ attiva l'oggetto DCF77\r\n      DCF.Start();\r\n      Serial.println(&quot;Waiting for signal from DCF77  ...&quot;);\r\n      Serial.println(&quot;It may takes at least 2 minutes.&quot;);\r\n      lcd.backlight();\r\n      lcd.setCursor(0,0);\r\n      lcd.print(&quot;Waiting for signal!&quot;);\r\n      lcd.setCursor(0,1);\r\n      lcd.print(&quot;2 minutes wait!&quot;);\r\n      delay(2000);\r\n      lcd.clear();\r\n}\r\n\r\nvoid loop()\r\n{\r\n      \/\/ signal presence interrogation every second\r\n      delay(950);\r\n      digitalWrite(PIEDINO_LED, HIGH);\r\n      delay(50);\r\n      digitalWrite(PIEDINO_LED, LOW);\r\n\r\n      \/\/ Signal presence test\r\n      time_t DCFtime = DCF.getTime();\r\n      if (DCFtime!=0)\r\n      {\r\n            Serial.println(&quot;Updated time&quot;);\r\n            setTime(DCFtime);\r\n            segnaleValido = true;\r\n            lcd.clear();\r\n      }\r\n\r\n     \/\/ Time has been set, the LED lights up briefly\r\n     if (segnaleValido)\r\n     {\r\n           delay(50);\r\n           digitalWrite(PIEDINO_LED, HIGH);\r\n     }\r\n     digitalClockDisplay();\r\n}\r\n\r\nvoid digitalClockDisplay()\r\n{\r\n      \/\/sends the time on serial line\r\n      stampaZeroSeriale(hour());\r\n      Serial.print(&quot;:&quot;);\r\n      stampaZeroSeriale(minute());\r\n      Serial.print(&quot;:&quot;);\r\n      stampaZeroSeriale(second());\r\n      Serial.print(&quot; &quot;);\r\n      Serial.print(day());\r\n      Serial.print(&quot; &quot;);\r\n      Serial.print(month());\r\n      Serial.print(&quot; &quot;);\r\n      Serial.print(year());\r\n      Serial.println();\r\n      lcd.setCursor(0,0);\r\n      stampaZeroSerialeLCD(hour());\r\n      \/\/ sends the time to the LCD\r\n      lcd.print(&quot;:&quot;);\r\n      stampaZeroSerialeLCD(minute());\r\n      lcd.print(&quot;:&quot;);\r\n      stampaZeroSerialeLCD(second());\r\n      lcd.setCursor(0,1);\r\n      lcd.print(day());\r\n      lcd.print(&quot; &quot;);\r\n      lcd.print(month());\r\n      lcd.print(&quot; &quot;);\r\n      lcd.print(year());\r\n}\r\n\r\nvoid stampaZeroSeriale(int cifra)\r\n{\r\n      \/\/ adjustment of the field\r\n      if(cifra &lt; 10)\r\n             Serial.print('0');\r\n      Serial.print(cifra);\r\n}\r\nvoid stampaZeroSerialeLCD(int cifra)\r\n{\r\n      \/\/ adjustment of the field\r\n      if(cifra &lt; 10)\r\n            lcd.print('0');\r\n      lcd.print(cifra);\r\n}\r\n\r\n<\/pre>\n<div style=\"width: 640px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-345-1\" width=\"640\" height=\"352\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/dcf77.mp4?_=1\" \/><a href=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/dcf77.mp4\">https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/dcf77.mp4<\/a><\/video><\/div>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_345\" class=\"pvc_stats all  \" data-element-id=\"345\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>DCF77 refers to a communication protocol that allows the time of a system to be synchronized with that propagated by a radio transmitter near Frankfurt (Germany). The signal is transmitted with the frequency of 77.5 kHz and a power of 50 kW. On the side we see the range of the signal that reaches 1900 [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_345\" class=\"pvc_stats all  \" data-element-id=\"345\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"parent":95,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-345","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/345"}],"collection":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/comments?post=345"}],"version-history":[{"count":29,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/345\/revisions"}],"predecessor-version":[{"id":960,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/345\/revisions\/960"}],"up":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/95"}],"wp:attachment":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/media?parent=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}