Introduction: Attiny85 Distance Finder

About: Just a student that enjoys programming.

Before I made this instructable I had just gotten some new Attinys (Attinies?) and wanted to make something with them. That's when I noticed my ultrasonic range finder all alone being unused. This ultrasonic Attiny distance finder gives the distance through a series of flashing LEDs and can even be switched from CM to IN by holding the button for long enough.

Step 1: Gather Materials

Sorry, most of the links are for items in bulk but they're cheap and are what I used.

Step 2: Built the Circuit

If you want you can test this on a breadboard to make sure everything is in order, or you can go straight to a perfboard (or create your own PCB).

port number (pin Number)

  • Ultrasonic echo + Trig pin >>> 2 (7)
  • Button ------------------------- >>> 1 (6)
  • 50s LED ---------------------- >>> 0 (5)
  • 10s LED----------------------->>> 4 (3)
  • 1s LED ------------------------ >>> 3 (2)

Feel free to change these anyway that's easiest to make. I set it up this way because it looked the nicest on Fritzing :)

Step 3: Program the Attiny

As you probably know extra steps are needed in order to program an Attiny. If you know how to program on continue on your way! If you don't, here is a link or an instructable!

Also, MAKE SURE to download the New Ping library as that is how I can have the echo and trig on the same pin. If you don't know how to add a library, download the .zip from the link then go to
Sketch > Include Library > Add .zip Library > Downloads > NewPing*.zip

*Please don't say that you are getting errors while compiling without first adding the library!*

And here is the code.

Step 4: Using It

Basically now it's just point and shoot (well, press).

To give the distance there are three LEDs. One meaning 50, 10, and 1 respectively. For example, if the distance is 67 then the 50 LED will flash once, the 10 will flash once and the 1 will flash seven times. All adding up to 67. (50 + 10 + 7= 67).

To switch it from CM to IN or vice versa hold the button for over two seconds. Depending on what it is currently on (Its default is CM) all the LEDs will flash to indicate what it got set to.

Solid light on then off == CM to IN
Flashing light ---------- == IN to CM

If you have any questions feel free to ask!

Arduino Contest 2017

Participated in the
Arduino Contest 2017