Suppose I give you the job of building a little gadget that will measure how far you walk in a day. Sounds like a tricky task to me. You could use something like a click wheel (a large wheel you roll over the ground that clicks each time it turns one complete circuit), but rough or muddy ground is going to cause problems and it's going to have a job measuring stairs.
Okay, so let's redefine the problem by considering what walking involves. Every time you walk, your body tilts to one side and you swing a leg forward. Then your body tilts the other way and you swing the other leg forward too. Each tilt of the hips and shift of the legs is a step. Assuming each step is pretty much the same length, all we need to do is count the number of steps we make in a day, by counting the number of times our body tilts from side to side. We can then multiply the number of steps by the length of each one to figure out the overall distance walked. This is pretty much how a pedometer works.
link https://www.explainthatstuff.com/how-pedometers-work.html