To do so, someone suggested using a Z-Uno with an ultrasonic sensor, since there is no commercially available distance sensor yet. I want to combine two sensors though, so that I only need to purchase one Z-Uno board (this hobby could get expensive lol...) so I was wondering if this would work. I was pointed to http://z-uno.z-wave.me/examples/hc-sr04 ... ce-sensor/ as an example. So what I would do is mirror the setup with a second ultrasonic sensor, wired to pins 7 and 8.
Here is the code I modified from that link, would this work? I removed all the comments from the original code so the comments here are notes and questions that I have.
Code: Select all
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(
ZUNO_SENSOR_MULTILEVEL_TYPE_GENERAL_PURPOSE_VALUE,
0, // not sure what i'd use for this value, i think 0 should work
SENSOR_MULTILEVEL_SIZE_TWO_BYTES, // don't think i need this much, one byte should work, right?
0, // don't need any decimal precision
getter
)
);
int compare_distance = 3000; // this is the variable I'll change to compare distance to
int overlap_distance = 100; // this value is used as an overlap zone between car detected and not detected, used to prevent the edge case
int readPinMe = 9;
int triggerPinMe = 10;
byte homeStateMe = 0;
int readPinWife = 7;
int triggerPinWife = 8;
byte homeStateWife = 0;
void setup() {
Serial.begin();
pinMode(readPinMe, INPUT);
pinMode(triggerPinMe, OUTPUT);
digitalWrite(triggerPinMe, LOW);
pinMode(readPinWife, INPUT);
pinMode(triggerPinWife, OUTPUT);
digitalWrite(triggerPinWife, LOW);
}
void loop() {
int tmp;
// Me
digitalWrite(triggerPinMe, LOW);
delayMicroseconds(10);
digitalWrite(triggerPinMe, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPinMe, LOW);
tmp = pulseIn(readPin, HIGH, 100000);
if (tmp != 0) {
if (tmp < (compare_distance - overlap_distance) && homeStateMe == 0) {
homeStateMe = 1;
} else if (tmp > (compare_distance + overlap_distance) && homeStateMe == 1) {
homeStateMe = 0;
}
}
// Wife
digitalWrite(triggerPinWife, LOW);
delayMicroseconds(10);
digitalWrite(triggerPinWife, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPinWife, LOW);
tmp = pulseIn(readPin, HIGH, 100000);
if (tmp != 0) {
if (tmp < (compare_distance - overlap_distance) && homeStateWife == 0) {
homeStateWife = 2;
} else if (tmp > (compare_distance + overlap_distance) && homeStateWife == 2) {
homeStateWife = 0;
}
}
zunoSendReport(1);
delay(1000);
}
word getter() {
return homeStateMe + homeStateWife;
// this makes 4 states:
// 0 = nobody home
// 1 = me home
// 2 = wife home
// 3 = both home
}
Thanks,
-Vinay