Need Help - How to use RX Data from HLK LD1115H for control Relay output

Hi Everyone, I'm newbie here. I buy 1 Arduino Mega 2560 and 1 Presence Sensor Hi Link HLK LD1115H. I want connect this sensor to Arduino and control relay if sensor detect Human Presence.
Sensor have Vo (3V) Output, but i dont want to use it, its value is not what I want. So i decide use RX data received from Sensor.

With my project, i just can received data, i want to data in my IF function like Example:
Data ASCII Code:
mov, 2 1234
occ, 5 562

i will use First 3 characters "mov" or "occ". If "mov" is sensor detect movement and if "occ" is sensor detect human presence. Next i want use 3 or 4 lasted character is Sensitive of "mov" or "occ". Now, if sensitive in my range, relay output will ON.

But, i dont know how to get that, coz my code to try convert code to String, but i can not use String function for do it.

Someone can give me some ideas for my project. Thank you so much.

int i = 0;
void sensor1();
void cambien2();
void cambien3();
void setup() {
  // initialize serial ports
  Serial.begin(9600);  // USB serial port 0
  Serial1.begin(115200);
}
char read_byte [13];
void loop() {
  sensor1();
}

void sensor1() {
  for (i = 1;i<=13;i=i+1) {
    if(Serial1.available()) {
      // get byte from USB serial port
      read_byte [i] = Serial1.read();
      String s = String(read_byte [i]);
      Serial.print(s);
    } else {
      i=0;
    }
  }
}

My Serial Print Sensor Data

My LD1115H sensor

What about the first byte?
What about the fourteenth . . Oops!

Take a look at the serial basics tutorial

1 Like

i will read again serial basics tutorial see how

But, i dont know first byte bro, in datasheet or manual dont mention it.

If i use UartAssist software, i see in HEX code 6F 63 63 is mov, and 6D 6F 76 is occ.

The first byte is the first to be sent
It would normally go into the array at index zero, so the for loop would normally go from zero.
The last element in a thirteen element array has the index twelve, not thirteen, so the for loop condition should be "< 13" at worst.

1 Like

thanks bro, let me try

I made a project on this sensor, maybe you can find something useful) GitHub - stiamon77/AQST-MS: Occupancy\Motion sensor HLK-LD1115H-24G ESP32 or ESP8266, Arduino, connection to Home Assistant, Human Presence Sensor Radar

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.