implemented reading distance sensor logic