DZone
IoT Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > IoT Zone > Bluetooth Communication With Arduino

Bluetooth Communication With Arduino

Learn how to communicate to an Arduino using Bluetooth in this short tutorial.

Sony Arouje user avatar by
Sony Arouje
·
Mar. 13, 16 · IoT Zone · Tutorial
Like (6)
Save
Tweet
9.39K Views

Join the DZone community and get the full member experience.

Join For Free

i am in the process of redesigning my raspberry pi based aeroponic controller . in my new system, i am using arduino. this time, i decided to use bluetooth instead of wifi to communicate between my mobile app and arduino controller. later i will write another post explaining about this new design. in this post i will explain how to communicate to arduino via bluetooth.

arduino bluetooth connection

i bought a bluetooth module from ebay, it’s a very low-cost module. the connection is pretty simple. see the connection below. i am using arduino nano in my new design.

connection_v2_bb

connection details

  • nano vcc to bt vcc
  • nano gnd to bt gnd
  • nano rxd to bt txd
  • nano txd to bt rxd

in my sketch i used softserial and i assign d2 and d3 as rxd and txd respectively.

i haven’t used the en and key pin in the bluetooth module. you might want to use en pin if you want to enter into at mode to issue any commands to bt module.

arduino sketch

#include <softwareserial.h>
softwareserial soft(2,3);// rx, txvoid setup() {
  soft.begin(9600);
  serial.begin(9600);
}

void loop() {
  if(soft.available()){
      string serialdata = soft.readstring();
      serial.println(serialdata); //echo bluetooth data to serial      writeack();
  }
}

void writeack(){
  uint8_t payload[]="ack|0|\n";
  soft.write(payload,sizeof(payload));
}

it’s a very simple sketch to receive the data from bluetooth module and echo to serial, also send and acknowledgment back to the caller.

you can test the program by issuing some text from hyperterminal or any other similar app. i wrote an android app to issue a command via mobile bluetooth.

happy coding…

arduino

Published at DZone with permission of Sony Arouje, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A First Look at CSS When and Else Statements
  • Kafka Fail-Over Using Quarkus Reactive Messaging
  • 6 Best Books to Learn Multithreading and Concurrency in Java
  • How To Deploy Apache Kafka With Kubernetes

Comments

IoT Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo