{"id":261,"date":"2013-02-10T23:46:44","date_gmt":"2013-02-10T22:46:44","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=261"},"modified":"2014-05-09T23:05:14","modified_gmt":"2014-05-09T21:05:14","slug":"arduino-send-and-receive-data-thru-radio-frequency-rf433","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=261","title":{"rendered":"Arduino : send and receive data thru radio frequency (RF433)"},"content":{"rendered":"<p>I wanted to find a way to call my kids, with me sitting on ground floor and them, sitting on the top floor of the house.<\/p>\n<p>2 arduino, one acting as transmitter, one acting as receiver and here we go : they would not ignore me anymore \ud83d\ude42<\/p>\n<p><strong>Lets start the transmitter (schema and code)<\/strong> : it has a push button to send the signal and a led to indicate it is transmitting.<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/tx_button_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/tx_button_bb-300x275.png\" alt=\"tx_button_bb\" width=\"300\" height=\"275\" class=\"alignnone size-medium wp-image-260\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/tx_button_bb-300x275.png 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/tx_button_bb.png 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>\r\n#include <VirtualWire.h>\r\n\r\nconst int led_pin = 11;\r\n\/\/const int transmit_pin = 4;\r\n\/\/const int transmit_en_pin = 3;\r\nconst int transmit_pin = 3;\r\n\/\/const int transmit_en_pin = 3;\r\nconst int buttonPin=2;\r\n\r\n\r\nvoid setup()\r\n{\r\n\r\n   pinMode(buttonPin, INPUT);        \/\/ sets the digital pin as output\r\n  pinMode(led_pin, OUTPUT);      \/\/ sets the digital pin as output\r\n      delay(1000);\r\n    Serial.begin(9600);\t\/\/ Debugging only\r\n    Serial.println(\"setup\");\r\n  \/\/ Initialise the IO and ISR\r\n  vw_set_tx_pin(transmit_pin);\r\n  \/\/vw_set_rx_pin(receive_pin);\r\n  \/\/vw_set_ptt_pin(transmit_en_pin);\r\n  \/\/vw_set_ptt_inverted(true); \/\/ Required for DR3100\r\n  vw_set_ptt_inverted(false); \r\n  vw_setup(2400);\t \/\/ Bits per sec\r\n}\r\n\r\nbyte count = 1;\r\n\r\nvoid loop()\r\n{\r\n  int reading = digitalRead(buttonPin);\r\n  if(reading==HIGH) {\r\n   \/\/\r\n  digitalWrite(led_pin, HIGH); \/\/ Flash a light to show transmitting\r\n char msg[7] = {'h','e','l','l','o',' ','#'};\r\n \/\/msg[5]=count;\r\n  vw_send((uint8_t *)msg, strlen(msg)+1);\r\n  vw_wait_tx(); \/\/ Wait until the whole message is gone\r\n  Serial.println(count);\r\n  count = count + 1;\r\n  delay(500);\r\n  digitalWrite(led_pin, LOW);\r\n  }\r\n}\r\n<\/pre>\n<p><strong>Next comes the receiver<\/strong> : it has a buzzer playing a small melody and a led blinking to indicate it is receiving.<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/rx_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/rx_bb-300x104.png\" alt=\"rx_bb\" width=\"300\" height=\"104\" class=\"alignnone size-medium wp-image-259\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/rx_bb-300x104.png 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/02\/rx_bb.png 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>\r\n#include <VirtualWire.h>\r\n#include <pitches.h>\r\n\r\nconst int led_pin = 8;\r\nconst int receive_pin = 3; \/\/2\r\nconst int buzzer=11;\r\n\r\n\/\/ tableau de m\u00e9morisation des notes de la m\u00e9lodie\r\nint melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};\r\n\r\n\/\/ tableau de m\u00e9morisation de la dur\u00e9e des notes : 4 = noire, 8 = croche, etc.:\r\nint noteDurations[] = {4, 8, 8, 4,4,4,4,4 };\r\n  \r\n  void play(){\r\n    \/\/ boucle pour parcourir les notes de la m\u00e9lodie\r\n  for (int thisNote = 0; thisNote < 8; thisNote++) { \/\/ thisNote de 0 \u00e0 7 \r\n\r\n    \/\/ pour calculer la dur\u00e9e de la note, on divise 1 seconde par le type de la note\r\n    \/\/ainsi noire = 1000 \/ 4 sec, croche = 1000\/8 sec, etc...\r\n    int noteDuration = 1000\/noteDurations[thisNote];\r\n\r\n    \/\/ joue la note sur la broche x pendant la dur\u00e9e voulue\r\n    tone(buzzer, melody[thisNote],noteDuration);\r\n\r\n    \/\/ pour distinguer les notes, laisser une pause entre elles\r\n    \/\/ la dur\u00e9e de la note + 30% fonctionne bien :\r\n    int pauseBetweenNotes = noteDuration * 1.30;\r\n    delay(pauseBetweenNotes); \/\/ delai entre les notes\r\n\r\n    \/\/ stoppe la production de son sur la broche 8 :\r\n    noTone(buzzer);\r\n  }\r\n  }\r\n\r\nvoid setup()\r\n{\r\n   pinMode(led_pin, OUTPUT);        \/\/ sets the digital pin as output\r\n  pinMode(buzzer, OUTPUT);      \/\/ sets the digital pin as output\r\n    delay(1000);\r\n    Serial.begin(9600);\t\/\/ Debugging only\r\n    Serial.println(\"setup\");\r\n\r\n    \/\/ Initialise the IO and ISR\r\n    \/\/vw_set_tx_pin(transmit_pin);\r\n    vw_set_rx_pin(receive_pin);\r\n    \/\/vw_set_ptt_pin(transmit_en_pin);\r\n    \/\/vw_set_ptt_inverted(true); \/\/ Required for DR3100\r\n    vw_set_ptt_inverted(false); \r\n    vw_setup(2400);\t \/\/ Bits per sec\r\n    vw_rx_start();       \/\/ Start the receiver PLL running\r\n}\r\n\r\nvoid loop()\r\n{\r\n    uint8_t buf[VW_MAX_MESSAGE_LEN];\r\n    uint8_t buflen = VW_MAX_MESSAGE_LEN;\r\n\r\n    if (vw_get_message(buf, &#038;buflen)) \/\/ Non-blocking\r\n    {\r\n\tint i;\r\n\r\n        \r\n\t\/\/ Message with a good checksum received, print it.\r\n\tSerial.print(\"Got: \");\r\n\t\r\n\tfor (i = 0; i < buflen; i++)\r\n\t{\r\n\t    Serial.print(buf[i], HEX);\r\n\t    Serial.print(' ');\r\n\t}\r\n        Serial.print(' ');\r\n        for (i = 0; i < buflen; i++)\r\n\t{\r\n\t    Serial.print(char(buf[i]));\r\n\t    Serial.print(' ');\r\n\t}\r\n\tSerial.println();\r\n        digitalWrite(led_pin, HIGH);delay(1500);digitalWrite(led_pin, LOW);delay(1500);\r\n        digitalWrite(led_pin, HIGH);delay(1500);digitalWrite(led_pin, LOW);delay(1500);       \r\n        play();\r\n    }\r\n}\r\n<\/pre>\n<p>Voila !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to find a way to call my kids, with me sitting on ground floor and them, sitting on the top floor of the house. 2 arduino, one acting as transmitter, one acting as receiver and here we go : they would not ignore me anymore \ud83d\ude42 Lets start the transmitter (schema and code) <a href='https:\/\/labalec.fr\/erwan\/?p=261' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-261","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=261"}],"version-history":[{"count":8,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":1217,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/261\/revisions\/1217"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}