Skip to content

Commit e94e27f

Browse files
Commented the Arduino code
1 parent 05d99b0 commit e94e27f

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

bluetooth/bluetooth.ino

+34-20
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,89 @@
11
#include<SoftwareSerial.h>
2-
#define PIN A5
2+
3+
//We're using pin 10 and 11 in RX and TX mode
34
SoftwareSerial BT(10,11);
5+
//String that will store the command from mobile device
46
String readdata;
5-
char data = 0; //Variable for storing received data
7+
char data = 0;
68
bool ledOn = false;
7-
int startDelay, stopAfter;
9+
//Variables used for implementing delay mechanism
10+
int startDelay, stopAfter;
11+
//Used for reading data as it is received from the Bluetooth input stream
812
char c;
9-
int bulb_1 = 0, bulb_2 = 0;
13+
//The two vaiables represent the two output pins to which bulbs are connected
14+
int bulb_1 = 0, bulb_2 = 0;
1015

1116
void setup()
1217
{
1318
BT.begin(38400);
14-
Serial.begin(9600); //Sets the baud for serial data transmission
15-
pinMode(3, OUTPUT); //Sets digital pin 13 as output pin
16-
pinMode(2, OUTPUT);
19+
Serial.begin(9600); //Sets the baud for serial data transmission
20+
pinMode(3, OUTPUT); //Sets digital pin 3 as output pin
21+
pinMode(2, OUTPUT); //Sets digital pin 2 as output pin
1722
}
1823

1924
void loop()
2025
{
21-
while(BT.available()) // Send data only when you receive data:
26+
while(BT.available()) //Receive data as long as it is available
2227
{
2328
delay(10);
2429
data = BT.read();
2530
readdata+=data;
2631
}
2732

28-
//Read the incoming data & store into data
33+
//Read the incoming data & store into readdata
2934
if(readdata.length()>0)
3035
{
31-
Serial.print(readdata); //Print Value inside data in Serial monitor
32-
Serial.print("\n");
36+
Serial.print(readdata); //Print value inside data in Serial monitor
37+
Serial.print("\n");
3338

3439
if(readdata == "1") {
40+
//If bulb 1 is selected, set bulb_1 to pin 3
3541
bulb_1 = 3;
42+
//Keep the bulb off initially
3643
digitalWrite(bulb_1, LOW);
44+
//Make readdata string empty
3745
readdata = "";
3846
}
3947

4048
else if(readdata == "2") {
49+
//If bulb 2 is selected, set bulb_2 to pin 2
4150
bulb_2 = 2;
51+
//Keep the bulb off initially
4252
digitalWrite(bulb_2, LOW);
4353
readdata = "";
4454
}
4555

4656
else if(readdata == "01") {
57+
//If bulb 1 has been unchecked, make bulb_1 as 0 to disselect it
4758
bulb_1 = 0;
48-
digitalWrite(bulb_1, LOW);
4959
readdata = "";
5060
}
5161

5262
else if(readdata == "02") {
63+
//If bulb 1 has been unchecked, make bulb_1 as 0 to disselect it
5364
bulb_2 = 0;
54-
digitalWrite(bulb_2, LOW);
5565
readdata = "";
5666
}
5767

5868
if(readdata == "STOP") {
69+
//This signal is sent by pressing disconnect button on the app
70+
//It makes both the bulbs non-funtional
5971
bulb_1 = 0;
6072
bulb_2 = 0;
6173
readdata = "";
62-
digitalWrite(bulb_1, LOW);
63-
digitalWrite(bulb_2, LOW);
6474
}
6575

6676
if(readdata == "ON") {
77+
//This signal is sent by tapping the bulb when it is off
78+
//Used to switch on the selected bulb(s)
6779
digitalWrite(bulb_2, HIGH);
6880
digitalWrite(bulb_1, HIGH);
6981
readdata = "";
7082
ledOn = true;
7183
}
7284
else if(readdata == "OFF") {
85+
//This signal is sent by tapping the bulb when it is on
86+
//Used to switch off the selected bulb(s)
7387
digitalWrite(bulb_2, LOW);
7488
digitalWrite(bulb_1, LOW);
7589
readdata = "";
@@ -79,14 +93,14 @@ void loop()
7993
//Get index of 'e', number following 'e' indicates the number of seconds for which the bulb(s) should remain on
8094
c = readdata.indexOf('e');
8195

96+
//Get the start delay and convert it to int
8297
startDelay = readdata.substring(1, c-1).toInt();
98+
//Get the stop delay and convert it to int
8399
stopAfter = readdata.substring(c+1, readdata.length()-1).toInt();
84100

85-
if(startDelay != 0) {
86-
delay(startDelay*10);
87-
digitalWrite(bulb_1, HIGH);
88-
digitalWrite(bulb_2, HIGH);
89-
}
101+
delay(startDelay*10);
102+
digitalWrite(bulb_1, HIGH);
103+
digitalWrite(bulb_2, HIGH);
90104

91105
if(stopAfter != 0) {
92106
delay(stopAfter*10);

0 commit comments

Comments
 (0)