# Current Shunt With Arduino

Hello, I have a question in the hopes to get some help.

I am working on a little rig to measure current from a motor and see it on arduino serial monitor (eventually excel which I know how to do already).

The way I have been doing it is the following:

• Using a current shunt to lower the current to a small mV value so that I don't break things (lol). My shunt is at a max rating of 10A (100mV max).
• The output of the shunt goes into a ad623 amplifier which I setup to get a 10x gain(because the mV would be too small to get good readings into Arduino).

The amplifier is giving me a proper gain when measured with a multimeter, but when i try using the arduino the readings are ridiculous. For example, when I run the motor I get like 400, 200, then 0,0,0,0,0,0 then 400, 200, 0,0,0,0. Any ideas? The amplified voltage should definitely be high enough so that it gives a proper value to the arduino analog input. My code should be fine as well.

All help appreciated.

Thanks!

Using a current shunt to lower the current to a small mV

Current is not messured is volts! Explain what you are really doing. Circuit diagram and links to the parts you are using would help as would posting your code.

Mark

Sorry, @holmes64, but with a shunt it is. The shunt is a very low resistance and the current is calculated using Ohms law from the voltage measured across the shunt.

@granosx, rig up some temporary arrangement to enable you to put different constant currents through the shunt and see what measurements the Arduino produces compared to your multimeter.

How have you the Arduino configured? What voltage reference are you using? How often are you taking readings? Post your code.

…R

I gather that is NOT an AC motor.

Have you considered using one of these ? (SEE ATTACHED)
https://learn.sparkfun.com/tutorials/ina169-breakout-board-hookup-guide/introduction

Can we get some Electrical Specs for the motor (a datasheet or link to it would be better)
Motor Type ?
Motor Power Supply voltage ?
Motor current ? (Presumably you can’t use a meter to measure this ?)

INA169_Breakout.pdf (73.3 KB)

Robin2: Sorry, @holmes64, but with a shunt it is. The shunt is a very low resistance and the current is calculated using Ohms law from the voltage measured across the shunt.

@granosx, rig up some temporary arrangement to enable you to put different constant currents through the shunt and see what measurements the Arduino produces compared to your multimeter.

How have you the Arduino configured? What voltage reference are you using? How often are you taking readings? Post your code.

...R

That is an excellent idea! I will rig something up tomorrow and report.As far as configuration goes, I'm using an Arduino Uno, analog input pin, and seeing what value I get through analogRead before I even start to scale down the value to give a real current value. As for my code, It's basic right now, I will post it tomorrow as its on another computer I don't have access to right now. But its just reading from the analog pin.

@lar3ry: It is a DC motor.

@raschemel: I have to find the datasheet, but the supply voltage is 100 volts DC. I cannot recall how much current it runs with I will report with that info tomorrow. I think it was about .2 amps, I will check the data sheet.

Update:

So I decided to take a step back.

I set the arduino voltage reference to 1.1v in the hopes that maybe I can get a reading without needing the amplifier.

My multimeter tells me the reading should be high enough for the arduino to read. However I am having the same issue as before, I will get a reading for 1 second then 0 for a few seconds then a reading and rinse and repeat.

I wonder what it could be.

As far as data sheet for the motor goes:

http://www.johnsonmotor.com/en/products/dc-motors/standard-dc-motors/high-voltage-dc-motors/datasheets/DC781-2-LSG-020-metric.pdf

Don't bring in the complication of a motor until you are sure you can read steady currents reliably.

...R

As far as data sheet for the motor goes:

I see in the datasheet, the input voltage is listed as 100.0 V DC, Rectified, 60 Hz. What sort of power supply are you using for the motor? Fullwave rectified? Half-wave? Filtered/smoothed?

If it's a pulsating DC, you could get the symptoms you are seeing, as the voltage you read depends where, in the cycle, you sample with the analogRead().

I would suggest (as an addition to Robin2's suggestion), a simple sketch that does an analogRead() of the pin, followed by a Serial.println() of the variable you read into, a delay(500), and nothing else.

Then, attach a potentiometer to the analog pin, (ends to 5V and GND, center tap to analog pin), then vary it to ensure you can see the levels change. Only then, attach and start to work on the current sensor.

It also might help if you post your code.

lar3ry:

As far as data sheet for the motor goes:

I see in the datasheet, the input voltage is listed as 100.0 V DC, Rectified, 60 Hz. What sort of power supply are you using for the motor? Fullwave rectified? Half-wave? Filtered/smoothed?

If it's a pulsating DC, you could get the symptoms you are seeing, as the voltage you read depends where, in the cycle, you sample with the analogRead().

I would suggest (as an addition to Robin2's suggestion), a simple sketch that does an analogRead() of the pin, followed by a Serial.println() of the variable you read into, a delay(500), and nothing else.

Then, attach a potentiometer to the analog pin, (ends to 5V and GND, center tap to analog pin), then vary it to ensure you can see the levels change. Only then, attach and start to work on the current sensor.

It also might help if you post your code.

I am using a power supply that it came with. It was originally a product I took apart. The supply plugs into a power outlet and gives a full wave rectified source. On a random note, per the AC warnings I did try using a DC power supply and at some point it was working perfectly fine (into arduino) but I cannot for the life of me get back to that result after trying with the rectified signal again.

Currently I am just using a code to get an analog reading with a few points of precision ( decimal places ).

" void setup() {

Serial.begin(9600); analogReference(INTERNAL); // 1.1V Ref

}

void loop() {

int sensorValue = analogRead(A1); double vShunt = sensorValue * (1.1 / 1023.0);

Serial.print(sensorValue); Serial.print(" , "); Serial.println(vShunt,8); delay(1000);

}"

Again, I have no trouble amplifying the shunt output(in mV) with my ad623an amplifier whether I use a dc power supply or the rectified signal, and in fact the multimeter readings match with both methods. It's just when it comes to the arduino that I have problems. Maybe potential difference could be an issue? Or maybe even the fact that one of the signals is rectified and not just DC?

I will try playing with the potentiometer, I guess thats just a test to make sure the board isn't busted? Luckily I do have a bunch of boards (uno, mini, nano etc..).

Thanks in advance, I appreciate all the help.

EDIT: The potentiometer works fine. Hmm..

If your amplifier is giving output voltages between 0 and 1 volt its hard to understand how the Arduino ADC is not reading them. I am really thinking of something in the region of 0.5 volts for testing. What is the output impedance of the amplifier? The Arduino ADC likes it to be 10k or less.

Have you tried making a simple voltage divider with a potentiometer that gives similar votages and testing whether the Arduino ADC can read those voltages correctly?

I think you need to show us a diagram of how you have everything wired up. A photo of a clear pencil sketch will be fine.

...R

Robin2: If your amplifier is giving output voltages between 0 and 1 volt its hard to understand how the Arduino ADC is not reading them. I am really thinking of something in the region of 0.5 volts for testing. What is the output impedance of the amplifier? The Arduino ADC likes it to be 10k or less.

Have you tried making a simple voltage divider with a potentiometer that gives similar votages and testing whether the Arduino ADC can read those voltages correctly?

I think you need to show us a diagram of how you have everything wired up. A photo of a clear pencil sketch will be fine. ...R

That is a really good idea, I will try out the divider and see how arduino behaves. Sure, I will see if I can make a little sketch later today.

Thank you.

EDIT: Voltage divider method also works fine and the arduino can read pretty low values.

Here is a sloppily drawn (my handwriting sucks) sketch of my setup.

The 11k resistor is used to get a gain of about 10 ( the resistor value there will change the gain, and no resistor sets the gain to 1 ).

The amplifier is an ad623an instrumentation amplifier.

PS: Right clicking the attachment and clicking view image should make it easier to see the schematic.

You have not said whether the shunt and amplifier work with a steady current.

Edit to add ... I'm out of my depth here, and this may be nonsense, but it is something I would try.

Looking at the AD623 data sheet it mentions load impedances of 10k and 100k but doesn't quote the device output impedance and it doesn't say anything about the sort of impedance it should or should not be connected to. The Arduino ADC has a very high input impedance. I wonder would there be any improvement if you connect a 10k (or 100k) resistor between the AD623 output and ground?

...R

Robin2: I don't know anything about your amplifier and I don't see anything wrong with your connections.

You have not said whether the shunt and amplifier work with a steady current.

Edit to add ... I'm out of my depth here, and this may be nonsense, but it is something I would try.

Looking at the AD623 data sheet it mentions load impedances of 10k and 100k but doesn't quote the device output impedance and it doesn't say anything about the sort of impedance it should or should not be connected to. The Arduino ADC has a very high input impedance. I wonder would there be any improvement if you connect a 10k (or 100k) resistor between the AD623 output and ground?

...R

Hey, thanks for the suggestions.

I did try adding a 100k resistor and it has no change to the arduino readings, in other words I am still getting a a cycle of a few values then 0 , few values, 0.

I still wonder about the power supply. Here’s a little sketch to test it (I assume you do not have an oscilloscope). If it’s full-wave rectified, I would expect to see approximately 8 “peaks” in the 64 samples if it’s unfiltered. You can change the number of samples to 80 if your mains voltage is 50 Hz.

``````int readings[64];

void setup() {
Serial.begin(115200);
}

void loop() {
for (int i = 0; i < 64; i++) {
delay(1);
}
for (int i = 0; i < 64; i++) {
}
while (1) {}
}
``````

granosx:
I am still getting a a cycle of a few values then 0 , few values, 0.

Is this happening with a constant current and without the motor connected (or at least without the motor turning)?

Are the values correct (even if the 0 isn’t)?

…R

lar3ry:
I still wonder about the power supply. Here’s a little sketch to test it (I assume you do not have an oscilloscope). If it’s full-wave rectified, I would expect to see approximately 8 “peaks” in the 64 samples if it’s unfiltered. You can change the number of samples to 80 if your mains voltage is 50 Hz.

``````int readings[64];
``````

void setup() {
Serial.begin(115200);
}

void loop() {
for (int i = 0; i < 64; i++) {
delay(1);
}
for (int i = 0; i < 64; i++) {
}
while (1) {}
}

I will try this shortly.

The values are definitely wrong. Not to mention that even with the motor turned off the readings are like this.

edit: I used your code above to see how it behaves and its a very similar output. I added a line to make the voltage reference 1.1v by the way.

“2
0
0
0
5
0
0
0
0
0
0
5
0
0
0
0
0
0
0
6
0
0
0
0
0
0
5
0
0
0
0
0
0
0
6
0
0
0
0
0
0
7
0
0
0
0
0
0
0
5
0
0
0
0
0
0
6
0
0
0
0
0
0
0”

This is driving me nuts ; ;

Multimeter readings are stable as well (shunt outputs about 1.5mV which translates to .15 amps).

granosx:
Multimeter readings are stable as well (shunt outputs about 1.5mV which translates to .15 amps).

You seem to have a wonderful ability to NOT provide useful information. When the shunt is outputting a steady (?) 1.5mV what voltage is the amplifier presenting to the Arduino ADC?

If you are multiplying by 10 it should be 15 mV, which (I think) should give a an ADC output of about 13 or 14 with the 1.1v internal reference.

You said earlier that the ADC reads correctly from a potentiometer. That strongly suggests that the problem has to do with your amplifier. Try a different amplifier (even if it isn’t precise) just to see what happens.

Can you describe what you are doing to get the 0.15 amps current through the shunt?

And what is the time interval between the readings you have listed?

…R

Robin2, I was under the impresion the ADC resolution was 5V/1023=4.8mV per ADC count. So 15mV would only be 3 counts and is NO WHERE NEAR HIGH ENOUGH amplitude to use the arduino ADC. If the OP can't increase the gain he needs to add a second AMP stage to boost the signal by a factor of 100 to get it to 1.5V. Using an arduino ADC to measure a 15mV signal is just a waste of time. I don't know if my math is right about the ADC but I am pretty sure that the signal the OP is trying to measure is too low by a factor of 100. In addition , he would probably do better to have a voltage follower op amp on the front end. I thought his current shunt breakout had programmable gain. Why isn't he using it ?