Im having some trouble setting up HC-SR04 sensor to measure pellet bunker level. The sensor is on top of the bunker and needs to be working in reverse. If the bunker level gets lower, the value should go down. Is it possible? I have no idea what lines to add to sample code https://z-uno.z-wave.me/examples/hc-sr0 ... ce-sensor/ and how to write value in %, not cm. Any help?
Later i will add 6 DS18B20 temp sensors. But again i have no idea about the code for both of those things to work.
Im using Vera Edge controller at the moment.
The whole idea is to put z-uno with some central in one box, so i could measure 6 different temperatures on my heater and monitor pellet bunker level over the internet.
void loop(){
int duration,distance,percentage,heightTank,deviation;
//You'll probably want to change the next 2 lines.
// The first one is the max. level of the water.
// The next one is how high the sensor is above that max. level.
heightTank=151;
deviation=29;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
percentage=100-(((distance-deviation)*100)/heightTank);
Serial.println(distance);
Serial.println(percentage);
delay(1000);
Okay so i modified the code to this but i get an error when compiling: Error compiling for board Z-Wave>ME Z-Uno. Aaand i have no idea what im missing here.
// HC-SR04 Ultrasonic Distance Sensor
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL_GENERAL_PURPOSE(getter)
);
int readPin = 9;
int triggerPin = 10;
byte controlState = 0;
word percentage;
void setup() {
Serial.begin();
pinMode(readPin, INPUT);
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
}
void loop(){
int duration, distance, percentage, heightTank, deviation;
//You'll probably want to change the next 2 lines.
// The first one is the max. level of the water.
// The next one is how high the sensor is above that max. level.
heightTank=151;
deviation=29;
digitalWrite(triggerPin, LOW);
delayMicroseconds(10);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(readPin,HIGH, 100000);
distance = (duration/2)/29.1;
percentage = 100-(((distance-deviation)*100)/heightTank);
Serial.println(percentage);
delay(1000);
}
word getter() {
return percentage;
}
And change the getter to return one byte only in percentage (instead of word).
Didn't quite understand what im supposed to change?
// HC-SR04 Ultrasonic Distance Sensor
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL_GENERAL_PURPOSE(getter)
);
int readPin = 9;
int triggerPin = 10;
byte controlState = 0;
byte percentage;
void setup() {
Serial.begin();
pinMode(readPin, INPUT);
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
}
void loop(){
byte distance, heightTank, deviation;
int duration;
//You'll probably want to change the next 2 lines.
// The first one is the max. level of the water.
// The next one is how high the sensor is above that max. level.
heightTank=151;
deviation=29;
digitalWrite(triggerPin, LOW);
delayMicroseconds(10);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
duration = pulseIn(readPin, HIGH, 100000);
distance = (duration*10/2)/291;
percentage = (byte)(100-(((distance-deviation)*100)/heightTank));
Serial.println(percentage);
delay(1000);
}
byte getter() {
return percentage;
}
Yep it compiled now. There was some error with my file so i created a new one and all good but with both codes, Vera doesn't show any result - level. It shows the device but no value. I tried moving object from 10cm to 100cm but still nothing.
Still no results, i tried to modify the code back and forth but no use, cant get any readings from Vera. Maybe its the Vera controller? Even though it worked with example code.