Go Down

Topic: Problem with HLRV-MaxSonar-EZ01 (Read 786 times) previous topic - next topic


Hello !! I'm a french student.
But I have a problem to use a sensor with my arduino mega.  :smiley-roll:
So with the HRLV-MaxSonar-EZ01, an ultrasonic sensor, I want to get a distance by a TTL signal. But I obtain random values.

My program :
byte distance;
const int impulsion = 10;

void setup ()
  Serial2.begin(9600); // 
  Serial.begin (9600);
  pinMode (distance, INPUT);
  pinMode (impulsion, OUTPUT);

void loop ()
  digitalWrite (impulsion, HIGH);//launch an impluse to start the echo
  delayMicroseconds (21);
  digitalWrite (impulsion, LOW);//stot the impulsion to stop the echo
  distance = Serial2.read ();//get the distance
  Serial.println (distance);//print the distance on the serial monitor

And I get values like 83, 53, 5 ... in firt I get 255  :smiley-eek:

Informations about the ultrasonic sensor :

Go Up