I'm thinking about getting a bunch of Maxbotix Ultrasonic rangefinders. I'd like to use as few pins on my controller as possible. Since I don't think you can have multiple devices on an RS232 serial connection, I'd quite like to interface their PWM output with the controller using I²C.

Is there some I²C device I can buy that accepts around 8 PWM inputs, and stores a representation of \$\frac{\text{pulse width}}{\text{period}}\$ in its registers?

  • 2
    \$\begingroup\$ Is "A microcontroller" with I2C and a timer acceptable, or do you need a custom solution? \$\endgroup\$ Mar 29, 2011 at 18:03
  • \$\begingroup\$ The key thing to realize is that you can only use one at a time anyway (they would interfere if used simultaneously) so this is really a muxing problem, not a multiple reading problem. You can probably simply combine the receive pins (with OR or AND depending on the sense) and select only one transmitter pin to fire. \$\endgroup\$ Sep 29, 2019 at 12:24

3 Answers 3


Thank you for linking to exactly what you are talking about -- it makes it much easier to get to the data sheets. The question "How can I use more than one MaxSonar®-EZ1™ in the same system?" in the MaxBotix MaxSonar FAQ lists several ways of using a bunch of them at one time (and some pitfalls to avoid). Some of them use 2 pins of the MCU -- the same number of pins as I2C, but a completely different protocol.

If I understand the data sheet correctly, one of those 2-pin methods is:

  • wire pin 1 low the MaxSonar to enable chaining
  • Wire an output pin from your MCU to the RX pin of the first MaxSonar in the chain.
  • Wire TX of each MaxSonar to RX of the next in the chain
  • Combine the signals from all the MaxSonar PW pins (AND? OR? NAND? diodes?).
  • Wire that combined signal to a timer input pin on the CPU.

Then software on the MCU

  • pulse the RX pin of the first MaxSonar
  • Time the first pulse width to give the distance the first MaxSonar sees
  • Time the second pulse width to give the distance the second MaxSonar sees
  • ...
  • After getting the pulse from every sonar (or timing out at 49 ms per sonar), do something with the data.
  • repeat.

Perhaps one of the other methods listed in the FAQ would work just as well or better for you.


Will an 8 channel ADC that supports I2C cut it?


  • \$\begingroup\$ @eric, if you place the signal through an averaging circuit(low pass) you will lose your response time but you can just read the analog value to know what percentage it is on. To expand on RQDQ's answer. \$\endgroup\$
    – Kortuk
    Mar 29, 2011 at 18:32
  • \$\begingroup\$ +1 Better yet, those sensors have analog output anyway! I'd still be interested in whether there are PWM input I²Cs out there though. \$\endgroup\$
    – Eric
    Mar 29, 2011 at 19:18

The microchip PIC18F87K22 has 10 capture compare modules that can handle this function and of course you can talk to it through I2C.

You could also do this will a really simple FPGA.

The Cypress PSoC family could probably also handle measurement of a bunch of PWM inputs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.