-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex04.ino
40 lines (33 loc) · 1.06 KB
/
ex04.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
// Arduino Engineering Lab
// Exercise n. 04
#include <SoftwareSerial.h>
// Define RX and TX pins for the Software Serial port
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
// Initialise hardware serial port (for monitoring)
Serial.begin(9600);
// Initialise Bluetooth serial port
BTSerial.begin(9600);
Serial.println("Bluetooth Module is ready!");
}
void loop()
{
// Check if data is available on Bluetooth
if (BTSerial.available())
{
char incomingData = BTSerial.read(); // Read the data
Serial.print("Received via Bluetooth: ");
Serial.println(incomingData); // Print on Serial Monitor
// Echo the received data back to the Bluetooth device
BTSerial.write(incomingData);
}
// Check if data is available on Serial Monitor
if (Serial.available())
{
char outgoingData = Serial.read(); // Read the data
BTSerial.write(outgoingData); // Send it to the Bluetooth device
Serial.print("Sent via Bluetooth: ");
Serial.println(outgoingData);
}
}