MJRoBot (Marcelo Rovai)
Published © GPL3+

Connecting "stuff" via Bluetooth / Android / Arduino

A very good wireless local area (and personal) network is undoubtedly the Bluetooth (BT). Let's play with it!

BeginnerFull instructions provided4 hours25,686
Connecting "stuff" via Bluetooth / Android / Arduino

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
#include <SoftwareSerial.h>
SoftwareSerial BT (10, 11); // RX, TX

String command = ""; // Stores response of bluetooth device

void setup ()
{
  Serial.begin (9600);
  Serial.println ("Type AT commands");
  BT.begin (9600); // HC-06 Usually default baud-rate
}

Code snippet #2

Plain text
void loop ()
{
  if (BT.available ()) // receive data if available.
  {
    while (BT.available ()) // "keep receiving".
    {
      delay (10); // Delay added to make thing stable
      char c = BT.read (); // Conduct serial read
      command + = c; // Build the string.
    }
    Serial.println (command);
    command = ""; // No repeats
  }
  if (Serial.available ())
  {
    delay (10);
    BT.write (Serial.read ());
  }
}

Code snippet #3

Plain text
dev1on
dev1off
dev2on
dev2off
dev3on
dev3off
dev4on
dev4off

Credits

MJRoBot (Marcelo Rovai)

MJRoBot (Marcelo Rovai)

60 projects • 912 followers
Professor, Engineer, MBA, Master in Data Science. Writes about Electronics with a focus on Physical Computing, IoT, ML, TinyML and Robotics.

Comments