How we can apply the method in real life


You need to explain each code and how we can apply the method in real life.

The main purpose for this code : is to charge up the six cells in the battery which means six outputs each with 5 voltage, and these outputs will be the six cells battery which is going to be charged in order from the lowest to the highest (lowest voltage first).

Explanation of Arduino Code:

The code is written in different step. The data is read from the analogue pins of the Arduino uno. There are four functions in the code

1. Update data:

In this function the data is updated from the batteries. The data here is in the form of digital number and is on 0-1024 scale. We need to convert this raw data to voltage to perform the further operation that is done by the following function.

2. Calculate_voltage:

The voltage is calculated using the formula told. The voltage is scaled to 0-5V scale.

3. Sort Array:

The array is sorted in the ascending order using the bubble sort array algorithm. The minimum value is sorted to the above of the array.

4. Findmin:

The minimum value is found using the if and else conditions.

5. Loop function:

This function keeps on repeating it repeatedly. Here the case and switch structure is used to turn on the charging point .

constint cell1Pin = A0;
constint cell2Pin = A1;
constint cell3Pin = A2;
constint cell4pin = A3;
constint cell5pin = A4;
constint cell6pin = A5;
float array1[6],array[6]={0};
float swap;
intmin_index=0;
constint chargepin1 = 8;
constint chargepin2 = 9;
constint chargepin3 = 10;
constint chargepin4 = 11;
constint chargepin5 = 12;
constint chargepin6 = 13;
void setup() {
pinMode(chargepin1, OUTPUT);
pinMode(chargepin2, OUTPUT);
pinMode(chargepin3, OUTPUT);
pinMode(chargepin4, OUTPUT);
pinMode(chargepin5, OUTPUT);
pinMode(chargepin6, OUTPUT);

}
voidsortarray()
{
for (int c = 0 ; c<(6-1) ; c++)
{
for ( int d=0 ; d<(6-c-1) ; d++)
{
if ( array[d] > array[d+1] )
{ swap = array[d];
array[d] = array [d+1];
array[d+1] = swap;

}
}
}
}
voidupdate_data()
{
array1[0]=array[0]=analogRead(A0);
array1[1]=array[1]=analogRead(A1);
array1[2]=array[2]=analogRead(A2);
array1[3]=array[3]=analogRead(A3);
array1[4]=array[4]=analogRead(A4);
array1[5]=array[5]=analogRead(A5);

}

voidfindmin()
{
for (int q=0;q<6;q++)
{
if(array[0]=array1[q])
{
min_index=q;
}
}
}
voidcalculate_voltage()
{
for(int y=0;y<6;y++)
{
array1[y]=array[y]=array[y]*(5.0/1023.0);

}
}
void loop() {
delay(1000);
update_data();
calculate_voltage();
sortarray();
findmin();
switch (min_index) {
case 0:
digitalWrite(chargepin1,HIGH);
digitalWrite(chargepin2,LOW);
digitalWrite(chargepin3,LOW);
digitalWrite(chargepin4,LOW);
digitalWrite(chargepin5,LOW);
digitalWrite(chargepin6,LOW);
break;

case 1:
digitalWrite(chargepin2,HIGH);
digitalWrite(chargepin1,LOW);
digitalWrite(chargepin3,LOW);
digitalWrite(chargepin4,LOW);
digitalWrite(chargepin5,LOW);
digitalWrite(chargepin6,LOW);
break;
case 2:
digitalWrite(chargepin3,HIGH);
digitalWrite(chargepin1,LOW);
digitalWrite(chargepin2,LOW);
digitalWrite(chargepin4,LOW);
digitalWrite(chargepin5,LOW);
digitalWrite(chargepin6,LOW);
break;
case 3:
digitalWrite(chargepin4,HIGH);
digitalWrite(chargepin1,LOW);
digitalWrite(chargepin2,LOW);
digitalWrite(chargepin3,LOW);
digitalWrite(chargepin5,LOW);
digitalWrite(chargepin6,LOW);
break;

case 4:
digitalWrite(chargepin5,HIGH);
digitalWrite(chargepin1,LOW);
digitalWrite(chargepin2,LOW);
digitalWrite(chargepin3,LOW);
digitalWrite(chargepin4,LOW);
digitalWrite(chargepin6,LOW);
break;

case 5:
digitalWrite(chargepin6,HIGH);
digitalWrite(chargepin1,LOW);
digitalWrite(chargepin2,LOW);
digitalWrite(chargepin3,LOW);
digitalWrite(chargepin4,LOW);
digitalWrite(chargepin5,LOW);
break;
}
}

Request for Solution File

Ask an Expert for Answer!!
Other Subject: How we can apply the method in real life
Reference No:- TGS01426977

Expected delivery within 24 Hours