I've asked another question in electronics about what to use to compare 2 input voltages, the answer was to use comparators.

Digging around a bit, turns out most of the comparators outputs are pull-up, which makes it quite difficult to translate (probably due lack of general electronics knowledge, self-learned) and I'm not able to distinguish from maker's PDFs which comparators have pull-up or pull-down outputs. I've figured PD comparators illustrate in PDF a resistor right after the output... but many illustrations I've seen doesn't clarify PD / PU, or I'm just missig that.

But my question is, are there any PD comparators (well known) where it's output can be connected to the digital pins or arduino (while those are defined as INPUT mode)?

I appreciate any guidance on this topic.

Just a side note, I want to switch on a led, when ever external source is at 12V and turn that same led off when it's below 11.5V...

2 Answers 2


You can't put 12 volts into a Uno input pin in any case.

You could run it into a voltage divider and divide it down to somewhere on the range 0 to 5 V, and then do an analogRead to see exactly (or almost exactly) what the resulting voltage is.

I don't really see where comparators come into it in this particular case. I mean, you could use a comparator to turn the LED on, but then where does the Arduino come into it?

I've actually tried with voltage divider, I went pretty high on my resistors, taking the 12V source and hooked in 4x1M resistors but the 12V never came down significantly.

You need a voltage divider like this:

Voltage divider

Those values give you 4 V on the Arduino pin if there is 12 V on the input.

Vout = (R2 / (R1 + R2) ) * Vin


(1000 / 3000) * 12V = 4V
  • Perhaps the 12Vs don't have to do anything with the comparator. It does not read like it is related.
    – Ariser
    Sep 16, 2015 at 3:48
  • You could be right, but I read I want to switch on a led, when ever external source is at 12V and turn that same led off when it's below 11.5V... as the purpose for the comparator.
    – Nick Gammon
    Sep 16, 2015 at 3:50
  • I was guided towards comparator since the external source is signal turning light in vehicle at it seems to output 12v as active and 11v (or close to 11v, +-0.5v) as inactive signal into the lightbulb. tho I suspect that there is some module that listens to these voltages and gives either 0 or 12v to the actual bulb but I'm unable to take apart that headlight to confirm that.
    – Deko
    Sep 16, 2015 at 10:12
  • Ive actually tried with voltage divider, i went pretty high on my resistors, taking the 12V source and hooked in 4x1M resistors but the 12V never came down significantly. I also tested out with few lower resistors like mutiple 100K, also with multiple 4K7 (all in series) but i only got 6V as lowest and 9V as highest (also that 9V sometimes peaked up to 11V). I did try to add more and more resistors to bring the 10V/12V scale down for arduino to handle but it never succeeded.
    – Deko
    Sep 16, 2015 at 11:05
  • You aren't doing it correctly then. Two resistors are all you need. A voltage divider does not work by having a lot of 1 M resistors in series. You need two resistors only, and tap into the junction between them. For example, a 2 k and a 1 k would divide 12 V down to 4 V. See voltage divider calculator. Look carefully at how they are wired.
    – Nick Gammon
    Sep 16, 2015 at 20:34

Many comparators come with open collector output. OC output means, it can pull down a potential, but cannot generate a voltage higher than ground.

If you have a high impedance input like your Arduino has, and you connect a OC output to it, nothing will happen unless you add a pullup resistor providing a positive voltage. Otherwise there won't be a closed electric circuit where any measurable voltages can be generatet.

Lucky you: Arduino input pins can generate a positive voltage by providing an internal pullup resistor. Read the documentation on input pins and pin direction to make use of this. This way you can connect an open collector output to your input pin without additional components.

But beware: This doesn't work with a comparator with a pullup output (I guess these are rather rare). In this case you have to provide an additional pulldown resistor to ground.

Caveat: You can use a comparator with totem pole or tristate output without pullup or down as long as its output swing does not exceed maximum allowable voltages of the input pin. I.e. you cannot connect a comparator supplied with 15 V and a totem pole output to the input of an arduino, because the high level will exceed 5 volts (I assume an Arduino Uno).

Now. How to learn from a datasheet, if the output is pulldown, pullup, totempole or tristate? If a device features a pulldown stage, you will find a value for something called "Output Sink Current" in the section "electrical characteristics". For a pulldown stage this will likely be named "Output source current". A tristate output will be denominated somewhere in the datasheet for sure, because this is an extra feature.

Have a look at lm339!

  • thank you for really good explanation, will check it out with PDFs. the reason to arduino is this led is actually neo pixel, and in arduino î have multiple animations for these pixels
    – Deko
    Sep 16, 2015 at 10:14

Your Answer

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

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