MB1010 LV-MaxSonar-EZ1 sensor using timer interrupt


hi guys! of know how write code able measure distance of target
mb1010 lv-maxsonar-ez1 sensor of quadcopter? have read in datasheet have wait 20microseconds before pin 3 analog voltage, can start read , calculate value. have write code 20microseconds? between i'm using analog voltage not pulse width. current code, on right path?

const int anpin = 0;

//variables needed store values
long anvolt, inches, cm;
int sum=0;//create sum variable can averaged
int avgrange=10;//quantity of values average (sample size)

void setup() {
serial.begin(9600);

}

void loop() {
 pinmode(anpin, input);
 //maxsonar analog reads known sensitive. see arduino forum more information.
 //a simple fix average out sample of n readings more consistant reading.\\
 //even averaging still find less accurate pw method.\\
 //this loop gets 60 reads , averages them

 for(int = 0; < avgrange ; i++) {
   //used read in analog voltage output being sent maxsonar device.
   //scale factor (vcc/512) per inch. 5v supply yields ~9.8mv/in
   anvolt = analogread(anpin);
   sum += anvolt;
   delay(10);
 }
 inches = sum/avgrange; cm = inches * 2.54;
 serial.print(inches);
 serial.print("in, ");
 serial.print(cm);
 serial.print("cm");
 serial.println();
 //reset sample total sum = 0;
 delay(500);
}



Arduino Forum > Using Arduino > Project Guidance > MB1010 LV-MaxSonar-EZ1 sensor using timer interrupt


arduino

Comments