I have built an electromagnetic accelerator of which I have successfully used the ADC (A0) of the Arduino GIGA to measure the voltage via a voltage divider. it is accurate to within .01 volts. Currently I have the results of the measurement with the existing code outlined below outputting to my laptop.
I would like to output the results of each voltage measurement to the GIGA display shield instead so that I may see the status of each capacitors voltage on the GIGA display. Currently there will be (5) capacitors I would like to capture the voltage for from the accelerator with a max of about 10 when I am finished. If someone could help me with 2 lines of an output display voltage from 2 capacitors I can repeat the rest in the code as needed. Any help would be appreciated.
/*
* program is used to measure any voltage thru a voltage divider.
*/
const float arduinoVCC = 3.30;//Arduino voltage
unsigned long ValueR1 = 3000;
unsigned long ValueR2 = 19800;
double Voltage_Source = 25;
const int alanogPin = A0;//the pin connecting the voltage.
const int inputResolution =1023;
const float average_of = 500;//Average of 500 readings
float voltage;
void setup() {
Serial.begin(9600);
Serial.println;
delay(500);
}
void loop() {
readVoltage();
Serial.print("Vin: ");
//Serial.print(voltage);
//Serial.print("V Avg: ");
Serial.print(getVoltageAverage());
Serial.println("V");
//delay(100);
}//loop end
/*
* @brief calculates the input voltage and updates the variable "voltage"
* @param none
* @return does not return anything
*/
void readVoltage(){
int A0Value = analogRead(alanogPin);
float voltage_sensed = A0Value * (arduinoVCC / (float)inputResolution);
// Serial.print("voltage_sensed:");
// Serial.print(voltage_sensed);
voltage = voltage_sensed * ( 1 + ( (float) ValueR2 / (float) ValueR1) );
}//readVoltage()
/*
* @brief calculates the average of input voltage and updates the variable "voltage"
* @param none
* @return retuns average of "average_of" iteration of voltage
*/
float getVoltageAverage(){
float voltage_temp_average=0;
for(int i=0; i < average_of; i++)
{
readVoltage();
voltage_temp_average +=voltage;
}
return voltage_temp_average / average_of;
}//getVoltageAverage