MJRoBot
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 hours16,684
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

MJRoBot

33 projects • 592 followers
Engineer, writer and forever student. Passionate to share knowledge of electronics with focus on IoT and robotics.

Comments