0% found this document useful (0 votes)
4 views4 pages

Code 44

This document contains an Arduino sketch for controlling devices via Bluetooth using the HC-06 module. It defines relay outputs for a motor, fan, and two lights, allowing them to be turned on or off through specific commands received via Bluetooth or voice commands. The setup initializes the Bluetooth connection and sets the output pins, while the loop continuously checks for incoming commands and executes the corresponding actions.

Uploaded by

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

Code 44

This document contains an Arduino sketch for controlling devices via Bluetooth using the HC-06 module. It defines relay outputs for a motor, fan, and two lights, allowing them to be turned on or off through specific commands received via Bluetooth or voice commands. The setup initializes the Bluetooth connection and sets the output pins, while the loop continuously checks for incoming commands and executes the corresponding actions.

Uploaded by

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

#include <SoftwareSerial.

h>

SoftwareSerial BT(10, 11); // RX, TX for HC-06

// Relay Outputs

#define MOTOR 2

#define FAN 3

#define LIGHT1 4

#define LIGHT2 5

String command = "";

void setup() {

[Link](9600);

[Link](9600);

// Set pins as output

pinMode(MOTOR, OUTPUT);

pinMode(FAN, OUTPUT);

pinMode(LIGHT1, OUTPUT);

pinMode(LIGHT2, OUTPUT);

// Initially OFF

digitalWrite(MOTOR, HIGH);

digitalWrite(FAN, HIGH);

digitalWrite(LIGHT1, HIGH);
digitalWrite(LIGHT2, HIGH);

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

void loop() {

while ([Link]()) {

char c = [Link]();

command += c;

delay(5);

if ([Link]() > 0) {

[Link]("Received: " + command);

// ------------------------ BUTTON CONTROL ------------------------

if (command == "MOTOR_ON") digitalWrite(MOTOR, LOW);

if (command == "MOTOR_OFF") digitalWrite(MOTOR, HIGH);

if (command == "FAN_ON") digitalWrite(FAN, LOW);

if (command == "FAN_OFF") digitalWrite(FAN, HIGH);

if (command == "LIGHT1_ON") digitalWrite(LIGHT1, LOW);

if (command == "LIGHT1_OFF") digitalWrite(LIGHT1, HIGH);


if (command == "LIGHT2_ON") digitalWrite(LIGHT2, LOW);

if (command == "LIGHT2_OFF") digitalWrite(LIGHT2, HIGH);

// ------------------------ VOICE COMMANDS ------------------------

[Link](); // Make matching easier

if ([Link]("motor on") >= 0) digitalWrite(MOTOR, LOW);

if ([Link]("motor off") >= 0) digitalWrite(MOTOR, HIGH);

if ([Link]("fan on") >= 0) digitalWrite(FAN, LOW);

if ([Link]("fan off") >= 0) digitalWrite(FAN, HIGH);

if ([Link]("light one on") >= 0 || [Link]("light 1 on") >= 0)

digitalWrite(LIGHT1, LOW);

if ([Link]("light one off") >= 0 || [Link]("light 1 off") >= 0)

digitalWrite(LIGHT1, HIGH);

if ([Link]("light two on") >= 0 || [Link]("light 2 on") >= 0)

digitalWrite(LIGHT2, LOW);

if ([Link]("light two off") >= 0 || [Link]("light 2 off") >= 0)

digitalWrite(LIGHT2, HIGH);

// Clear command buffer


command = "";

You might also like