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;
}
}
}