Hi everyone, This is the first time for me to use an arduino. I am doing a small project on making a some sort of data logger, which will be measuring voltage and current with varies load resistance and calculate the power. I have been wondering around the internet, but it seems that the resources can't resolve my problem.
while(inByte=='s'){
analogWrite(lampPin, 191);
Measurement();
digitalWrite(rledPin, LOW);
digitalWrite(gledPin, HIGH);
}
}
}
void Measurement() {
int VoltageSensor = analogRead(A0);
int CurrentSensor = analogRead(A1);
float voltage = VoltageSensor* (5.0 / 1023.0);
float current = CurrentSensor* (5.0 / 153603.5);
float power = voltage* current;
Serial.print(voltage, 5);
Serial.print('\t');
Serial.print(current, 5);
Serial.print('\t');
Serial.print(power, 5);
Serial.println();
delay(1000);
}
How do I tell arduino stop when the maximum power is reached?
My idea is like :
- if nowPower>prevPower, keep reading
- if prevPower>nowPower, stop reading, prevPower=maxPower
- Serial.print(maxPower)
Not sure how to do it exactly, and one last thing, in my sketch when I press 's' in the monitor, it will start measuring, the problem is I don't know how to break the while loop, I have tried to use delay and break, they didn't seem to work, maybe I have done something wrong.
Please help