-
Notifications
You must be signed in to change notification settings - Fork 1
/
pc_bluetooth_connect.ino
43 lines (42 loc) · 1.07 KB
/
pc_bluetooth_connect.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//code write by Moz for YouTube changel LogMaker360, 27-10-2015
//code belongs to this video: https://www.youtube.com/watch?v=6jZMJ7DFCY0
#include <SoftwareSerial.h>
SoftwareSerial BT(1, 0);
// creates a "virtual" serial port/UART
// connect BT module TX to 0
// connect BT module RX to 1
// 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
}
}