INA219 and PWM DC Motor Speed Controller Problem

Hello everyone. Right now I'm working on a project that is using an Arduino Nano, two INA219 sensors, a PWM DC Motor Speed Controller, and OLED as a display. The load that I'm using is a small electrolyzer. I already installed these components on a perfboard.
For better details here you can see here in my diagram:

I'm using the PWM to control my electrolysis power output by varying its voltage. To measure the voltage on the load I put the first sensor on the high side (before the anode), and the second sensor on the low side (after the cathode). Then, I calculate the voltage load by: bus_voltage_ina1 - load_voltage_ina2. For my load current measurement, I averaged both sensors' current. Sometimes I use 3 LED and 3 resistors paralleled as a load to test the sensor's reading.

The problem that I have right now is:

  1. Voltage reading. When I connect PWM with LED load, both voltage reading is stable and accurate. But when I connect PWM and my electrolyzer, the voltage reading on the low side always fluctuates, while on the high side the voltage reading is still stable.
  2. Current reading. Both sensors are not able to read accurately but are stable both on LED load and on my electrolyzer. The error is quite linear; approximately my multimeter shows 20% less current than my sensor.
  3. When I connected my PWM to my electrolyzer, and increase the PWM output (so it outputs more than 400 mA), all my systems immediately freeze. Below 400mA, the system will not freeze. So, when that occurs I have to put my PWM back to 0 output and reset my Arduino to make it run again.

The goal is to make the voltage and current reading accurate again, and also to make my system able to not freeze on high current (3 A). Thank you

I didn't read all your text, I stpppd when you schematic shows the 'load' connected to the inputs of the amplifiers. Something not right there.

If so, what is going to happen?

Does anybody know how to solve these problems? Or if you think there is no solution, at least can you show me where is possibly the mistake that I did, or where the problem lies? Any help will be much appreciated. I'll leave more details if it is necessary. Thank you!

The amplifiers inputs are connected and the only connection shown to your electrolyser. Assuming ideal amplifiers for the moment, then they will not provide or deliver any current to the electrolyser 'load'. In practice there is a very small current flowing (~20uA according to the data sheet).
Disconnecting the amplifiers should therefore make no difference to your circuit. That leaves your electrolyser wholly seperate from the remainder of your circuit. i.e. it is doing nothing and nothing is being done to it.

I did some experiments today. So instead of using two sensors, I tried to use one sensor only and put it either on the high side or the low side. Weirdly, one of them (INA2) was able to work when I put it on the low side; the system didn't freeze, and I could see the voltage and current readings. The other is not, it freezes immediately after I increased the voltage. But as you may agree, connecting my 'load' directly to amplifier inputs will create problems. On the low side, both of my sensors provide erratic readings of voltage and current. Is there something happening on the motor(-) on my PWM? On a multimeter, the measurements are stable and accurate but not on these sensors. Should I put something between my load and sensor input so the amplifier is able to read stably and accurately?

In my experiments too, the sensor current readings were still 20% above my multimeter. What caused this? Should I buy new sensors, or there is something happening on the wires and my solder joints? The cables from sensor inputs to my 'load' somehow provide a voltage drop (0.1-0.15 V) when operating. Can this affect the current readings?

Anyway these are how my perfboard look like:



A motor speed controller is not an amplifier.
And as Spock would have said, trying to measure a PWM signal with a voltmeter and an ammeter is not logical.
Maybe better at the input of the speed controller.

I know it isn't. The PGA is built inside the INA219 sensor.

If I measure at the input, does it mean that I only measure the current consumed by the speed controller? If so, is it true that I only use it to measure input voltage and not my load voltage?

The voltages should be almost the same in and out of the controller. What changes is the relative width of the pulses .
Duty_Cycle_Examples

Yes, of course, but the average voltage and current are not the same, and I think these are the important thing that I want to measure. I don't really care about the maximum voltage/current that the PWM is giving out. By the way, using my multimeter I can repeatedly read the average values despite PWM duty cycles. So do my sensors that were able to read average values when I changed the load to LED with resistors. Also, the voltage and current readings were stable. (But please correct me if I'm wrong). The problem is when I paired up my system with electrolyzer load, the current and voltage was fluctuating, and this is the problem I wanted to solve.

So do the same in your code.
Take many samples, and average them (like the DMM does).

Try to Google "Arduino smoothing code".
Leo..

Hi everyone. I want to know, does this sensor able to measure average voltage and current from PWM signal?

Yes

@goldpepper526

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Thank you, I'll have a look at it.
On other hand, I've been discovering some alternative solutions. On the PWM output, to smoothen the PWM signal, some are using RC low pass filter, and some suggest using DAC. Are these possible in my case?

Three Methods to Filter Noisy Arduino Measurements - Coding - MegunoLink
This is one of many explanations for smoothening noisy signals. I think this can be used for smoothening the PWM too. This can be helpful (if I decided to not add more components to my circuit), but unfortunately, what I've found is my PWM output was pretty noisy, and I think for this case smoothening them won't give accurate results, and doesn't solve the real problem.

Not only your PWM, but everyone else's too.
PWM "noise" is the full 5volt on a Nano.

Did someone already tell you that you shouldn't connect 5volt to V-in of the Nano (post#1).
Leo..

You're right, I should've known that Vin should be 7-12 V but how I did this mistake. Maybe it's luck that somehow the Nano was able to run and had no issues. Thank you for reminding me, soon I'll change my wiring.

Now I realize what I'm doing is stupid. Sorry for this. I'm still new to electronics, but I kind of pretend to myself that I know things. I think these sensors have some kind of inner components so they can read average voltage and current, turns out it can't be done.

On the other hand, I've looked at some solutions on the internet. There is one thing that caught my interest, which is using RC low pass filter on the output. By using this, the PWM signals can be converted to analog voltage. I'm quite sure that if the voltage is steady, my sensors can read it, and this can solve my problem. As a plus, they are cheap, simple and easy to modify. But there are some considerations that I don't understand. Some sources said the value of the resistor and capacitor can't be random values, they have to be designed specifically. My question is on what requirements, and how to do it? Can someone explain this in simple terms?

By the way, this solution I'm offering is not final. If you know another better solution than this, please let me know. Thank you.