For my current project, I need to sense if current is present on a 24V @ .2A circuit. Further, I want a very cheap solution and I don’t want to use an MCU. The output needs to be a 3.3V signal so I can read it with a Raspberry Pi GPIO pin.
I started researching how to do this. A good article is here:
I decided to go with low-side sensing. That way the amount of voltage being sensed is low, although the LM339 comparator could handle the 24V signal. It just seems like the smart way to go for a beginner such as myself.
Although I’ve experimented with them before, I had to learn a lot more about comparators before I could get this working. Once source was
Unfortunately I didn’t save the link to the simplest explanation I could find but it said, in essence, if the non-inverting signal voltage (+) is higher than the inverting signal voltage (-), then the output will be positive. That’s the clearest explanation I’ve ever found and finally sunk in.
The first thing necessary is to create a voltage drop after the load by inserting a low resistance resistor between the load and ground. I could have tried to figure this out with math, but since I only have a few different such resistors on hand, I just stuck them into the circuit and measured the voltage drop.
Then I went to 100 Ohms, knowing that probably wasn’t going to work. Sure enough I got 9V which is pretty high, but more importantly the resistor started getting quite hot – 145 deg F.
So then I went down to 1 Ohm. The voltage drop across that was very small, < .1V. It stayed cool as well.
So I decided to go with a 10 Ohm resistor and ordered a 1W model to be sure there would be no heating issues (my test resistor was 1/4W). My estimation is the power consumed will be .4W (2V * .2 A). So 1W should be plenty.
Determining Resistors for Comparator
I decided to use the LM339 comparator because it is well documented and cheap. With 4 comparators, it is cheaper than the LM139 that has only 1.
It took several hours of messing around and failing but I came up with the following circuit I was able to use to determine what resistor I needed for the inverting input of the comparator.
I used a 100K POT, and started it at 0 ohms and increased the resistance until I got the LED to turn on/off when I powered the load. Once I got to where I was happy, I was at about 50K Ohm.
I should note here that my load simply switches on and off. I saw no advantage to trying and setting up a feedback loop from the output pin to the input pin.
At this point, I have the values for R1 and R2 so I was able to complete the sensor circuit:
When the load switches on, a 2V voltage occurs across R1. The LM339 senses this, turns off its internal sink transistor so the 3.3V signal goes to an input GPIO pin of the Raspberry Pi.
My original circuit appeared to run fine, but, when I connected the output to a Teensy to monitor the sensor pin, the signal was oscillating off and on very fast. Connecting the output to an oscilloscope, I could see noise on the output line that the voltmeter just didn’t pickup on.
I corrected the problem by creating a feedback loop from pin 2 to pin 5. As with the other resistor values, I connected a pot and adjusted it until the output signal was low EXCEPT when the current was detected. I found this to be 27K Ohm for my application and inserted a fixed resistor. This circuit works fine with the Teensy:
For me, there were too many unknowns to make this work.