I wanted to expand my Raspberry Pi robot and bought 2x 4 way channel infrared boards with adjustable distance, but I didn't research if I would actually be able to connect these to the raspberry without a analog to digital convertor of some sort. Here are a few pictures of the IR board along with the description from the online seller:


  • Working voltage: DC 3.3V-5V
  • Working current: try to choose more than 1A power supply
  • Working temperature: - 10oC - +50oC
  • Mounting aperture: M3 screws
  • Detection range: 1mm to 60 CM adjustable, the closer the performance more stable, white reflects the farthest distance.
  • Size: in the control panel of 42mm x 38mm x 12mm (length x width x height)
  • Small forward 25mm x 12mm x 12mm (length x width x height)
  • Output interface: 6 wire interface (1234 to 4 signal output ends, + positive power, - for the negative power is ground)
  • The output signal: TTL level (can be directly connected to I/0 microcontroller, infrared light reflected back to the sensor induction, the red indicator light, output low level; no infrared light, the indicator light does not shine, the output high.)

Images: enter image description here
enter image description here

In my understanding the TTL means that the output from the control board is Digital, but I am not sure about that. Can anyone tell me:

  1. if this(outputs) can be directly connected to the raspberry pi GPIOs?
  2. if it can, what resistors should I use to protect the Pi?
  3. if this can be powered from the cheap L298N motor drivers(I am using one to drive 2 DC motors)?

I am using RPi.GPIO library for my project, if that matters.
Many thanks in advance for any comments/replies.

UPDATE: I was finally able to measure the output:
Input 3.3V - Output signal High=3.2-3.3V Low=0.2-0.3V
Input 5V - Output signal High=4.9-5V Low=0.2-0.3V

Can I accept it as safe to connect to Pi(probablt with just a resistor) when supplying 3.3V?

  • TTL is 5v digital logic. The pi has 3v. Gpio pins.
    – PaulF8080
    Apr 3 '16 at 6:24
  • That's great. So I just have to figure out the resistors needed? Would it better to make a voltage divider for each output?
    – archer66
    Apr 3 '16 at 7:42
  • The one thing that puzzles me is they say TTL, but they also say it can have a 3v supply.
    – PaulF8080
    Apr 3 '16 at 10:53
  • @archer66 "Can I accept it as safe to connect to Pi(probably with just a resistor) when supplying 3.3V?" Yes.
    – jDo
    Apr 6 '16 at 21:02

What you have there is a 4-channel comparator (LM339) circuit with 4 x 10 K resistors on the outputs (pull-ups, it seems), a capacitor, 4 x 10 K trim pots on the inputs and 5 indicator LEDs. The LM339 comparator is quite rugged and can operate within a voltage range of 2-36 volts. The limiting factors are the LEDs that probably require 3v3-5v volts and the Pi GPIOs that only operate at 3v3.

if this(outputs) can be directly connected to the raspberry pi GPIOs?

Maybe, maybe not. The fact that it has male pins on the board suggests that you can but it's hard to tell how much thought went into making the thing. I wasn't able to find anything about internal resistors in the LM339 data-sheet so I don't think it has any. On your board, I only see the 10 k pull-up resistors - these won't burn up a large enough share of the current to save the Pi in case of over-current (their purpose is to ensure a clean, active low signal). I'd measure it with a multimeter/ampmeter or check if it burns out an LED that's connected directly without resistors.

if it can't, what resistors should I use to protect the Pi?

The absolute maximum current on the output channels of the LM339 is 18 mA. At 3v3, this means that the minimum required resistance to keep the LM339 safe is 183 ohm. Practically speaking, anything in the 680-4.7K is fine. Digital GPIOs are voltage driven, not current driven, so you might find that it still works with something ridiculously high like 100 K. Anyway, when in doubt, start out (too) high and reduce resistance until the thing works. More practical still, just use 4 x 1 K resistors from Pi GPIOs to board input - always a safe bet providing you keep the voltage at 3v3.

if this can be powered from the cheap L298N motor drivers(I am using one to drive 2 DC motors)?

Current won't be an issue (motors require more current than a few IR LEDs and a comparator) but can the L298N provide voltages as low as 3v3? Also, do they flip the polarities to change the direction of the motor? If so, make sure you don't end up doing that with your digital logic circuits. Diodes are your friends if reverse polarity is a risk.

Anyway, if you can get 3v3 out of the L298N modules and don't overload the thing by driving two motors meanwhile, it should work. Otherwise, just get some DC-DC buck converters, connect them directly to your power supply and have dedicated power to the comparator board - maybe via a MOSFET if you need to turn the thing off.

  • Marked as answered. I have breadboard power supply that can output 3.3V and I'll try to use it to power the board. If no place to mount it on the RC car then I'll suply power from L298N +5V out and try voltage divider on each output, as with HC-SR04.
    – archer66
    Apr 20 '16 at 6:55
  • @archer66 Cool. Sounds reasonable. I think it'll work fine.
    – jDo
    Apr 20 '16 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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