Just purchased a Z-Uno and created a distance sensor to use in the garage in order to get some visual indications when the car is near the wall.
I used the schema on this page (https://z-uno.z-wave.me/examples/hc-sr0 ... ce-sensor/) and adjusted the example slightly since I did not need to have direct association.
However, I feel that the measurement is way off and the reporting is way to slow to use it in the way I´m planning.
I´ve tried multiple power supplies.
Have I done anything wrong?
Code: Select all
// HC-SR04 Ultrasonic Distance Sensor
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(
ZUNO_SENSOR_MULTILEVEL_TYPE_DISTANCE,
0, // scale is meters
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
2, // two decimals after dot
getter
)
);
int readPin = 9;
int triggerPin = 10;
word lastValue;
void setup() {
Serial.begin();
pinMode(readPin, INPUT);
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
}
void loop() {
int tmp;
// trigger measurement
digitalWrite(triggerPin, LOW);
delayMicroseconds(10);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
// read pulse width
tmp = pulseIn(readPin, HIGH, 100000);
if (tmp != 0) {
lastValue = tmp / 58; // convert to cm, see datasheet
Serial.println(lastValue);
// send report to controller (Life Line group)
zunoSendReport(1);
}
delay(250);
}
word getter() {
return lastValue;
}