Performing calculations with variables

float Csp=0;
float C1=0;
float C2=0;
float G=0;
float OF=0;
float m=0;
float X=0;
float X1=0;
float FR=0;
float t=0;
float t1=0;
float val=0;
float val1=0;
float val2=0;
float analogPin=3;
float C3=0;

void setup() {
Serial.begin(9600);
pinMode(1,OUTPUT);
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(3, OUTPUT);
Serial.print(12, BYTE);
Serial.print(129,BYTE);
Serial.print("LCL");
Serial.print(148,BYTE);
Serial.print("0.09");
Serial.print(136,BYTE);
Serial.print("SP");
Serial.print(155, BYTE);
Serial.print("0.1");
Serial.print(143, BYTE);
Serial.print("UCL");
Serial.print(162, BYTE);
Serial.print("0.11");
Serial.print(188, BYTE);
Serial.print("Salty");
Serial.print(194, BYTE);
Serial.print(203, BYTE);
Serial.print("DI");
Serial.print(22,BYTE);
}

void loop(){
digitalWrite(4, HIGH);
delay(1000);
float (val=0);
float (val2=0);
float (val1=0);
float (Csp=0);
float (C1=0);
float (G=0);
float (C2=0);
float (X=0);
float (X1=0);
float (m=0);
float (OF=0);
float (t=0);
float (FR=0);
float (t1=0);
float (t=0);
float (m=0);
float (C3=0);
digitalWrite(4, LOW);
val=(analogRead(analogPin));
m=79.1;
FR=9.25;
OF=.15;
Csp=.1;
C1=((.0006*(pow(val,.8133))));
G=.7;
C2=(C1+(Csp-C1)G);
C3=(C1-(Csp-C1)G);
X=((m
(C2-C1))/((1-OF)
(.01-C1)));
X1=((m*(C1-C3))/((1-OF)(C1)));
t=((60
(X/FR))1000);
t1=((60
(X1/FR))1000);
val2=(pow(val, .8133)
.0006);
Serial.print(174, BYTE);
Serial.print(val2,4);
delay(1000);
if (val2<.09){
digitalWrite(7, HIGH);
delay(t);
digitalWrite(7, LOW);
Serial.print(169, BYTE);
Serial.print("ON");
Serial.print(182, BYTE);
Serial.print("OFF");
delay(8500);
}
if (val2>.11){
digitalWrite(8, HIGH);
delay(t1);
digitalWrite(8, LOW);
Serial.print(182, BYTE);
Serial.print("ON");
Serial.print(169, BYTE);
Serial.print("OFF");
delay(8500);
}

}

This is my code. It's supposed to control the salinity of water in a tank, but val2 is showing up as 0. val2 is the variable I used for % weight of salt in the water. val is the analog value from the conductivity sensor. The equation I used (.0006(val)^.8133) comes from a calculation in excel. Did I enter that equation wrong? Do I have to do something else in order to used the pow() function? Help please.

All floats should be initialized as 0.0 and not 0.

Have you confirmed that the analog sensor works?

float analogPin=3;

...using a float for a pin number is a bad idea. Change the declaration to this...

const int analogPin=3;

@ Senso: by an amazing ( four billion to one!) coincidence of IEEE 754 excess 127 floating point , the integer and float representations of zero are identical right down to the bit level, and better still, are also completely endian-agnostic.

Anyway, all those global floats would have been initialised to zero, even if they had not been explicitly assigned the value.

Oh yeah, and what Coding Badly said, with a side-order of using the # icon when posting code.

I have worked with a strange PIC compiler that spited out all sorts of errors if all floats where not initialized to 0.0 0 wont cut it for some reason.

Yet another reason to be grateful we're not using PICs.
:smiley: