{"id":126,"date":"2014-09-23T20:37:33","date_gmt":"2014-09-23T19:37:33","guid":{"rendered":"http:\/\/www.sarbyn.com\/tech\/?p=126"},"modified":"2014-09-23T20:37:33","modified_gmt":"2014-09-23T19:37:33","slug":"bluetooth-hc-06-arduino-rx1-and-tx1","status":"publish","type":"post","link":"https:\/\/www.sarbyn.com\/blog\/2014\/09\/23\/bluetooth-hc-06-arduino-rx1-and-tx1\/","title":{"rendered":"Bluetooth HC-06 + Arduino + RX1 and TX1"},"content":{"rendered":"<p>Yes&#8230;I&#8217;m alive.<br \/>\nIt&#8217;s about 1 year that I didn&#8217;t post something on this wonderful blog but I&#8217;ve been quite busy.<\/p>\n<p>But some days ago I bought a bluetooth module (HC-06, the cheapest module for Arduino) in order to integrate wireless capability in my HomeTemp project, and I want to share a simple thing about its configuration:<\/p>\n<p><strong>DO NOT WIRE THE MODULE TO RX1 (pin 0) AND TX1 (pin 1).<\/strong><\/p>\n<p>I tried the\u00a0easiest way to connect the module to an Arduino UNO board, using the standard RX1 and TX1 pin, but the behavior was a little confusing:<\/p>\n<ul>\n<li>The module sends correctly data via bluetooth<\/li>\n<li>The module does not receive any data via bluetooth<\/li>\n<\/ul>\n<p>I didn&#8217;t\u00a0understand why&#8230;maybe a &#8220;conflict&#8221; with the standard Serial USB communication. But after some experiments \u00a0I found a post somewhere that suggests to use the &#8220;<a title=\"SoftwareSerial Reference\" href=\"http:\/\/arduino.cc\/en\/Reference\/softwareSerial\" target=\"_blank\">SoftwareSerial<\/a>&#8221; Arduino Library and use two others PIN (10 and 11). With this simple configuration the following example works like a charm \ud83d\ude42 Not all pins support change interrupts, check the SoftwareSerial page and check which pins should work.<\/p>\n<p>Pair the device with your PC (the default pairing PIN is 1234) and then open a serial console (on Mac OSX I use &#8220;screen \/dev\/tty.XXXYYZZZ). You are now able to read and send data.<\/p>\n<p>I hope it could be helpful to someone.<\/p>\n<pre class=\"brush: cpp; collapse: false; title: BluetoothTest.ino; notranslate\" title=\"BluetoothTest.ino\">\r\n\r\n#include &lt;SoftwareSerial.h&gt;\r\n#define LED_PIN 12\r\n\r\nSoftwareSerial bluetoothSerial(10, 11);\r\n\r\nvoid setup() {\r\n  pinMode(LED_PIN, OUTPUT);  \r\n\r\n  \r\n  Serial.begin(57600);\r\n\r\n  bluetoothSerial.begin(9600);\r\n  bluetoothSerial.println(&quot;I'm ready&quot;);\r\n  \r\n  digitalWrite(LED_PIN, LOW);\r\n  delay(300);\r\n  digitalWrite(LED_PIN, HIGH);\r\n  delay(300);\r\n  digitalWrite(LED_PIN, LOW);\r\n  delay(300);\r\n  digitalWrite(LED_PIN, HIGH);\r\n  delay(300);\r\n  digitalWrite(LED_PIN, LOW);\r\n  \r\n  Serial.print(&quot;Ready to go&quot;);  \r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n  if (bluetoothSerial.available() &gt; 0) {\r\n    char inChar = bluetoothSerial.read();\r\n    if (inChar == '1') {\r\n        digitalWrite(LED_PIN, HIGH);\r\n        bluetoothSerial.print(&quot;ON&quot;);\r\n    }\r\n    else if (inChar == '0'){\r\n        digitalWrite(LED_PIN, LOW);\r\n        bluetoothSerial.print(&quot;OFF&quot;);\r\n    }\r\n  } \r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yes&#8230;I&#8217;m alive. It&#8217;s about 1 year that I didn&#8217;t post something on this wonderful blog but I&#8217;ve been quite busy. But some days ago I bought a bluetooth module (HC-06, the cheapest module for Arduino) in order to integrate wireless capability in my HomeTemp project, and I want to share a simple thing about its <a class=\"read-more\" href=\"https:\/\/www.sarbyn.com\/blog\/2014\/09\/23\/bluetooth-hc-06-arduino-rx1-and-tx1\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[10],"tags":[21,42],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-examples","tag-arduino","tag-bluetooth"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3JApm-22","jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/126"}],"collection":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":3,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/posts\/126\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sarbyn.com\/blog\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}