Asked — Edited

Ping Sensor Offset

how can i add offset to sonars or IR sensors ,some sensors dont read the distance correct ,like sonars its 6 inches

Skip to comments


Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.


The value returned by the sonar is not a distance in inches or mm. There will be no offset setting. If you wish to convert your numbers to a unit, use math within EZ-Script:)


This is the info i got on maxsonar EZ1 model The LV-MaxSonar-EZ1T detects objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. Objects from 0- inches to 6-inches range as 6-inches how would i add that to your control under sonar distance like 1 inch from sonar is read as 1 inch and 2 inch is read as 2 inch and so on


The value returned from the EZ-B is a number between 0 and 255. The returned value is relative to the distance resolution of the sensor.:)


is that analog voltage or ping value and do you have a example for the math and formula for the ping distance

lv-maxsonar-ez1 has both analog output and ping output

from the data sheet it says 147us/inch for pwm (ping)



Do it like we did for Leaf. Just measure the distance every foot or so.  and make the notes to what value from 0-255 you get. Then you can pretty well tell what is two feet, four feet, eight feet,

six inches, etc.


no,its not the same,it is C SHARP program,and not shore how ALEX did it plus some was done in lispworks too


If you are working in C#, it is really easy. Or even EZ-Script it is easy. It's simple math, and here's how.

So let's say you take a tape measure and measure the distance between the sensor and a wall. Let's speculate the distance is 50 cm and the value is 100.

One would assume that a value of 200 would be the distance of 100 cm, and the value of 50 would be a distance of 25 cm.

So it's easy to see the multiplier (scalar) for the returned value would be 0.5 (50 divided by 100).

So you could make a C# function like this...

public decimal GetDistanceInCM(EZ_B.Digital.DigitalPortEnum triggerPort, EZ_B.Digital.DigitalPortEnum echoPort) {

      decimal scalar = 0.5m;
      decimal value = GetValue(triggerPort, echoPort);

      return value * scalar;   


Ok thanks DJ, i thought it was much more in the EZ script. also thats in cm ,i forgot formula for inches

Coding is always hard for me and thinking for most of the rest of the guys in the forum ,thats one reason you made the EZB


You mentioned the program you are working with is C#.

If it is EZ-Script, than you will do this...

$value = GetPing(d0, d5) * 0.5

First you just need to figure out your scalar. And use the tape measure like my prevoius response:)


OK thanks DJ ,last question i need in inches


Hi @robotmaker From what you posted re: the specs on the LV-MaxSonar-EZ1T, (1 inch resolution and 0-254 inch range)... since that matches the ADC range of 0-255 then I would think that you could use the Analog Output of your sensor and an ADC port on the EZ-B.

The ADC Value control does have the option to type in your unit of measurement (for our visual purposes only) and a multiplier feature, which if set to 0 should represent 1 inch for each displayed number.

You may not need a scaler (multiplier) but if you do then the math is the same, just do the calibration steps @DJ mentioned using inches, and enter the scaler number in the multiplier field (i.e. 0.5 using @DJ's example).

Hope this helps.


they say that the analog ouput is not very stable,this sonar has the best accuracy of all the sonars pwm is very stable