forked from ECE-196/ece-196-fa24-final-project-Final-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bluthooth.ino
34 lines (27 loc) · 1003 Bytes
/
Bluthooth.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
#include <BluetoothSerial.h>
// Create a Bluetooth Serial object
BluetoothSerial SerialBT;
// Pin for actuator (e.g., motor control)
const int actuatorPin = 2;
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize Bluetooth
SerialBT.begin("ESP32-Squirrel-Detector"); // Bluetooth name
Serial.println("Bluetooth device is ready to pair");
// Set up actuator pin
pinMode(actuatorPin, OUTPUT);
digitalWrite(actuatorPin, LOW); // Ensure actuator is off
}
void loop() {
if (SerialBT.available()) {
String message = SerialBT.readStringUntil('\n'); // Read message from Mac
Serial.println("Message received: " + message);
if (message == "ACTUATE") {
Serial.println("Triggering actuator!");
digitalWrite(actuatorPin, HIGH); // Activate actuator
delay(1000); // Keep actuator on for 1 second
digitalWrite(actuatorPin, LOW); // Deactivate actuator
}
}
}