{"id":2805,"date":"2018-06-08T17:09:34","date_gmt":"2018-06-08T09:09:34","guid":{"rendered":"https:\/\/drho.club\/?p=2234"},"modified":"2018-06-08T17:09:34","modified_gmt":"2018-06-08T09:09:34","slug":"arduino-bluetooth-mobile-phone01","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2018\/06\/08\/arduino-bluetooth-mobile-phone01\/","title":{"rendered":"\u3010Arduino\u3011\u4f7f\u7528\u624b\u6a5f\u900f\u904e\u85cd\u7259\u63a7\u5236Arduino"},"content":{"rendered":"<p>\u9019\u4e00\u6b21\u6211\u5011\u8981\u7df4\u7fd2\u7684\u662fArduino\u7684\u85cd\u7259\u6a21\u7d44\uff0c\u900f\u904e\u9019\u500b\u6a21\u7d44\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5728\u4e0d\u540c\u7684Arduino\u4e4b\u9593\u76f8\u4e92\u901a\u8a0a\uff0c\u540c\u6642\u4e5f\u53ef\u4ee5\u4f7f\u7528\u624b\u6a5f\u7684APP\u7a0b\u5f0f\u63a7\u5236Arduino\u4e0a\u7684\u8f38\u51fa\u88dd\u7f6e\u3002\u5982\u679c\u540c\u5b78\u5011\u5b78\u6703\u4e86\u9019\u9805\u6280\u5de7\uff0c\u5c31\u53ef\u4ee5\u505a\u51fa\u8a31\u591a\u5229\u7528\u624b\u6a5f\u63a7\u5236Arduino\u9059\u63a7\u8eca\u3001\u5bb6\u7528\u96fb\u5668\u4ee5\u53ca\u4efb\u4f55\u5176\u5b83\u4f7f\u7528Arduino\u9023\u63a5\u7684\u88dd\u7f6e\u3002<\/p>\n<p>\u9019\u6b21\u8981\u4f7f\u7528\u7684\u6a21\u7d44\u662fHC-06\uff0c\u6b63\u9762\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.45.40.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2235 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.45.40.jpg\" alt=\"\" width=\"400\" height=\"177\" \/><\/a><\/p>\n<p>\u5b83\u7684\u80cc\u9762\u6709\u5404\u500b\u63a5\u8173\u7684\u8aaa\u660e\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.45.34.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2236 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.45.34.jpg\" alt=\"\" width=\"400\" height=\"195\" \/><\/a><\/p>\n<p>\u5176\u4e2d\u6211\u5011\u6703\u4f7f\u7528\u5230\u7684\u662fVCC\u3001GND\u3001TXD\u3001\u4ee5\u53caRXD\u9019\u5e7e\u500b\u63a5\u8173\u3002VCC\u7576\u7136\u662f\u63a55V\uff0cGND\u63a5GND\uff0c\u800cTXD\u4ee5\u53caRXD\u5206\u5225\u662f\u4e32\u5217\u5354\u5b9a\u7684\u50b3\u9001\u548c\u63a5\u6536\uff0c\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\u6211\u5011\u8981\u5206\u5225\u628a\u5b83\u5011\u9023\u63a5\u5230Atduino\u7684D10\u548cD11\u9019\u5169\u500bGPIO\u63a5\u8173\u3002\u9023\u63a5\u4e4b\u5f8c\u7684\u6a23\u5b50\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.41.33.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2237 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.41.33.jpg\" alt=\"\" width=\"700\" height=\"525\" \/><\/a><\/p>\n<p>\u70ba\u4e86\u793a\u7bc4\u53ef\u4ee5\u900f\u904e\u624b\u6a5f\u63a7\u5236Arduino\uff0c\u6240\u4ee5\u6211\u5011\u518d\u52a0\u4e0a\u4e86\u4e00\u500b3\u8272LED\u7684\u6a21\u7d44\uff08\u4e5f\u53ef\u4ee5\u7528\u4e00\u822c\u7684LED\uff0c\u4f46\u662f\u5c31\u8981\u52a0\u4e0a\u9650\u6d41\u96fb\u963b\uff09\uff0c\u4e26\u628a\u5b83\u63a5\u5230D2\u4e0a\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.39.54.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2238 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/2018-06-08-16.39.54.jpg\" alt=\"\" width=\"700\" height=\"525\" \/><\/a><\/p>\n<p>\u6b64\u85cd\u7259\u6a21\u7d44\u4f7f\u7528\u7684\u662f\u4e32\u5217\u57e0\u7684\u64cd\u4f5c\u65b9\u5f0f\uff0c\u800c\u4e14\u7528SoftwareSerial\u9019\u500b\u985e\u5225\u4f86\u9032\u884c\u64cd\u4f5c\u3002\u5728Arduino\u7aef\u7684\u7a0b\u5f0f\u5982\u4e0b\uff08\u53c3\u8003\u7db2\u8def\u6587\u7ae0\u4fee\u6539\uff1ahttp:\/\/blog.cavedu.com\/2013\/11\/08\/appinventorandarduinowithbluetooth\/\uff09\uff1a<\/p>\n<p>[code]<br \/>\n#include &lt;SoftwareSerial.h&gt;<br \/>\n#include &lt;Wire.h&gt;<\/p>\n<p>int LED = 2;<br \/>\nSoftwareSerial BT(10,11); <\/p>\n<p>void setup() {<br \/>\n  BT.begin(38400);<br \/>\n  pinMode(LED, OUTPUT);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n  byte cmd[20];<br \/>\n  int strsize;<br \/>\n  while(true){<br \/>\n    if ((strsize=(BT.available()))&gt;0){<br \/>\n      for (int i=0; i&lt;strsize; i++){<br \/>\n        cmd[i]=char(BT.read());<br \/>\n      }<br \/>\n    }<br \/>\n    if (cmd[0]==&#8217;a&#8217;) {<br \/>\n      digitalWrite(LED, HIGH);<br \/>\n    } else {<br \/>\n      digitalWrite(LED, LOW);<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>\u5148\u4f86\u770b\u57f7\u884c\u7684\u793a\u7bc4\u5f71\u7247\uff1a<\/p>\n<p><iframe loading=\"lazy\" title=\"\u624b\u6a5f\u900f\u904e\u85cd\u7259\u63a7\u5236Arduino\u4e0a\u7684LED\u793a\u7bc4\u5f71\u7247\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/I3vOx1l8_rQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>\u6b64\u7a0b\u5f0f\u4e3b\u8981\u662f\u900f\u904eSoftwareSerial\u9019\u500b\u985e\u5225\u53bb\u555f\u7528\u85cd\u7259\u505a\u70ba\u4e32\u5217\u50b3\u8f38\uff0c\u4e00\u958b\u59cb\u5c31\u8981\u6b63\u78ba\u5730\u8a2d\u5b9aTXD\u548cRXD\u7684\u8173\u4f4d\uff0c\u5728\u9019\u88e1\u6211\u5011\u4f7f\u7528\u7684\u985e\u5225\u57f7\u884c\u5be6\u4f8b\u540d\u7a31\u70baBT\uff0c\u63a5\u8457\u5728setup\u7684\u51fd\u6578\u4e2d\u8981\u6307\u5b9a\u6b63\u78ba\u7684Baud Rate\u505a\u70ba\u555f\u59cb\uff0c\u4e0d\u540c\u7684\u6a21\u7d44\u7684\u9810\u8a2dbaud rate\u90fd\u4e0d\u592a\u4e00\u6a23\uff0c\u7b46\u8005\u7684\u4f8b\u5b50\u662f 38400\uff0c\u5982\u679c\u4f60\u767c\u73fe\u7a0b\u5f0f\u7121\u6cd5\u6b63\u78ba\u63a5\u6536\u5b57\u4e32\u7684\u8a71\uff0c\u53ef\u4ee5\u8a66\u8a669600\u6216\u662f57600\u7b49\u7b49\u3002<\/p>\n<p>\u5982\u679c\u8a2d\u5b9a\u6b63\u78ba\u7684\u8a71\uff0c\u4f7f\u7528\u4e00\u500b\u7121\u7aae\u8ff4\u5708\u5c31\u53bb\u67e5\u8a62BT.available()\uff0c\u770b\u770b\u5728\u85cd\u7259\u7aef\u662f\u5426\u6709\u8cc7\u6599\u50b3\u9001\u9032\u884c\uff0c\u5982\u679c\u6709\u7684\u8a71\uff0c\u5c31\u900f\u904eBT.read()\u51fd\u6578\u57f7\u884c\u8b80\u53d6\u8cc7\u6599\u7684\u4f5c\u696d\uff0c\u4e00\u6b21\u8b80\u53d6\u4e00\u500b\u5b57\u5143\uff0c\u8b80\u53d6\u4e4b\u5f8c\u518d\u9010\u4e00\u653e\u5165\u5b57\u5143\u9663\u5217\u4e2d\uff0c\u4e4b\u5f8c\u518d\u6aa2\u67e5\u5176\u5167\u5bb9\u5373\u53ef\uff0c\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u6aa2\u67e5\u7b2c\u4e00\u500b\u6536\u5230\u7684\u5b57\u5143\uff0c\u5982\u679c\u662f&#8217;a&#8217;\uff0c\u5c31\u958b\u555fLED\uff0c\u5982\u679c\u662f\u5176\u5b83\u7684\u5b57\u5143\uff0c\u5247\u4e00\u5f8b\u628aLED\u95dc\u9589\u3002<\/p>\n<p>\u4ee5\u4e0a\u662f\u85cd\u7259\u7aef\u7684\u63a5\u6536\u7a0b\u5f0f\uff0c\u800c\u767c\u9001\u7aef\u5247\u662f\u4ee5APP Inventor\u4f86\u88fd\u4f5c\u4e00\u652f\u624b\u6a5fAPP\uff0c\u5efa\u7acb\u85cd\u7259\u9023\u7dda\u4e26\u767c\u5c04\u6b63\u78ba\u7684\u5b57\u5143\u3002\u4ee5\u4e0b\u662fAPP\u7684\u4ecb\u9762\u4f48\u7f6e\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2241\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.12.png\" alt=\"\" width=\"373\" height=\"629\" \/><\/a><\/p>\n<p>\u4ee5\u4e0b\u662f\u6240\u6709\u4f7f\u7528\u5230\u7684\u5143\u4ef6\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.18.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2242\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.18.png\" alt=\"\" width=\"169\" height=\"196\" \/><\/a><\/p>\n<p>\u5176\u4e2d\u7b2c\u4e00\u500b\u662f\u6e05\u55ae\u9078\u64c7\u5668\uff0c\u4e2d\u9593\u4e09\u500b\u662f\u6309\u9215\u5143\u4ef6\uff0c\u6700\u5f8c\u4e00\u500b\u5247\u662f\u85cd\u7259\u5ba2\u6236\u7aef\u3002\u7a0b\u5f0f\u4e00\u958b\u59cb\u57f7\u884c\u7684\u6642\u5019\uff0c\u5148\u628a\u5404\u6309\u9215\u7684\u53ef\u7528\u4e0d\u53ef\u7528\u5148\u8655\u7406\u597d\uff0c\u5982\u4e0b\u6240\u793a\uff0c\u4ee5\u78ba\u4fdd\u4e00\u958b\u59cb\u7684\u6642\u5019\u4e00\u5b9a\u8981\u5148\u6309\u6e05\u55ae\u9078\u64c7\u5668\uff0c\u9032\u884c\u85cd\u7259\u88dd\u7f6e\u7684\u641c\u5c0b\u548c\u9023\u7dda\u4f5c\u696d\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.46.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2243 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.46.png\" alt=\"\" width=\"374\" height=\"168\" \/><\/a><\/p>\n<p>\u6309\u4e0b\u6e05\u55ae\u9078\u64c7\u5668\u7684\u6642\u5019\uff0c\u5728\u9078\u5230\u9805\u76ee\u4e4b\u524d\u5c31\u8981\u5148\u9032\u884c\u85cd\u7259\u88dd\u7f6e\u7684\u6383\u63cf\u4f5c\u696d\uff0c\u5217\u51fa\u9644\u4ef6\u6240\u6709\u53ef\u4ee5\u9023\u7dda\u7684\u88dd\u7f6e\u6e05\u55ae\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.54.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2244\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.42.54.png\" alt=\"\" width=\"498\" height=\"84\" \/><\/a><\/p>\n<p>\u6709\u4e86\u6e05\u55ae\u4e4b\u5f8c\uff0c\u5373\u53ef\u9078\u64c7\u6211\u5011\u7684\u85cd\u7259\u6a21\u7d44\uff08 HC-06\uff09\u9032\u884c\u9023\u7dda\uff0c\u9023\u7dda\u7684\u4f5c\u696d\u5982\u4e0b\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2246\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.13.png\" alt=\"\" width=\"532\" height=\"229\" \/><\/a><\/p>\n<p>\u5b8c\u6210\u9023\u7dda\u4e4b\u5f8c\uff0c\u9700\u8981\u628a\u5176\u5b83\u7684\u6309\u9215\u555f\u7528\uff0c\u7136\u5f8c\u628a\u6e05\u55ae\u9078\u64c7\u5668\u7684\u6309\u9215\u53d6\u6d88\u53ef\u7528\u72c0\u614b\u3002\u6b64\u6642\u5982\u679c\u756b\u9762\u6c92\u6709\u51fa\u73fe\u932f\u8aa4\u8a0a\u606f\u7684\u8a71\uff0c\u5c31\u53ef\u4ee5\u958b\u59cb\u900f\u904e\u6309\u9215\u4f86\u5c0dArduino\u9032\u884c\u64cd\u4f5c\u3002\u5982\u679c\u662f\u7b2c\u4e00\u6b21\u9023\u7dda\u7684\u8a71\uff0c\u4f60\u7684\u624b\u6a5f\u9084\u6703\u6709\u4e00\u500b\u8981\u6c42\u914d\u5c0d\u7684\u529f\u80fd\uff0c\u4e00\u822c\u4f86\u8aaa\uff0c\u9810\u8a2d\u7684pin\u78bc\u662f1234\u6216\u662f0000\u3002\u6253\u958bLED\u4ee5\u53ca\u95dc\u9589LED\u7684\u6309\u9215\u7a0b\u5f0f\u5167\u5bb9\u5982\u4e0b\uff08\u5176\u5be6\u5c31\u662f\u9001\u4e00\u500b\u5b57\u5143&#8217;a&#8217;\u6216\u662f&#8217;b&#8217;\u800c\u5df2\uff09\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.26.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2247\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.26.png\" alt=\"\" width=\"392\" height=\"237\" \/><\/a><\/p>\n<p>\u6700\u5f8c\u548c\u85cd\u7259\u65b7\u7dda\u7684\u6309\u9215\u7a0b\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2245\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/06\/screenshot-2018-06-09-\u4e0a\u534810.43.00.png\" alt=\"\" width=\"358\" height=\"192\" \/><\/a><\/p>\n<p>\u9664\u4e86\u57f7\u884c\u65b7\u7dda\u529f\u80fd\u4e4b\u5916\uff0c\u9084\u8981\u628a\u6309\u9215\u7684\u53ef\u4f7f\u7528\u72c0\u614b\u518d\u91cd\u65b0\u8abf\u6574\u4e00\u4e0b\uff0c\u65b9\u4fbf\u63a5\u4e0b\u4f86\u7684\u64cd\u4f5c\u3002\u5728\u64cd\u4f5c\u7684\u904e\u7a0b\u7576\u4e2d\u4f60\u9084\u6703\u767c\u73fe\uff0c\u5982\u679c\u85cd\u7259\u6a21\u7d44\u662f\u8655\u7406\u672a\u9023\u7dda\u72c0\u614b\uff0c\u6703\u6709\u4e00\u500b\u5c0f\u71c8\u4e0d\u65b7\u5730\u9583\u720d\uff0c\u5982\u679c\u5efa\u7acb\u9023\u7dda\u4e4b\u5f8c\uff0c\u8a72\u5c0f\u71c8\u865f\u6703\u8b8a\u6210\u662f\u6046\u4eae\u7684\u60c5\u6cc1\u5594\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9019\u4e00\u6b21\u6211\u5011\u8981\u7df4\u7fd2\u7684\u662fArduino\u7684\u85cd\u7259\u6a21\u7d44\uff0c\u900f\u904e\u9019\u500b\u6a21\u7d44\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5728\u4e0d\u540c\u7684Arduino\u4e4b\u9593\u76f8\u4e92\u901a\u8a0a\uff0c\u540c\u6642\u4e5f\u53ef\u4ee5\u4f7f\u7528\u624b\u6a5f\u7684APP\u7a0b\u5f0f\u63a7\u5236Arduino\u4e0a\u7684\u8f38\u51fa\u88dd\u7f6e\u3002\u5982\u679c\u540c\u5b78\u5011\u5b78\u6703\u4e86\u9019\u9805\u6280\u5de7\uff0c\u5c31\u53ef\u4ee5\u505a\u51fa\u8a31\u591a\u5229\u7528\u624b\u6a5f\u63a7\u5236Arduino\u9059\u63a7\u8eca\u3001\u5bb6\u7528\u96fb\u5668\u4ee5\u53ca\u4efb\u4f55\u5176\u5b83\u4f7f\u7528Arduino\u9023\u63a5\u7684\u88dd\u7f6e\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[208],"class_list":["post-2805","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-208"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2805"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2805\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}