Project List

Mail me

Last update: 2012-09-07



Polaroid sonar ranging sensors (model 6500) are very popular in the robotics community. However, they are not available everywhere and they are expensive. Buying an old/used Polaroid camera and re-using its transceiver and electronics is a cost effective alternative. Therefore, this article shows how sensors taken from a Polaroid 670AF camera can be attached to and evaluated by an Atmel ATmega8 microcontroller.


The functional principle of sonar ranging sensors it to measure the time-of-flight (TOF) it takes for the sonar pulse from being emitted to being reflected by an obstacle to returning home (and being detected) to the sensor.

When working with Polaroid sensors some vocabulary should be clear:

The circuit/software introduced here does not make use of BLNK/BINHI in order to keep effort small. Furthermore infrared sensors can be used to measure shorter distances.

Reusing 670AF Parts

Differences Between 670AF and 6500 Modules

As mentioned above this interface circuit drives a module taken from a Polaroid 670AF instant camera. One may find lots of pages and documents on the internet dedicated to the series 6500 module. Only little information on the 670AF electronics can be found on the internet. Both modules look very similar. But the electrical behaviour is different:

Connectors of Polaroid module 6500 and 670AF

Signals and Timing Diagram

Everything described below was taken from the Polaroid series 6500 datasheet or from internet sources dedicated to that module respectively. As mentioned above the Polaroid module taken from the 670AF camera has eight pins. With the INIT signal one triggers the messurement procedure. The module then sends out 16 pulses of 50kHz. When the reflected wave returns it is detected and the ECHO signal goes high. To avoid detecting the transmission itself the internal blanking is activated for a short period of time (2.38ms) after the INIT signal went high. The echo detection is supressed while the INTERNAL BLANKING is high. This determines the minimum distance which could be messured by the module to 40cm approximately. One could inhibit the internal blanking by setting the BINHI signal (blanking inhibit). Doing so decreases the minimum distance which could be messured. It also increases the danger of false readings. The internal blanking should take 0.9ms at least. That means that BINHI should go high at least 0.9ms after INIT went high. In my application either BINHI nor BLNK is used. They are pulled low internally. So I left the pins unconnected. The only signals used by my interface circuit are the INIT input and the ECHO output.

Timing diagram of Polaroid sonar module

Custom Hardware and Software

There are various variants possible ways of how to connect the sensor to the ATmega8 and for constructing the software. Included in this project are three different approaches. These three approaches require two different wirings.

There are a few things common to all these approaches. A short delay time is required after PWR has been raised. By experimentation I found out that 10ms do suffice. (This is probably to load the extra capacitor and also to power up the Polaroid circuit. Maybe the Polaroid circuit also needs time to stabilize its oscillator?) A short delay is also required once PWR has been reset to low. (This is probably to unload the extra capacitor, maybe also to unload coils/capacitors on the polaroid circuit board.) Polaroid uses a thin ribbon cable with according connectors. These are hard to handle and prone to loose contact when not fixed in a solid casing. Therefore I removed that unusual thin ribbon cable by a standard ribbon cable with according connectors (see picture below).

Polling the ECHO Signal

The first two approaches are actively monitoring the ECHO signal connected to an "ordinary" AVR input pin. These are the two principles:
  1. We do everything in the main loop. PWR and INIT are raised there as well as we conduct busy waiting for ECHO there. The delay is produced by the busy delay function _wait_ms(). Timer #1 is used to measure the time elapsed. This is achieved by reseting it at INIT and reading it at ECHO. Code example can be found in main-busy.c.
  2. We use timer #1 to produce time intervals of 100μs. In the corresponding ISR we implement a state machine which is clocked in intervals of 100μs. That ISR controls PWR and INIT. It also reads the ECHO pin. Even though we are polling here we nevertheless do it only every 100μs. In the mean time the AVR can be sent to idle sleep mode. Inside the ISR we also count the 100μs ticks. This will be our time elapsed. Code example can be found in main-constant_interval.c.

Wiring diagram (variant A, no input capturing)

Using Input Capture to Read the ECHO Signal

The last approach uses the AVRs input capture capability to supervise the ECHO input. Most of the activity takes place in the main loop. However we only indirectly poll for the ECHO signal. ECHO is connected with the input capture pin ICP1. When the Polaroid electronics raises ECHO (raising edge) the corresponding interrupt will be triggered. First thing the ISR has to do - according to the ATmega8 datasheet - is to read ICR1. (The current timer value is saved in ICR1 when the input capture flag is set.) Code example can be found in main-input_capture.c.

Thoughts have to be spent in case one want's to use input capture while applying more than one sensor. The ECHO output is open collector. They can simply connected together with no further measures. But that is a logical OR meaning that the input capture ISR will be triggered in case any sensor is firing its ECHO output. Once the first sensor has raised its ECHO pin no further sensing with the remaining sensors is possible. A possible solution is to use one sensor after the other and reset (¬PWR) the sensors before progressing to the next sensor. This will decrease the number of measurements per unit of time because power-up and -down requires some delay. Alternatively one could use a multiplexer to let through only the current sensor. In that case power-up and -down would only be required at the beginning of an measurement sequence and at the end respectively. But that would also increase complexity and number of parts used.

Wiring diagram (variant B, using the input capture pin ICP1)

Things To Be Improved

It would be great to use an interrupt to produce the waiting time intervalls and to use input capture. By doing so everything would be in the interrupt service routines. The AVR would be idle sleeping most of the time unless an interrupt occurs.



Original Polaroid module from 670AF camera
670AF module with connector replaced
Prototype with 670AF module attached

Version History

1.0.02012-08-19Initial version.
1.1.02012-09-07Now using libAvrUtils 1.2.0.

Copyright Statement

mega8usRanger Copyright (C) 2012 Holger Zahnleiter

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. The program and its source code are published under the GNU General Public License (GPL). See http://www.gnu.org/licenses/gpl-3.0.txt for details.


Creating this library would not have been possible without the achievements of the following persons/organisations:


Sonar Ranging Primer Sonar Ranging Primer Acroname Robotics.
Sonar Ranging Application Notes Sonar Ranging Application Notes at Arrick Robotics.
http://www.mikrocontroller.net/ A great (german) resource of Atmel AVR tutorials and general microcontroller know how.
RoboterNETZ Another great (german) resource of microcontroller know how.
AVR freaks English speakers should visit this website.
CrossPack CrossPack for AVR Development for Mac OS X.
AVR-GCC-Tutorial German avr-gcc tutorial from mikrocontroller.net.
http://www.nongnu.org/avr-libc/ The AVR C library (for use with avr-gcc).
http://www.nongnu.org/avrdude/ AVRDUDE, a tool for flashing AVRs.
http://www.cadsoft.de/ EAGLE a CAD software for designing circuits. Free version available for Mac OS X, Linux and Windows.
RS-232 product site MAXIM's website featuring their line of RS-232 transceivers. The most current datasheet can be downloaded from there.
ATmega8 product site Atmel's website featuring ATmega8. The most current datasheet can be downloaded from there.


Source code for ATmega8 (mega8usRanger-1.1.0-src.zip)
ATmega8 test program (testBusy.hex)
ATmega8 test program (testConstantInterval.hex)
ATmega8 test program (testInputCapture.hex)
Wiring diagram/Eagle 6.2.0 (mega8usRanger_A.sch)
Wiring diagram/Eagle 6.2.0 (mega8usRanger_B.sch)
Atmel ATmega8 Datasheet
Polaroid Sonar Transducer Datasheet
Polaroid 6500 Sonar Board Datasheet
MAXIM RS-232 Transceivers Datasheet


The information on this web site and the documents downloadable from here have been carefully reviewed and is believed to be reliable, but I do not assume any liability arising out of the application or use of any documents, programs or circuit described herein.
Furthermore I want to declare that I'm not responsible in any way for the content of other web pages, books and other sources I'm refering to.