Go Down

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

Augustindu50

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
  delay(500);
 

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

Informations about the ultrasonic sensor :
http://www.maxbotix.com/documents/HRLV-MaxSonar-EZ_Datasheet.pdf

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!

Arduino
via Egeo 16
Torino, 10131
Italy