Hi, my first time in this forum.
I'm using the ultrasonic-sensor HC-SR04 and measure a distance and the time. In the serial monitor the data looks like that:
817
152
827
158
836
158
and so on. The first data is the time in µs, the second data the distance in cm. So it works. But i will separate the distance-data from the time-data in the serial monitor with loops. But it doesn't work well. First i get all the time-data, but all distance-data are zeros. Look at my sorcecode, maybe you find something.
// Arduino Uno, IDE 1.6.7
// 23.12.2015
# define echoPin 2
# define trigPin 1
int n;
int n_max = 100;
int array_distance[100];
int array_time[100];
void setup() {
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (n = 0; n < n_max; n++) {
Triggerimpuls();
Distanz_Berechnung();
Zeitmessung();
Ausgabe_Zeit();
Ausgabe_Distanz();
//delay(1000); //Ausgabe_Distanz delivers only zeros. Why?
}
//Ausgabe_Zeit();
//Ausgabe_Distanz(); // doesn't work with the loop, only zeros. Why?
Programmende(); // durch Endlosschleife
}
void Triggerimpuls() {
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
}
void Distanz_Berechnung() {
array_distance[n] = pulseIn(echoPin, HIGH, 25000) * 0.01715;
}
void Zeitmessung() {
array_time[n] = millis();
}
void Ausgabe_Zeit() {
// for (n = 0; n < n_max; n++) {
Serial.println(array_time[n]);
// }
}
void Ausgabe_Distanz () {
//for (n = 0; n < n_max; n++) {
Serial.println(array_distance[n]);
//}
// Ausgabe_Distanz delivers only zeros. Why?
}
void Programmende () {
while (1);
}
Thank you !!