MaxSonar with Arduino (kind of)

The declared purpose for this project is to detect the presence of a person, in a relatively tight area, and switch the light on and off.

About schematic

There is an Arduino-like core, an MaxSonar®-EZ0™ High Performance Sonar Range Finder, a 24V relay to control the light and a PTN78060 voltage regulator from 24V to 5V. [Note 1]

Because I didn’t want to use a full Arduino (i.e. whatever 16MHz ATmega328P) I switched for an improvised Arduino.

Actually it is an ATtiny45 AVR controller intended for some other application. I just fitted it in to match my purpose.

As you may know, out there is an extension for some ATtiny controllers to behave as Arduino, of course a tiny one . Take a look here: to figure out whether this is interesting for you.

Here is the schematic in pdf format.

Some explanation might help to have an idea of how this is actually working.

  • The 24V relay: this is one that I had had the intention to use for this project, because the light is powered by 24V (a LED fixture). You can use some other relay but have to adapt the schematics.
  • The PTN78060W is a 3 Amp Wide input – Adjustable Switching Regulator. I got a bunch of them and now I use them everywhere [Note 2]. As you can see, from the data sheet, there is, indeed, a wide range of values for input voltage, from 7V to 36V,  and the output voltage goes from 2.5V up to 12.6V. What is really amazing is the efficiency of 93%, that means it works cold. The output voltage is adjustable by one resistor (see the values in the table at the end of data sheet).
  • Now we get closer to the “core” of this project.
  1. The first part is LV-MaxSonar®-EZ0™ High Performance Sonar Range Finder. It 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 typically range as 6- inches. The  interface output formats included are pulse width output, analog voltage output, and serial digital output. I use here the pulse width output. It outputs a pulse width representation of range. The distance can be calculated using the scale factor of 147μs per inch. That means for 6 inches distance the width of pulse is 6*147 = 882μs and for 40 inches the width is 40*147 = 5880μs or 5.88ms.
  2. The second part is the AVR controller ATtiny45. This behaves as Arduino, a tiny one – of course, with only 6 pins (plus two for Vcc and GND). This might be enough for some applications. As specified before, you can install the tiny core extension for Arduino IDE. To figure out what’s about you can take a look at Arduino Forum and this topic might be a good start:

Some words about the code

Here is the file with the code (pdf format).

[To be continued …]


  1. I usually use what I have at hand and match what I have to improvise a solution for my purpose. This is the reason for some mixtum-compositum you can find weird or not so usual. The amount of money spent is almost zero. Indeed I have a pile of  electronic stuff  gathered during long years…

  2. I have a couple of applications for these nice little guys.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s