Me-UltraSonic Sensor for distance


#1

Hello,

On my mbot robot the distance sensor works but not well !!!

I does not give the good distance !!!
For example at 60 cm from the door it gives 48 cm
It’s the same for all distances … it gives less.

I thought it was out of order.
Si I replaced it by the one in the box of the starter robot kit.
It’s the same !!!

Who can explain.
Is it an error in the library ?
Is it a problem of voltage ?

Thanks


#2

Calibration of the units could be off, but it is a good exercise in lerning how they work, and how software can be used to resolve mechanical variances.

There is a great wiki on the sensor here:
Echo Location

It could be in the firmware, you could add a conversion factor of 1.25 (outputx1.25=actual)


#3

Hello,

Many thanks for your anwer and the wiki link that gives much information.
I had thought of multiplying the result by 1.25 in my program

The question is : Why nobody made this remark before ???

Did you know ?


#4

Look at This

They use 200 for inches and cm.
That seems false.
But how to change the library for mblock ?

#include “MeUltrasonic.h”
/* UltrasonicSenser */
MeUltrasonic::MeUltrasonic(): MePort(0)
{
}
MeUltrasonic::MeUltrasonic(uint8_t port): MePort(port)
{
}

double MeUltrasonic::distanceCm(uint16_t maxCm)
{
long distance = measure(maxCm * 55 + 200);
return (double)distance / 58.0;
}

double MeUltrasonic::distanceInch(uint16_t maxInch)
{
long distance = measure(maxInch * 145 + 200);
return (double)(distance / 148.0);
}

double MeUltrasonic::distanceCm(){
return distanceCm(400);
}
double MeUltrasonic::distanceInch(){
return distanceInch(5);
}
long MeUltrasonic::measure(unsigned long timeout)
{
long duration;
MePort::dWrite2(LOW);
delayMicroseconds(2);
MePort::dWrite2(HIGH);
delayMicroseconds(10);
MePort::dWrite2(LOW);
pinMode(s2, INPUT);
duration = pulseIn(s2, HIGH, timeout);
return duration;
}


#5

I didn’t see your example there, not sure if you are still working on this.

Did you modify the firmware file and get a good result?

The 200 figure is added, so it would produce a flat difference across all readings, in your case, reading is 12cm low whether @ 10cm or 100cm.

If difference is linear increase by distance measured, then the 55 number would be suspect.

Testing the inch readouts may shed light also, interesting, please post results if you find any.


#6

Hello

The MakeBlock Ultrasonic Sensor looks like the HC-SR04

If it’s the same it works like this :

http://www.micropik.com/PDF/HCSR04.pdf

I’ve done nothing for the moment.
The distance I get is proportional to the real one.

Thanks for helping me.

MJL


#7

And I found that in the forum of this link

The guy who is programming with aduino explains (in french) that it’s a hardware problem.
He has to divide by 77 and not 58 !!!

LDVC@
26/11/2015 à 18:35 Répondre
Bonjour, j’ai essayé plusieurs capteurs HC-SR04 avec l’ARDUINO Uno sous Arduino 1.1.0.5 (Ubuntu 14.04.3), l’air intérieur autour de 19°C, j’ai besoin de diviser par 77 plutôt que 58 pour que cela fonctionne avec de vraies mesures de distances.
En fait, je conseille à tout le monde de vérifier ses capteurs et l’ARDUINO en retirant la division par 58, puis mettre un obstacle à un mètre, voire deux mètres, lire le retour, et opérer la division qui ramènera aux centimètres.
Par exemple avec ma cible à 100 cm, le programme sans la division retourne autour de 7700, alors je divise ensuite par 77 pour obtenir les centimètres.
Je ne comprends pas d’où vient l’écart.
PS : on peut mettre des floats à la place des entiers pour les variables lecture_echo et cm.
Cordialement,
LDVC@


#8