Analog voltage on A0 -A5

I am using an arduino uno and have been able to get multiple voltages on the 6 analog pins. I am having a time trying to figure out the code to add all 6 voltages to get a sum value to display.

A0 = 4.12 A1 = 4.01 A2 = 4.05 A3 = 4.18 A4 = 4.03 A5 = 4.11

Sum = ???

Anyone know the code to add all 6 of these?

You would use “+” operator to sum values. If you need specifics, post the code you have so far. Be sure to enclose it within code tags, use the </> icon or type it like this:

[code] your.code.here [/code]

One way:

#define NUM_ANALOGS     6
int grpinsAnalog[NUM_ANALOGS] = 
{
    A0, A1, A2, A3, A4, A5  
};

void setup( void )
{
    Serial.begin(9600);
    
    for( int i=0; i<NUM_ANALOGS; i++ )
        pinMode( grpinsAnalog[i], INPUT );
    
}//setup

void loop( void )
{
    float
        fSum;

    fSum = 0.0;
    for( int i=0; i<NUM_ANALOGS; i++ )
        fSum = fSum + ((float)analogRead( grpinsAnalog[i] ) * 5.0 / 1023.0);

    Serial.print( "Sum is: " ); Serial.println( fSum, 2 );

    delay(1000);
    
}//loop

So far....

(Code)

int voltS1=A0; //assign voltage on A0 int voltS2=A1; //assign voltage on A1 int voltS3=A2; //assign voltage on A2 int voltS4=A3; //assign voltage on A3 int voltS5=A4; //assign voltage on A4 int voltS6=A5; //assign voltage on A5 int readValue; //readValue Varible float Voltage; //Voltage Varible

void setup() { pinMode(voltS1,INPUT); // voltS1 an input pinMode(voltS2,INPUT); // voltS2 an input pinMode(voltS3,INPUT); // voltS3 an input pinMode(voltS4,INPUT); // voltS4 an input pinMode(voltS5,INPUT); // voltS5 an input pinMode(voltS6,INPUT); // voltS6 an input Serial.begin(9600); //start serial port

}

void loop() { readValue = analogRead(voltS1); // Read voltS1 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("1st Cell Group "); //Print cell number 1S delay(500); //delay 250 ms

readValue = analogRead(voltS2); // Read voltS2 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("2nd Cell Group "); //Print cell number 2S delay(500); //delay 250 ms

readValue = analogRead(voltS3); // Read voltS3 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("3rd Cell Group "); //Print cell number 3S delay(500); //delay 250 ms

readValue = analogRead(voltS4); // Read voltS4 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("4th Cell Group "); //Print cell number 4S delay(500); //delay 250 ms

readValue = analogRead(voltS5); // Read voltS5 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("5th Cell Group "); //Print cell number 5S delay(500); //delay 250 m

readValue = analogRead(voltS6); // Read voltS6 and put value in readValue Voltage = (5./1023.)*readValue; //calculating the real world voltage Serial.println(Voltage); //print out the real world voltage Serial.print("6th Cell Group "); //Print cell number 6S delay(500); //delay 250 m

/(code)

Please use code tags (the </> button in the full editor) when posting code.

The moment you start using numbers in variable names, have a look at arrays. Like used in the example in #2.

For forcing a floating point operation, better use 5.0 instead of 5. for readability. Having that .0 added to one of the two is enough.

Blackfin:
One way:

#define NUM_ANALOGS     6

int grpinsAnalog[NUM_ANALOGS] =
{
   A0, A1, A2, A3, A4, A5  
};

void setup( void )
{
   Serial.begin(9600);
   
   for( int i=0; i<NUM_ANALOGS; i++ )
       pinMode( grpinsAnalog[i], INPUT );
   
}//setup

void loop( void )
{
   float
       fSum;

fSum = 0.0;
   for( int i=0; i<NUM_ANALOGS; i++ )
       fSum = fSum + ((float)analogRead( grpinsAnalog[i] ) * 5.0 / 1023.0);

Serial.print( "Sum is: " ); Serial.println( fSum, 2 );

delay(1000);
   
}//loop

As the OP is a noob, I would think it a bit over the top to “give” him/her a code ready to go, with all the extra “tricks of the trade”
You have used arrays which will be the ultimate way to go, but provide no links or comments as to how your code works or the array statements.

Sorry just constructive criticism, we are trying to teach and help with code, not produce blocks of code that will instantly give the OP what he/she wants.

Tom… :slight_smile:

Hi, To help you, you need to assign different variable names to each analog reading, so this;

 readValue = analogRead(voltS1);  // Read voltS1 and put value in readValue
    Voltage = (5./1023.)*readValue;  //calculating the real world voltage
    Serial.println(Voltage);         //print out the real world voltage
    Serial.print("1st Cell Group  ");              //Print cell number 1S
    delay(500);                      //delay 250 ms
   
    readValue = analogRead(voltS2);  // Read voltS2 and put value in readValue
    Voltage = (5./1023.)*readValue;  //calculating the real world voltage
    Serial.println(Voltage);         //print out the real world voltage
    Serial.print("2nd Cell Group  ");              //Print cell number 2S
    delay(500);                      //delay 250 ms

becomes this;

readValue = analogRead(voltS1);  // Read voltS1 and put value in readValue
float S1Voltage = (5. / 1023.) * readValue; //calculating the real world voltage
Serial.println(S1Voltage);         //print out the real world voltage
Serial.print("1st Cell Group  ");              //Print cell number 1S
delay(500);                      //delay 250 ms

readValue = analogRead(voltS2);  // Read voltS2 and put value in readValue
floaT S2Voltage = (5. / 1023.) * readValue; //calculating the real world voltage
Serial.println(S2Voltage);         //print out the real world voltage
Serial.print("2nd Cell Group  ");              //Print cell number 2S
delay(500);                      //delay 250 ms

And then at the end you put;

float TotalVolts = S1Voltage + S2Voltage + S3Voltage + S4Voltage + S5Voltage + S6Voltage;
Serial.print(" TOTAL BATTERY VOLTAGE = ");
Serial.print(TotalVolts);
Serial.println(" Volts");

You need to edit more of the variable names as I have only for this example changed the first two analog reads.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

@Blackfin, is providing you with a compressed version of what you want to do, but I believe you will learn more by editing your own code, get it working then look at @Blackfin's example.

Tom... :)