{"id":543,"date":"2016-03-20T21:22:35","date_gmt":"2016-03-21T02:22:35","guid":{"rendered":"http:\/\/adaming.com\/blog\/?p=543"},"modified":"2016-03-20T21:22:35","modified_gmt":"2016-03-21T02:22:35","slug":"arduino-projects-jy-mcu-hc-06","status":"publish","type":"post","link":"http:\/\/adaming.com\/blog\/index.php\/archive\/arduino-projects-jy-mcu-hc-06\/","title":{"rendered":"Arduino Projects:  JY-MCU \/ HC-06"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-549\" src=\"http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160320_222055-300x225.jpg\" alt=\"IMG_20160320_222055\" width=\"300\" height=\"225\" srcset=\"http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160320_222055-300x225.jpg 300w, http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160320_222055-768x576.jpg 768w, http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160320_222055-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>I installed the Bluetooth module on a chassis with a Arduino and a motor shield in anticipation of having a Bluetooth controlled robot.<\/p>\n<p>&nbsp;<\/p>\n<p>Lately I&#8217;ve found myself with some extra time and wanting to do some Ardunio projects. \u00a0I&#8217;m working on controlling a small robot with some DC motors and perhaps putting a buzzer on it, a range sensor for collision avoidance and maybe a mechanical arm to pick things up. \u00a0I purchased the module from <a href=\"http:\/\/www.amazon.com\/gp\/product\/B0093XAV4U?psc=1&amp;redirect=true&amp;ref_=oh_aui_detailpage_o00_s01\">Amazon for $10<\/a>.<\/p>\n<p>I&#8217;ve been working trying to get the bluetooth\u00a0module JY-MCU\/HC-06 to work, but unfortunately it took a bit of a learning curve. \u00a0Here is what I found from reading:<\/p>\n<ul>\n<li>Although the RX line claims it needs 3.3V, 5V is fine.<\/li>\n<li>The JY-MCU doesn&#8217;t need RX\/TX to be discovered; all it needs is power and the blinking red light to be discovered<\/li>\n<li>My Nexus 5 Android version 6 doesn&#8217;t detect<\/li>\n<li>I tried a Samsung Galaxy S2. \u00a0The HC-06\u00a0was discoverable but would drop the connection after about 20s.<\/li>\n<\/ul>\n<ul>\n<li>Commands can be issued through the serial command window in the Ardiuno IDE. \u00a0Here is a link to the\u00a0<a href=\"http:\/\/www.martyncurrey.com\/arduino-and-hc-06-zs-040\/\">list of the commands<\/a><\/li>\n<li>Here is the <a href=\"http:\/\/www.tec.reutlingen-university.de\/uploads\/media\/DatenblattHC-05_BT-Modul.pdf\">HC06 datasheet<\/a><\/li>\n<li>Baud Rate is 9600 by default<\/li>\n<li>I used Sena Blueterm, free on the Android Play store, to send commands from my Nexus 7 to the device. \u00a0Here is a <a href=\"http:\/\/www.ohmex.com\/senabterm.pdf\">tutorial<\/a>.<\/li>\n<li>I&#8217;m using <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=Qwerty.BluetoothTerminal&amp;hl=en\">Bluetooth Terminal<\/a> from the Android play store.<\/li>\n<\/ul>\n<h2>Code used to confirm that the Arduino Uno has received information from Computer &#8211;&gt; Ardiuno &#8211;&gt; Computer<\/h2>\n<blockquote><p>int incomingByte = 0; \/\/ for incoming serial data<\/p>\n<p>void setup() {<br \/>\nSerial.begin(9600); \/\/ opens serial port, sets data rate to 9600 bps<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>\/\/ send data only when you receive data:<br \/>\nif (Serial.available() &gt; 0) {<br \/>\n\/\/ read the incoming byte:<br \/>\nincomingByte = Serial.read();<\/p>\n<p>\/\/ say what you got:<br \/>\nSerial.print(&#8220;I received: &#8220;);<br \/>\nSerial.println(incomingByte, DEC);<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<ul>\n<li>Nexus 7 tablet can discover the HC-06, but gives a &#8220;failed to connect device&#8221; error. \u00a0Went to sleep, then tried it again next morning with passcode &#8216;1234&#8217; and it paired. \u00a0Weird.<\/li>\n<li>Turning the BT receiver\/transmitter in Android (pulldown dashboard box) seems to help.<\/li>\n<\/ul>\n<h2>Lighting an LED by sending commands over \u00a0Serial via the Arduino IDE<\/h2>\n<blockquote><p>char blueToothVal; \/\/value sent over via bluetooth<br \/>\nchar lastValue; \/\/stores last state of device (on\/off)<\/p>\n<p>void setup()<br \/>\n{<br \/>\nSerial.begin(9600);<br \/>\npinMode(13,OUTPUT);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\nif(Serial.available())<br \/>\n{\/\/if there is data being recieved<br \/>\nblueToothVal=Serial.read(); \/\/read it<br \/>\n}<br \/>\nif (blueToothVal==&#8217;n&#8217;)<br \/>\n{\/\/if value from bluetooth serial is n<br \/>\ndigitalWrite(13,HIGH); \/\/switch on LED<br \/>\nif (lastValue!=&#8217;n&#8217;)<br \/>\nSerial.println(F(&#8220;LED is on&#8221;)); \/\/print LED is on<br \/>\nlastValue=blueToothVal;<br \/>\n}<br \/>\nelse if (blueToothVal==&#8217;f&#8217;)<br \/>\n{\/\/if value from bluetooth serial is n<br \/>\ndigitalWrite(13,LOW); \/\/turn off LED<br \/>\nif (lastValue!=&#8217;f&#8217;)<br \/>\nSerial.println(F(&#8220;LED is off&#8221;)); \/\/print LED is on<br \/>\nlastValue=blueToothVal;<br \/>\n}<br \/>\ndelay(1000);<br \/>\n}<\/p><\/blockquote>\n<h2>Lighting the LED via Bluetooth<\/h2>\n<blockquote><p>#include<br \/>\nSoftwareSerial BT(10, 11);<br \/>\n\/\/ creates a &#8220;virtual&#8221; serial port\/UART<br \/>\n\/\/ connect BT module TX to D10<br \/>\n\/\/ connect BT module RX to D11<br \/>\n\/\/ connect BT Vcc to 5V, GND to GND<br \/>\nvoid setup()<br \/>\n{<br \/>\n\/\/ set digital pin to control as an output<br \/>\npinMode(13, OUTPUT);<br \/>\n\/\/ set the data rate for the SoftwareSerial port<br \/>\nBT.begin(9600);<br \/>\n\/\/ Send test message to other device<br \/>\nBT.println(&#8220;Hello from Arduino&#8221;);<br \/>\n}<br \/>\nchar a; \/\/ stores incoming character from other device<br \/>\nvoid loop()<br \/>\n{<br \/>\nif (BT.available())<br \/>\n\/\/ if text arrived in from BT serial&#8230;<br \/>\n{<br \/>\na=(BT.read());<br \/>\nif (a==&#8217;1&#8242;)<br \/>\n{<br \/>\ndigitalWrite(13, HIGH);<br \/>\nBT.println(&#8220;LED on&#8221;);<br \/>\n}<br \/>\nif (a==&#8217;2&#8242;)<br \/>\n{<br \/>\ndigitalWrite(13, LOW);<br \/>\nBT.println(&#8220;LED off&#8221;);<br \/>\n}<br \/>\nif (a==&#8217;?&#8217;)<br \/>\n{<br \/>\nBT.println(&#8220;Send &#8216;1&#8217; to turn LED on&#8221;);<br \/>\nBT.println(&#8220;Send &#8216;2&#8217; to turn LED on&#8221;);<br \/>\n}<br \/>\n\/\/ you can add more &#8220;if&#8221; statements with other characters to add more commands<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<ul>\n<li>Arduino is not responding to command sent over bluetooth\n<ul>\n<li>Checked each jumper cable by lighting up and LED. \u00a0Cables are fine.<\/li>\n<li>Unplugged the module and plugged it back in. \u00a0It works!<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Next step, writing the code to control the motors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I installed the Bluetooth module on a chassis with a Arduino and a motor shield in anticipation of having a Bluetooth controlled robot. &nbsp; Lately I&#8217;ve found myself with some extra time and wanting to do some Ardunio projects. \u00a0I&#8217;m working on controlling a small robot with some DC motors and perhaps putting a buzzer &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/adaming.com\/blog\/index.php\/archive\/arduino-projects-jy-mcu-hc-06\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Arduino Projects:  JY-MCU \/ HC-06&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/543"}],"collection":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=543"}],"version-history":[{"count":5,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/543\/revisions"}],"predecessor-version":[{"id":550,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/543\/revisions\/550"}],"wp:attachment":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=543"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}