Seeed Studio XIAO ESP32C3 and 24GHz mmWave Sensor - Human Static Presence Module Lite (MR24HPC1) in ARDUINO #1963
ShaneChrome
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would like some help or input i am doing this project where i integrate this controller and device and mqtt in Arduino but I cannot find the Library for (MR24HPC1) in ARDUINO I amgetting error that says the library doesn't exist.
Code below
// Include necessary libraries
#include <WiFi.h>
#include <PubSubClient.h>
#include <Ticker.h>
#include <MR24HPC1.h>
// Define sensor and light control pins
#define SENSOR_TX D7
#define SENSOR_RX D6
#define LIGHT_PIN D8
// Define MQTT server and topic information
#define MQTT_SERVER "49c47a0b5ec343ed9e197f021fd35c83.s1.eu.hivemq.clouds"
#define MQTT_TOPIC "Serverless"
// Sensor and MQTT client instances
MR24HPC1 sensor;
WiFiClient espClient;
PubSubClient mqttClient(espClient);
// Ticker for periodic tasks
Ticker presenceCheckTicker;
// Presence detection flag
bool presenceDetected = false;
void setup() {
// Initialize Serial communication
Serial.begin(115200);
// Initialize sensor
sensor.begin(SENSOR_TX, SENSOR_RX);
// Configure sensor parameters
sensor.setDetectionRange(3.0, 5.0);
sensor.setDetectionAngle(60);
// Connect to WiFi
connectToWiFi();
// Set up MQTT client
mqttClient.setServer(MQTT_SERVER, 8883);
// Start presence detection check
presenceCheckTicker.attach(60, checkPresence);
// Set up light control pin
pinMode(LIGHT_PIN, OUTPUT);
}
void loop() {
// Maintain MQTT connection
if (!mqttClient.connected()) {
reconnectMQTT();
}
mqttClient.loop();
// Check for OTA updates
handleOTAUpdates();
}
void checkPresence() {
// Check sensor for presence detection
if (sensor.isPersonDetected()) {
if (!presenceDetected) {
presenceDetected = true;
publishPresenceEvent(true);
turnOnLight();
}
} else {
if (presenceDetected) {
presenceDetected = false;
publishPresenceEvent(false);
turnOffLight();
}
}
}
void publishPresenceEvent(bool present) {
// Publish presence detection event to MQTT broker
String payload = "{"presence":" + String(present) + "}";
mqttClient.publish(MQTT_TOPIC, payload.c_str());
}
void turnOnLight() {
// Turn on the light
digitalWrite(LIGHT_PIN, HIGH);
}
void turnOffLight() {
// Turn off the light after 5 minutes of no presence
delay(300000);
digitalWrite(LIGHT_PIN, LOW);
}
void connectToWiFi() {
// Connect to WiFi network
WiFi.begin("UPC1447010", "vr8drMczvdh5");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void reconnectMQTT() {
// Reconnect to MQTT broker
while (!mqttClient.connected()) {
if (mqttClient.connect("49c47a0b5ec343ed9e197f021fd35c83.s1.eu.hivemq.cloud")) {
Serial.println("Connected to MQTT broker");
} else {
Serial.print("Failed to connect to MQTT broker, rc=");
Serial.print(mqttClient.state());
Serial.println(" - Trying again in 5 seconds");
delay(5000);
}
}
}
void handleOTAUpdates() {
// Check for and handle OTA firmware updates
ArduinoOTA.handle();
}
Beta Was this translation helpful? Give feedback.
All reactions