add radar motion sensor

This commit is contained in:
interfisch 2021-07-14 21:09:23 +02:00
parent 5bc41fcf21
commit f786cbd77c
2 changed files with 61 additions and 0 deletions

View File

@ -227,6 +227,11 @@ build_flags =
-D dataPIR_readdelay=100 -D dataPIR_readdelay=100
-D dataPIR_senddelaymax=1000*60*10 -D dataPIR_senddelaymax=1000*60*10
-D SENSOR_RADAR
-D RADARPIN=D5
-D dataRADAR_readdelay=100
-D dataRADAR_senddelaymax=1000*60*10
-D SENSOR_BH1750 -D SENSOR_BH1750
-D dataBH1750_minchange=10.0 -D dataBH1750_minchange=10.0
-D dataBH1750_senddelaymax=1000*60*2 -D dataBH1750_senddelaymax=1000*60*2

View File

@ -94,6 +94,13 @@ struct sensordata
bool value_PIR=false; bool value_PIR=false;
#endif #endif
#ifdef SENSOR_RADAR
// High/Low Output Radar Sensor
// For example: RCWL-0516 (needs 5v input (gnd, vin), 3.3v output level. high for 2seconds when movement detected)
sensordata dataRADAR;
bool value_RADAR=false;
#endif
#ifdef SENSOR_LDR #ifdef SENSOR_LDR
struct sensordata dataLDR; struct sensordata dataLDR;
@ -334,6 +341,17 @@ void setup() {
#endif #endif
#endif #endif
#ifdef SENSOR_RADAR
Serial.println("initializing radar");
pinMode(RADARPIN, INPUT);
#ifdef dataRADAR_readdelay
dataRADAR.readdelay=dataRADAR_readdelay;
#endif
#ifdef dataRADAR_senddelaymax
dataRADAR.senddelaymax=dataRADAR_senddelaymax;
#endif
#endif
#ifdef SENSOR_LDR #ifdef SENSOR_LDR
Serial.println("initializing ldr"); Serial.println("initializing ldr");
pinMode(LDR_PIN, INPUT); //ldr pinMode(LDR_PIN, INPUT); //ldr
@ -480,6 +498,10 @@ void setup() {
sensorNode.advertise("motion"); sensorNode.advertise("motion");
#endif #endif
#ifdef SENSOR_RADAR
sensorNode.advertise("radar");
#endif
#ifdef SENSOR_BMP180 #ifdef SENSOR_BMP180
sensorNode.advertise("temperature"); sensorNode.advertise("temperature");
sensorNode.advertise("pressure"); sensorNode.advertise("pressure");
@ -799,6 +821,36 @@ void loop_PIR()
} }
#endif #endif
#ifdef SENSOR_RADAR
void loop_RADAR()
{
sensordata &d=dataRADAR;
bool _changed=false;
if (millis() >= (d.lastreadtime+d.readdelay)) {
if (digitalRead(RADARPIN) != value_RADAR){
_changed=true;
}
d.lastreadtime=millis();
}
if (_changed || millis() >= (d.lastsent+d.senddelaymax)) { //send current value after some long time
Serial.print("Sending motion radar. reason=");
if (_changed) Serial.println("change"); else Serial.println("time");
if (digitalRead(RADARPIN)){
Homie.getLogger() << "radar " << ": " << "true" << endl;
sensorNode.setProperty("radar").send(String("true"));
value_RADAR=true;
}else{
Homie.getLogger() << "motion " << ": " << "false" << endl;
sensorNode.setProperty("radar").send(String("false"));
value_RADAR=false;
}
d.lastsent=millis();
}
}
#endif
#ifdef SENSOR_MHZ19 #ifdef SENSOR_MHZ19
void loop_MHZ19() void loop_MHZ19()
{ {
@ -1126,6 +1178,10 @@ void loopHandler() {
loop_PIR(); loop_PIR();
#endif #endif
#ifdef SENSOR_RADAR
loop_RADAR();
#endif
#ifdef SENSOR_MHZ19 #ifdef SENSOR_MHZ19
loop_MHZ19(); loop_MHZ19();
#endif #endif