New Tutorial online: HC-SR04 & 8×7 Segment Display

2014-07-22 19.17.37


HC-SR04 & 8×7 Segment Display


The HC-SR04 problem is solved!

Ok, a look at the HC-SR04 datasheet explains and solves the problem.

The speed of ultra sonic is 343 m/s. To measure a distance from 1m, it’s need round about 6 milliSeconds (actually there are two meter, one meter to the destination and one meter back).

So we need a special time for one measurement cycle and we are not able to make as many measurements per second as we want.
The HC-SR04 datasheet shows us the measurement cycle and the cycle time.

The cycle time must be less than 16 Hz. This is not possible with Timer0 and Timer2. Both timer are 8 Bit, and with a prescaler of 1024 we get as slowest frequence 61 Hz (16.000.000 / 1024*256). Therefore we need to use Timer1 if we want to measure permanently.

Here an example for a measurement function:

void Eyes_measurement() {
  digitalWrite(Eyes_Trigger,LOW);        // to be sure the Trigger is down
  digitalWrite(Eyes_Trigger,HIGH);       // start a measurement
  pulsdauer = pulseIn(Eyes_Echo,HIGH);   // get the result
  distance = pulsdauer / 58;             // value in cm

A bad day yesterday!
I tried to optimize the “The little One” code, but it was not successfully. I got a timing problem. To use the interrupt timer2 for the ultra sonic, the frequence is to high, also with a prescaler of 1024. But timer 1 is current in use …