Code for Ultrasonic ranger sensor using witg Zoul (zolertia2 module)

Hey everybody,



I’ve seen lots of python and cpp codes for ardwino but I need and I’m looking for the code of the grove ultrasonic ranger to use with zolertia2 remote (on contiki OS).



Really appreciated

Hi there~



We do not have the zolertia2 modules. you can base on below arduino code to write your own code. The distance equals duration/58. Duration is the ultrasonic trig to echo time travel slot and unit is uS. The distance unit is cm. thanks.

</s>long Ultrasonic::MeasureInCentimeters(void) { pinMode(_pin, OUTPUT); digitalWrite(_pin, LOW); delayMicroseconds(2); digitalWrite(_pin, HIGH); delayMicroseconds(5); digitalWrite(_pin,LOW); pinMode(_pin,INPUT); long duration; duration = pulseIn(_pin,HIGH); long RangeInCentimeters; RangeInCentimeters = duration/29/2; return RangeInCentimeters; }<e>