0% found this document useful (0 votes)
55 views2 pages

Bluetooth Relay Control Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views2 pages

Bluetooth Relay Control Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

#include <SoftwareSerial.

h>

// Define Bluetooth RX and TX pins


SoftwareSerial Bluetooth(0, 1); // RX = 10, TX = 11

// Relay pin definitions


const int relayPins[8] = { 2, 3, 4, 5, 6, 7, 8, 9 };

// Characters to turn relays ON ('a', 'c', ..., 'o')


// and OFF ('b', 'd', ..., 'p')
const char turnOnCommands[8] = { 'a', 'c', 'e', 'g', 'i', 'k', 'm', 'o' }; //a=97
const char turnOffCommands[8] = { 'b', 'd', 'f', 'h', 'j', 'l', 'n', 'p' };

void setup() {
// Initialize Serial Monitor
[Link](9600);
// Initialize Bluetooth Serial communication
[Link](9600);

// Set all relay pins as outputs and turn them OFF


for (int i = 0; i < 8; i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], HIGH);
}

[Link]("Bluetooth Relay Control Ready");


[Link]("Bluetooth Relay Control Ready");
}

void loop() {
if ([Link]()) {
char command = [Link]();
//[Link](command);

for (int i = 0; i < 8; i++) {


if (command == turnOnCommands[i]) {
digitalWrite(relayPins[i], HIGH);
[Link]("Relay ");
[Link](i + 1);
[Link](" turned ON");
[Link]("Relay ");
[Link](i + 1);
[Link](" turned ON");
} else if (command == turnOffCommands[i]) {
digitalWrite(relayPins[i], LOW);
[Link]("Relay ");
[Link](i + 1);
[Link](" turned OFF");
[Link]("Relay ");
[Link](i + 1);
[Link](" turned OFF");
}
}
}
}

You might also like