DFROBOT Gravity ultrasonic sensor with pixhawk

Hi, this is a rangefinder I had previously

This is the arduino code I used: I worked. But In don’t know how to use it with pixhawk. Plz help

#define  MAX_RANG      (520)//the max measurement vaule of the module is 520cm(a little bit longer than  effective max range)
#define  ADC_SOLUTION      (1023.0)//ADC accuracy of Arduino UNO is 10bit

int sensityPin = A0;    // select the input pin 
void setup() {
  // Serial init
  Serial.begin(9600);
}
float dist_t, sensity_t;
void loop() {
  // read the value from the sensor:
 sensity_t = analogRead(sensityPin);
  // turn the ledPin on

 dist_t = sensity_t * MAX_RANG  / ADC_SOLUTION;//
 Serial.print(dist_t,0);
 Serial.println("cm");

 delay(500);

}
FAQ

I looked up Maxbotix Analog Sonar — Plane documentation and found out that i’ll need to set 4 parameters:

  • [RNGFND1_PIN]= “14” for Pixhawk’s ADC 3.3v pin #2 ----> This is fine

  • [RNGFND1_MAX_CM] = “520” (i.e. 7m max range) if using EZ0 or EZ4, “1000” if using EZL0 ----> This also I measured

  • [RNGFND1_SCALING] = “2.04” (i.e. 7m / 5v) if using EZ0 or EZ4, “4.08” (i.e. 10m / 5v) if using EZL0 ----> What about this? 7m/5 = 1.4 not 2.04 right? I thought of 5.2m/5

  • [RNGFND1_TYPE] = "1” (Analog) ------> This is fine

I think I got it, it should be 0.01(Vout)*520(max.range)/3.3(Vin) == 1.58

@amilcarlucas plz help

You will need to adjust the scaling parameter, best option is to measure a distance then adjust the parameter until the sensor gives a correct reading.

ok sure thanks I’ll try