I'm using a power source to measure the voltage and current at two of the analog inputs. The problem with this code is that its measuring the wrong current values. If one of the inputs is 5V then the current should be within the mili Amps. Instead its monitoring within 1-3Amps. I can't seem to see the problem with this code. This will be used to measure the current and voltage produced from a wind turbine to monitor the power. I'm using the Arduino Mega.
int analogPin = A0; //measure pin 0
int analogPin1 = A1; //measure pin 1
int val0 = 0; //variable to store the read value of Pin 0
int val1 = 0; //variable to store the read value of Pin 1
double Vout0;
double Current1;
double I;
double P;
double C = 204.6; //constant value divider (5/1023) (ex 5V = 1023 serial monitor reading)
void setup ()
{
}
void loop()
{
val0 = analogRead(A0); //read the value of Pin 0
val1 = analogRead(A1); //read the value of Pin 1
Serial.begin(9600); //initialize the input on analog pin 0 and 1;
//print out the value read:
Vout0 = val0/C;
Current1 = val1/C;
I = Current1; //current from pin A1
P = Vout0 * I;
Serial.print("Volts = ");
Serial.println(Vout0); //printout voltage in serial monitor
Serial.print("Amps = ");
Serial.println(I); //printout amps in serial monitor
Serial.print("Power = ");
Serial.println(P); //printout power in serial monitor
Serial.println("===============================================");
Analog input pins don't measure current directly. There must be some external circuitry that is converting and scales some specific DC current range to the arduino 0-5vdc input range. Until you show us that circuitry and details it's hard to help you with your problem.
You are converting val1 by dividing it with the same constant as you use to convert val0 to volts.
It's very unlikely that they'll be the same. What is the full-scale current range on pin A1?
I'm using a power source to measure the voltage and current at two of the analog inputs
I can't even understand what you mean by this..... "a power source" is what, exactly ?
To measure the voltage at the analog input, you use ... the analog input. That's what it does.
The current should be negligible, because the analog input has quite a high impedance.
lvergara21, what is your status with this at the moment?
I notice you have in your main() the Serial.begin(9600).
Normally you do this only once, so the best place for that is in your Setup().
el_supremo is correct, you will most likely not be using the same scale factor value for both reading volts as current.
Also, where in the wind turbine circuit are you making the measurement, AC or DC side?
How are you measuring the current that you want to read from the wind turbine?
Typically, it is one of two methods, either a standard current shunt bar with an op-amp to bring up the mV to a higher value.
Or, secondly, a hall effect chip like the ACS712?