Best sensor to use for lineal distance

Hey all,

i am new to the world of Arduino and having heaps of fun with it. But it’s time to put it to work. I want to make a lineal metre counter like the old school wheel counter but want to do it with sensors and not need to physically touch the surface I’m measuring.

My objective is - count the total lineal meters of timber i feed through a machine, count the number of individual lengths and the time from when the first length enters to when the last board exits.

I would love some suggestions on the best way to do this and the best sensors to use. the proximity of the timber to the sensor would be as close as 5mm and as far as 250mm.



Hey Gavin,

Glad to hear!
Are you able to mod the machine a little bit? I’d say adding a rotary encoder(this is just an example, I’d measure up the machine and pick one to suit - RPM of the shaft and diameter) would the easiest way to going about figuring out the length of the timber and to detect the presence a laser TOF sensor or ultrasonic distance sensor.

A lil bit of a tangent although relevant: With many projects there will be many ways to do it and some will be easier or more accurate than others…first point fixation and sunken cost fallacy come into play a lot as well - Zack Freedman has a couple great videos on this topic

1 Like

Hi Gavin

This could get a bit tricky.
What size are we looking at. Large sawmill type thing or small hobby workshop style. What sort of accuracy are you looking at. Possibly the easiest if there are rollers involved would be count roller revolutions and calculate but that would assume no roller slippage.

Without having a roller on or something attached to the timber this could be a bit more tricky that seems at first sight. I think to measure acoustically or even optically to the end of the timber this end would have to be a respectable size.

Maybe a tape measure and pen and paper???
Cheers Bob


Hi Liam. Thanks for the reply.

I was hoping not to mod the machine but it to be more of a simple add on.
A rotary encoder was my first thought but the feed rollers run continuously and are difficult to get to obviously for safety reasons.

I asked the same question in a FB group and an ultrasonic sensor was a suggestion I received there.

This would involve me calculating the roller feed rate and having the sensor trigger at the start and end of each board. The duration of the triggered sensor calculated with the feed rate I.e. mm/sec would give me the length.

Cheers for the links. I’ll take a look at them.


Hi Robert.

Thanks for your suggestion. I just replied to Liam who also suggested using the rollers but is a bit difficult with there location atc.
We aren’t talking a big mill but not as small as a hobby scale. I make bespoke furniture and decore pieces. Accuracy at this point of the milling process regarding length isn’t that critical and just wanted to add this into my work flow to track time and quality on a rougher scale. More so for my own curiosity and time management.

Haha. A pen and paper yes and that’s how I do it now but there is no fun in that. The thing I’m loving about this Arduino scheme is it’s at the opposite end of my skill set but still allows me to use my creativity and be inventive.


Hey Gavin,

Yeah definitely a good call not wanting to mod your machine aha.
If the machine has a constant feed rate you might be able to take one from the books of 3D printing.

When you set it up a printer you’ll get a bit of material and feed it through, then you’ll take a measurement after say 3 seconds or so and see how far it has moved (This processes is called ‘-step calibration’ and uses a distance instead of speed but same difference). Log that on the Arduino and you’ll have a feed rate(speed) then using a break beam sensor or something (The TOF sensor above could do this as well) from this you will be able to calculate the length of each piece.
To adjust it you could hard code it directly into the microcontroller (Arduino) or have a screen and adjustment knob to set.

A good brainstorm might lead you to some other ideas that could work better

1 Like

hey Liam,

that sound like a plan!

Would ultrasonic be better than IR due to dust?

that’s kinda what i was thinking along the same lines as a 3D printer or CNC stepper calibration. i am thinking i could use a ESP 32 and bluetooth it to my tablet to retrieve the data so could add calibration settings to that. i always have a tablet at hand in my workshop for reading drawings etc.

1 Like

Hi Gavin
Liam is right. If you know the speed all you need to do is detect the ends of the timber and calculate the length.

This rather defeats your original statement re nothing touching the timber. If you are going down the feed roller path and they are a bit hard to get to you may as well have a wheel contacting the timber. There may be a chance you can set the feed rollers to known speeds then you would not have to measure it as long as the settings are reliable enough

Advice (for what it is worth). Get the first (measuring) part working first then you can tackle the exotic bits later. If you don’t attack this in a structured manner you will find yourself going in ever diminishing circles. We all know where that ends up don’t we…
Cheers Bob

1 Like

Hi Bob,

yeah i dont really want anything running in the timber for a few reasons.

this has given me a few ideas i would like to expore and i agree… KISS principal.
i am all to familiar with over complicating things.

1 Like

AHHHHH, another believer in good old KISS.
Cheers Bob


What technology does an optical mouse use? It doesn’t have to touch the desk although admittedly it has to be so close as to hardly matter. But maybe that tech can be adapted and used a few mm above the surface.

EDIT: I just tried, my mouse still works 2-3mm away.


Hi Rob and all,

Found this sensor and think it could be useful, It’s basically a mouse sensor but longer range:

Have a read and see if this is helpful

P.S. Just found out it has a longer range brother:

Only catch is that it’s gotta be at least 80mm away

1 Like

Ha ha, just saw this and I came back to this thread to post about it, you beat me to it :grinning:

Will be interesting to see if it does the job.