Dear all.
I am trying to upload below 2 code. Here below code compile properly. But Code i have attached in Rar file giving me error.
I have just seprated variable & declare globally.Let me Know what mistake i am doing here.
const int num_readings = 10;
float offSet = 2.44009;
const int mad = 2.24;
int readings[num_readings];
int index = 0;
float sample2SolCrnt = 0.0;
float solar_crnt = 0.0; // Solar panel current variable
float solarCrntVal = 0.0; // Current callibration variable
float current;
#define RELAY1 3
void setup() {
// sets the serial port to 9600
Serial.begin(9600);
pinMode(RELAY1, OUTPUT);
}
int average() {
int total = 0;
for(int i=0; i<num_readings; i++)
total = total + readings[i];
return total/num_readings;
}
float standard_deviation(int avg) {
int total = 0;
for(int i=0; i<num_readings; i++)
total = total + pow((avg - readings[i]), 2);
return sqrt(total/num_readings);
}
void loop() {
float sum=0.0;
// read analog input pin 0
int reading = analogRead(A0);
readings[index] = reading;
// incrementing the index
index = index + 1;
// if have already been done 10 readings...
if (index >= num_readings) {
// set the index to 0
index = 0;
// compute the average
int avg = average();
// compute the standard deviation
float std = standard_deviation(avg);
float madstd = mad * std;
float lowlimit = avg - madstd;
float highlimit = avg + madstd;
int count = 0;
int total = 0;
for(int i=0; i<num_readings; i++) {
// Check if the values of the readings are within the limits.
if(readings[i] >= lowlimit && readings[i] <= highlimit) {
total = total + readings[i];
count = count + 1;
}
}
// compute the new average
int newaverage = total/count;
// send it to the serial port (as ASCII digits)
Serial.println(newaverage, DEC);
// sum=sum+(.0264 *newaverage -13.51);
// float current= 0.0264*(newaverage-512);
//float current=0.0264*(newaverage-518);
current = 0.0336666666667*newaverage - 17.17;
Serial.print("current is :");
Serial.println(current);
}
if(current>1.0)
{
digitalWrite(RELAY1,LOW);
Serial.println("relay got tripped");
}else
{
digitalWrite(RELAY1,HIGH);
Serial.println("relay not tripped");
}
Serial.println(".....................");
delay(1000);
// wait 1000/num_readings ms for next reading
//delay(int(1000/num_readings));
}
ACS712_Modified.rar (1.1 KB)
