Hello,

I have followed this guide to prepare my sensor from this video.

Now I am using a custom code for my quadcopter.

And I have included in that custom code this lines of code to read my sonar sensor readings and print them in the console to monitor what happened with the sensor.

static AP_HAL::AnalogSource *Sonar_pin;  

void setup(){

Sonar_pin    = hal.analogin->channel(0);// i have it at A0 pin on my board

}

void loop(){

for(int i = 0; i < 60 ; i++)

  {

    float cm = Sonar_pin->voltage_average();

    hal.console->printf_P(

    PSTR("CM : %d\r\n"),

    cm);

  }

}

And the results are these:

3691289353?profile=original

Does anyone can help me get proper readings print in the serial monitor of the IDE and also determine if i wire good my sonar sensor .

I want to use the readings of the sensor to install an obstacle avoidance system to my quadcopter.

Thank you.

static AP_HAL::AnalogSource *Sonar_pin;  

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Did you solve your problem? it may be caused by baudrate.(Surely.)

    And your source-code is Awesome! I'm now coding source similiar to yours. your code is very helpful.

This reply was deleted.

Activity