Using HC-SR04 for measuring distance to car

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
dhanjel
Posts: 12
Joined: 27 Jan 2015 18:50

Using HC-SR04 for measuring distance to car

Post by dhanjel »

Hi

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;
}
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Using HC-SR04 for measuring distance to car

Post by PoltoS »

Please note that Sensor Multilevel values are reported every 30 seconds only. This is a Z-Wave requirement. But you can tune this.

Please read here: http://z-uno.z-wave.me/Reference/zunoSendReport/
According to Z-Wave Plus restrictions, values from Sensor Multilevel channels (defined via ZUNO_SENSOR_MULTILEVEL macro) will not be sent unsolicitedly to Life Line more often than every 30 seconds. At the same time Z-Uno will answer instantly on Sensor Multilevel Get command (solicited report). You can also change this time using configuration parameter #11. This restriction is not applicable to other channel types.
Post Reply