Current Presence Sensor

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.

Comparator_symbolCreating a Measurable Voltage Drop

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.

Amp-sense-fig1I started with 10 Ohms and got 2V. I check the temp of the resistor with an IR thermometer to make sure it wasn’t getting too hot.

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:

Amp-sense-fig3Note that I am powering the LM339 with 3.3V and pulling the output pin up with the same voltage.

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:

150626-fig1I should mention there is a site that will calculate the resistor values:

For me, there were too many unknowns to make this work.



This entry was posted in c-electronics and tagged . Bookmark the permalink.

2 Responses to Current Presence Sensor

  1. zoomx says:

    How about an optoisolator? The LED part will be connected to the 24V and the sensor part to RaspberryPI. Led will need a resistor.
    You can use a led and a sensor but an optoisolator is… isolated from ambient light.

    • Dan TheMan says:

      Seems like that would work.

      My project is ending up needing an MCU anyway (I will replace the RPI with a Teensy), so I’m planning to simply use one of the analog pins to measure voltage across a voltage divider and get rid of this circuitry altogether.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s