I need some help. I can’t understand why it's not printing out any value beside 0 on my serial monitor. So I use a Shunt resistor that has the resolution of 75mV for 50A. why the analog pin can't be read when connected to a resistor shunt? the data just reads 0 only...
The real problem is, when I convert this number to Amps, I always get 0.
amps = sensor_value *(5/1024) * (300/0.05)
by doing hand calculations, this formula gets me a value that make sense. Can somebody explain to me why I always get 0 at Serial.println(amps).
Please edit your post and place your code inside the code tag. It's a button on the bar that looks like this </>
Then, try what @chrisknightley said because it's correct. You are performing integer division.
I need some help. I can’t understand why it's not printing out any value beside 0 on my serial monitor. So I use a Shunt resistor that has the resolution of 75mV for 50A. why the analog pin can't be read when connected to a resistor shunt? the data just reads 0 only...
The real problem is, when I convert this number to Amps, I always get 0.
by doing hand calculations, this formula gets me a value that make sense. Can somebody explain to me why I always get 0 at Serial.println(amps).
Can you tell us what current you are passing through your shunt resistor?
The Uno has a 10 bit A/D so each bit is 5V/1024 =~ 5 mv.
With a 75mv/50 amp shunt, 5mv is approx 3.5 Amps.
You can lower the range of the A/D by specifying the internal ref ~ 1.1 volts
this will make each step of the A/D ~ 1mv so you will not be able to detect < 0.7Amps
When I have to troubleshoot an issue like this, I output the RAW A/D converter value.
Is the result of analogRead(A3) always zero, or is the outcome of your calculation in post #1 already zero regardless of the reading of A3? It's not clear from your post.
Did you in fact look at this? You didn't respond, but it's a relevant remark.
This is not a schematic of your setup. I know this because (1) you state above you use A3, and (2) there's no Arduino in the picture and no power supply for it; long story short: a COMPLETE schematic, please.
One more thing: in theory there's nothing wrong with having an Arduino directly measure the voltage over a shunt resistor. But personally I think it's kind of tricky to directly connect an Arduino to what is apparently a piece of high-power electronics without any apparent interfacing or protection.
Alright, actually one more thing still: you mention a "resolution" (wrong term!) of 75mV for 50A. But what is the actual range that you need to measure, and at what resolution? I.e. the 4.88mV step size of the Arduino, corresponding to a 3.3A step size as @chrisknightley pointed out, is that sufficient? It's a very low resolution measurement you're performing.
Frankly, this all sounds very haphazard to me. Hence the emphasis on providing a good and complete schematic so that the people here can give you some advice on how to go about this effectively and safely.