Skip to content

Instantly share code, notes, and snippets.

@drews256
Created July 22, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drews256/20da35edced1ec2ed06a1cd7d2749229 to your computer and use it in GitHub Desktop.
Save drews256/20da35edced1ec2ed06a1cd7d2749229 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11);
// creates a "virtual" serial port/UART
// connect BT module TX to D10
// connect BT module RX to D11
// connect BT Vcc to 5V, GND to GND
void setup()
{
// set digital pin to control as an output
pinMode(13, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println("Hello from Arduino");
}
char a; // stores incoming character from other device
void loop()
{
if (BT.available())
// if text arrived in from BT serial...
{
a=(BT.read());
if (a=='1')
{
digitalWrite(13, HIGH);
BT.println("LED on");
}
if (a=='2')
{
digitalWrite(13, LOW);
BT.println("LED off");
}
if (a=='?')
{
BT.println("Send '1' to turn LED on");
BT.println("Send '2' to turn LED on");
}
// you can add more "if" statements with other characters to add more commands
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment