Go Down

Topic: Problem with HLRV-MaxSonar-EZ01 (Read 470 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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131