I was planning on implementing a current sense feature on the STM32 Bluepill to measure the current output of a solar panel (150 mA short-circuit current, 14 V Open-circuit voltage) using LM358 single-supply op amps and a 0.01 ohm shunt. No matter what I tried however, I kept getting an inaccurate output value (way bigger than expected, 0.7 V below the positive rail).

That led me to the conclusion that the issue might be caused by the difference between the ground voltage of the op-amp and the measuring loop (schematic below). This made me question whether it was even possible to measure current across such a low resistance shunt using a differential amplifier, or if something else is causing my circuit to act unpredictably.

It is important to note that the resistance between the breadboard pins I am using is 0.07 ohms which is probably the culprit here; in addition, when measuring the voltage on the input pins of the op amp with respect to op-amp ground (the pin itself) I noticed that their values are different from the ones with respect to the ground of my power-supply, and the output seems to correspond to their values and not the ones I intend to amplify. In other words, there doesn't seem to be a problem with the gain of the amplifier, or at least as far as I know.

I would love to get some clarification on this, in order to decide whether to buy instrumentation amplifiers or not.

Note: I also saw people placing ceramic capacitors between the positive input and ground and between the output and ground in this configuration. I thought since the problem might be noise-related then it would probably fix this issue, but it didn't.


simulate this circuit – Schematic created using CircuitLab

  • \$\begingroup\$ I'm recalling a circuit I used with two opamps and (5) BJTs. A double-pointed current mirror consumed (4) BJTs. (I used matched pairs.) The Early Effect was negated through the use of the 5th BJT and the two opamps did the heavy lifting. It resulted in a very nice, linear voltage with respect to currents in a still smaller range (10 mA) but with a slightly larger current sense resistor. The total was 10 mV of drop. You are 10 times smaller. (Oh, this was a high-side current sense.) I'd have to re-think it. Maybe someone smarter will pop up on this. \$\endgroup\$
    – jonk
    Sep 16, 2021 at 19:27
  • \$\begingroup\$ You can use a current -> voltage converter. Just add a 1 ohm in parallel with your 0.01 ohm. The 1 ohm current (1.5 mA) be converted to 1.5 V by 1000 Ohm feedback op amp. See my schematic this post electronics.stackexchange.com/questions/585824/… (op amp, with supplies +5V/-5V). \$\endgroup\$
    – Antonio51
    Sep 16, 2021 at 19:50
  • \$\begingroup\$ As op amp, this datasheet.lcsc.com/lcsc/… can be used, from my point view. Must use a real ground, so power supplies +2.5V/-2.5V (with real ground mid point of 4x 1.5 V batteries). \$\endgroup\$
    – Antonio51
    Sep 16, 2021 at 20:25
  • 1
    \$\begingroup\$ Just to be written in the protocol: 0.01 ohm for 140mA is crazy. The reasonable value is 1.0 Ohm. \$\endgroup\$
    – fraxinus
    Sep 17, 2021 at 7:11
  • 2
    \$\begingroup\$ @fraxinus: 1 ohm is likely a bit high (140mV ground mismatch is big enough to cause concern) but 0.2 ohm would be 20x as sensitive as the current 10mohm, and still drop only a very reasonable 28mV. \$\endgroup\$
    – Ben Voigt
    Sep 17, 2021 at 15:42

6 Answers 6


You don't have to use a differential amplifier providing you are careful about the voltage drops that occur along the grounds. If you return the bottom end of the 500 ohm resistor to the same point as the ground end of the sense resistor it should avoid most of those errors.

However, one of the first things to do with this sort of problem is to ensure that the voltage from the sense resistor is a good match for the sensitivity of the amplifier.

With a 10 m Ohm sense resistor and 150mA max current the sense voltage will only be 1.5mV. However, the offset voltage of an LM358 is in the region of +/-3mV. Double the voltage you are trying to sense. The circuit will not accurately measure the current flow.

Why choose a 10mOhm sense resistor with a 12V panel you can afford to have a much higher burden? 1 ohm would be a more appropriate value. This would give 150mV max sense voltage a very small amount compared to the 12V of the panel. To get a 3V signal then only requires a gain of 20. The amplifier offset voltage would only contribute about 2% error.

You should also use a better amplifier - low-cost ones can have less than 1mV offset. Also, the LM358 is not well characterized for 3.3V operation. As its output can only get within about 1.4V of the positive rail (depends upon load) the output voltage will be restricted to ~1.9V or less. A rail-to-rail output opamp is much better when running from 3.3V supplies.

Solar panels are convenient in that since both terminals are floating (ie not connected to the ground) the amplifier can be operated in inverting mode with the sense resistor connecting to the negative end of the panel - it will still give a positive-going output and gives the option for panel to charge the battery that is powering your circuit. I have used this approach on small solar-powered instruments where the charging current of the battery can be measured.

I also have the ability to short the positive terminal to the ground so that the short-circuit can be periodically measured to determine the solar intensity.

Here is an example showing how to measure the charging current while charging a battery that can power the amplifier as well as other circuitry. If the non-inverting input of the opamp is connected to the ground close to the sense resistor any ground shift is attenuated by a factor of 20 as it is relative to a 3 volt signal.


simulate this circuit – Schematic created using CircuitLab

  • 2
    \$\begingroup\$ @A.H.Z although the datahseet does specify that it will operate from as low as 3V, all the characteristic data in the tables & graphs is specified at 5V-36V. \$\endgroup\$
    – brhans
    Sep 16, 2021 at 20:42
  • 3
    \$\begingroup\$ @A.H.Z - Even if it runs it will not be able to output more than ~1.8V so it will limit the output range. \$\endgroup\$ Sep 16, 2021 at 21:18
  • 1
    \$\begingroup\$ @KevinWhite but in the datasheet it is stated that the output can range from ground to 1 V below the positive rail, I don't understand what you're referring to . \$\endgroup\$
    – A.H.Z
    Sep 16, 2021 at 22:52
  • 5
    \$\begingroup\$ @A.H.Z - on the TI datasheet, it states that the worst case is 1.42V below positive rail when driving 50uA. It is worse at higher currents. So the worst case with a 3.3V supply is 1.88V output, I did approximate it to ~1.8V. See page 10. \$\endgroup\$ Sep 16, 2021 at 23:02
  • 1
    \$\begingroup\$ @KevinWhite Yes you're right that is true. \$\endgroup\$
    – A.H.Z
    Sep 16, 2021 at 23:04

You have an amplifier with a gain of about +2000 and an offset voltage of as much as +/-3mV at room temperature. It might typically be +/-2mV (onsemi datasheet). Since the output swing with no load and a 3.3V supply is from some mV up to maybe 2V, the zero-current output could be about anything within that range. Your entire full-scale input signal is only 1.5mV, so 15uV represents a 1% error. That is very little voltage.

You don’t need an in-amp (though it would make it easier and allow sloppier design) but you should get an amplifier with a very low offset voltage and probably rail-to-rail output and input that includes the negative rail.

The “ground” on R2 is also extremely critical- it must go back to the sense resistor directly, and it ideally would be slightly divided as a differential amplifier, but here that is optional when you consider tolerances.


First of all, if you are measuring a sense resistor that is connected to wires, then there will probably be ground offset. You will need a differential measurement to handle that.

The op-amp circuit you have shown is configured for a single-ended measurement. It needs to be set up for a differential measurement to account for the ground offset caused by the wire resistances. Also you need to use separate wires for the current measurement and the power return (kelvin connection). If you let significant current flow in the sense wires it will create measurement error due to the wire resistance.


simulate this circuit – Schematic created using CircuitLab

Additionally, using a large sense resistor will provide more accurate measurements. Even something as large as 1 ohm would be reasonable for a 12V circuit running only 150mA.

There are several options for making an accurate measurement.

  1. Amplify the current sense voltage and then feed it into a normal ADC.
    a) Use an instrumentation amplifier IC.
    b) Use a regular op-amp configured for a differential measurement.
    c) Current sense amplifier IC.
  2. Use an ADC meant for current sensing, both Analog Devices and Texas instruments make ADCs with small input ranges for this purpose.
  • \$\begingroup\$ Check the LM358 common mode input range, and look again. Also, still has Av=2000. Sorry, -1. \$\endgroup\$ Sep 17, 2021 at 15:42
  • \$\begingroup\$ @hacktastical I was not intending to suggest a specific op-amp or gain. The key idea was to use differential sensing to remove ground offset. The values used were just what was in the original post with differential sensing added. I have amended the answer to omit specific values for the parts. \$\endgroup\$
    – user4574
    Sep 18, 2021 at 12:18
  • \$\begingroup\$ The only op-amps that support the kind of sensing you propose are the ‘over-the-top’ capable ones like I discussed. That excludes about 99% of possible op-amp choices. I mention a specific part that can do this, but for other recommendations you really need to check carefully the op-amp common-mode input range. \$\endgroup\$ Sep 18, 2021 at 15:31
  • \$\begingroup\$ And you still have 10mOhm for sense - too low for the current being sensed. It requires stupidly-high Av to get useful output. Point being, your answer doesn’t address all the issues in OP’s design, and not even the key ones. \$\endgroup\$ Sep 18, 2021 at 15:43
  • \$\begingroup\$ @hacktastical For an op-amp that doesn't support inputs down to GND, one can always connect R1 to an offset voltage rather than GND, or split R1 in half between any stable voltage and ground to make the offset. \$\endgroup\$
    – user4574
    Sep 19, 2021 at 0:06

Realistically, you need something better than what you're working with. tl, dr: you need a better op-amp and a better design. We'll get to that in a moment.

On the other hand you don’t need an instrumentation amplifier, which is a specific setup composed of 3 op-amps (2 followers and one differential) that is used for amplifying high impedance signals. Current sensing using a low-ohm shunt isn’t that.

First, let's touch on what's going wrong now.

I understand the desire to use a low value sense on the low side. You're trying to eliminate the ground shift at your Bluepill. You also want to limit the LM358's input range to its supply rails (and at least than 1.5V below the + rail.) That's a common approach that allows you to use an ordinary op-amp if the gain being asked for isn't large. The LM324/358 is great for that, as long as you understand its limits.

But you have a bit of an XY problem here. Your chosen op-amp quality, the single-ended topology, the low value sense resistor, and the huge gain (Av=2000) you're asking from that op-amp are all conspiring against you and making your life much harder than it needs to be. That LM358's input offset is killing you, swamping the tiny sense voltage you're trying to work with. It’s an old, cheap device not really suitable for precision measurements.

Let's re-frame the approach then. So, five things:

  • Sense on the high side, so no ground shift. Allows the second thing...
  • Use a more realistic sense value scaled for your current (e.g, 2 ohms)
  • Use a differential amplifier, which you have to do with high-side anyway
  • Use lower gain (no more than Av=50) so input offset doesn't kill you
  • Use a better op-amp with less input offset

You could possibly do all this by an op-amp that has "over the top" capability, and construct a classic differential sense circuit. Maxim and Analog make several op-amps that can accommodate common-mode higher than the op-amp V+ rail, like the LT6015 for example.

But... there are excellent specialty amplifiers designed specifically for current sensing: low offset, can be used on either low side and high side, and "over the top" common-mode are all supported.

I've used the LT6105 on the +12V high side with good results. The LT6105 has current-source output, so it's very easy to scale the voltage range to whatever your ADC requires just by changing the load resistor. In your system it could be powered by the Bluepill's supply, by your voltage input, or any handy supply that gives you enough voltage compliance range.

The MAX4173 is billed as 'low cost' and is in an SOT23-6 package, so pretty small, smaller than the LM358 you're contemplating now. Same thing with the power supply, it won't care as it also does "over the top".

There are others, but you get the idea. It's a popular device type.

  • 1
    \$\begingroup\$ could you perhaps elaborate on this :"With this one you can sense on the high side, so you don't inject an offset into the Bluepill's ground." . \$\endgroup\$
    – A.H.Z
    Sep 16, 2021 at 19:53
  • 2
    \$\begingroup\$ @A.H.Z The sense resistor goes on the high-side of the connection, not the low side as you currently show. Then you tap off a differential set of traces (Kelvin connection) to the current-sense amplifier. The CSA will measure the differential voltage and amplify it to a level you can measure with an ADC. \$\endgroup\$
    – BrianB
    Sep 16, 2021 at 19:57

With this small shunt resistor you get tiny voltages, which needs special care to measure. As already mentioned, you need amplifiers with very low offset voltage and drift, e.g. chopper amplifiers like LTC1049 or LTC1050 (I once used these kind for a similar application to measure 400A precisely for a MRT magnet). Measuring such low voltages is possible, but needs to handle thermoelectric effects by carefully controlling temperature gradients and choosing material combinations with low thermoelectric coefficients. Unless measuring currents in the 100 or more amp range, just pick a larger shunt. Choose a resistance which gives you acceptibly power dissipation (e.g. 0.5W) at your maximum current.


The schematic is a well known application of op amps (bipolar supplies). Output voltage negative but can be changed by a classic inverting amplifier. A active virtual ground point can be used for unipolar supply (independant !) for the measurement system.

Proposed also with very low offset op amp GS8333 (?) (not tested, offset simplified) or OP2189.

Shown with all offset cancellation circuit (switch ON, doubled offset circuitry for easy adjustment).

The resistor gain setting is also "doubled". Be carefull twisted inputs cables and ground supplies near negative point of 15 V source. Just like Kelvin connection scheme.

enter image description here

An with the use of a instrumentation op amp AD620 (simulated)

enter image description here


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.