{"id":1576,"date":"2019-06-01T01:06:06","date_gmt":"2019-05-31T17:06:06","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=1576"},"modified":"2020-05-12T10:50:04","modified_gmt":"2020-05-12T02:50:04","slug":"how-to-get-your-esp32-development-board-to-communicate-with-another-device-over-bluetooth-serial","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-get-your-esp32-development-board-to-communicate-with-another-device-over-bluetooth-serial\/","title":{"rendered":"How to get your ESP32 development board to communicate with another device over Bluetooth Serial"},"content":{"rendered":"<p>Since a <a href=\"https:\/\/www.amazon.com\/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated\/dp\/B0718T232Z\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=01756258214c545a259870fca7991fbb&language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a> comes with Bluetooth, we can get it to communicate with another device over Bluetooth Serial. <\/p>\n<p>With this in mind, let's look at how we can get your ESP32 development board to communicate with another device over Bluetooth Serial.<\/p>\n<h2>Enabling ESP32 Development on Arduino IDE<\/h2>\n<p>At this point in time, you are ready to flash a program into your ESP32 board to test out communication via Bluetooth Serial. In order to do so, we need to use a tool to write our program into the flash memory of the development board.<\/p>\n<p>Since it is easy to write code and flash programs with <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\" rel=\"noopener\" target=\"_blank\">Arduino IDE<\/a>, we can use it to serve our purpose.<\/p>\n<p>In order to use Arduino IDE for this guide, be sure to <a href=\"https:\/\/www.techcoil.com\/blog\/enabling-esp32-development-on-arduino-ide\/\" rel=\"noopener\" target=\"_blank\">enable ESP32 development on Arduino IDE<\/a> before continuing.<\/p>\n<h2>Sample Arduino Sketch to get your ESP32 development board to communicate with another device over Bluetooth Serial<\/h2>\n<p>After you had enabled ESP32 development on Arduino IDE, you can then proceed with uploading a sample Arduino Sketch that demonstrate Bluetooth Serial communication:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &quot;BluetoothSerial.h&quot;\r\n\r\nBluetoothSerial SerialBT;\r\n \r\nvoid setup()\r\n{\r\n  SerialBT.begin(&quot;ESP32test&quot;);\r\n  delay(1000);\r\n}\r\n \r\nvoid loop()\r\n{\r\n  String inputFromOtherSide;\r\n  if (SerialBT.available()) {\r\n    inputFromOtherSide = SerialBT.readString();\r\n    SerialBT.println(&quot;You had entered: &quot;);\r\n    SerialBT.println(inputFromOtherSide);\r\n  }\r\n}\r\n<\/pre>\n<p>So what does this Arduino sketch do? <\/p>\n<p>Firstly, inside the <code>setup<\/code> function, we create a BluetoothSerial object with <strong>ESP32test<\/strong> as the device name. After that we send <strong>ESP32 BluetoothSerial echo test<\/strong> to the device that connects to it via Bluetooth.<\/p>\n<p>Next, inside the <code>loop<\/code> function, we try to read a <a href=\"https:\/\/www.arduino.cc\/reference\/en\/language\/variables\/data-types\/stringobject\/\" rel=\"noopener\" target=\"_blank\">String<\/a> for the other device. Whenever the other device sends something, we simply echo the input back to the sender.<\/p>\n<h2>Testing the ESP32 Bluetooth connection with Arduino IDE<\/h2>\n<p>Once you had uploaded the Arduino sketch onto the ESP32 development board, you can then proceed to test it with Arduino IDE. <\/p>\n<p>First, pair your computer with ESP32 via Bluetooth. For example, this is <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-connect-to-an-esp32-development-board-via-bluetooth-on-your-mac\/\" rel=\"noopener\" target=\"_blank\">how to connect an ESP32 development board via Bluetooth on your Mac<\/a>. In case you are using Windows 10, this is <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-connect-to-an-esp32-development-board-via-bluetooth-on-windows-10\/\" rel=\"noopener\" target=\"_blank\">how to connect to an ESP32 development board via Bluetooth on Windows 10<\/a>.<\/p>\n<p>Once you had paired your computer with ESP32, the Bluetooth connection will appear as a port inside your Arduino IDE.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-1.8.9-showing-bluetooth-connection-as-port.gif\" alt=\"Mac Arduino 1.8.9 showing bluetooth connection as port\" \/><\/p>\n<p>After you had selected the Bluetooth connection as the port to use, start <strong>Serial Monitor<\/strong>.<\/p>\n<p>When Serial Monitor appears, you should see the name of the Bluetooth connection as the title.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-1.8.9-serial-monitor-showing-utilization-of-ESP32test-bluetooth-connection-as-the-port..gif\" alt=\"Mac Arduino 1.8.9 serial monitor showing utilization of ESP32test bluetooth connection as the port\" \/><\/p>\n<p>Given that, you can use the Serial Monitor to send data to your ESP32 development board via the Bluetooth connection. <\/p>\n<p>When you do so, you should see what you had entered being echoed back inside the text area.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-1.8.9-serial-monitor-showing-utilization-of-ESP32test-bluetooth-connection-as-the-port-and-some-sample-input.gif\" alt=\"Mac Arduino 1.8.9 serial monitor showing utilization of ESP32test bluetooth connection as the port and some sample input\" \/><\/p>\n<p>At this point in time, you have validated that Bluetooth connection of your ESP32 development board is working. <\/p>\n<p>Given these points, you can then extend the code to instruct ESP32 to send sensor information to the other device via Bluetooth Serial. For example, you may wish to <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-use-a-esp32-development-board-to-read-temperature-and-humidity-from-a-dh11-sensor\/\" rel=\"noopener\" target=\"_blank\">get your ESP32 to read temperature and humidity from a DHT11 sensor<\/a> and send the readings to the other device through Bluetooth Serial.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-pq\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-pq&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-pq&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1576&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>Since a <a href=\"https:\/\/www.amazon.com\/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated\/dp\/B0718T232Z\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=01756258214c545a259870fca7991fbb&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a> comes with Bluetooth, we can get it to communicate with another device over Bluetooth Serial. <\/p>\n<p>With this in mind, let&#8217;s look at how we can get your ESP32 development board to communicate with another device over Bluetooth Serial.<\/p>\n","protected":false},"author":1,"featured_media":1584,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[588,648,651,647,630],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Mac-Arduino-1.8.9-serial-monitor-showing-utilization-of-ESP32test-bluetooth-connection-as-the-port-and-some-sample-input.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-pq","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1576"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=1576"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1576\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1584"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=1576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=1576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=1576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}