I have a program listed below that should control salinity in a small amout of water. I think everything is correct other than my "ctwo" equation all the way at the bottom. I have float point variables because I am dealing with decimals. The result/output of said equation from my arduino is a six figure number, but when I do the calculation manually with the same numbers the arduino uses I get a decimal like I should. I think its probably some kind of syntax that I have wrong, but I have no clue what to fix. Any help would be appreciated. The equation can be found all the way at the bottom of my program; the equation is "ctwo = (cone+(SP-cone)*G)"
unsigned long time;
unsigned long basetime;
int G = 80; //gain
int OF = 15; //overflow from DI or salty tank
float m = 3.986; //mass of water in tank
int deadtime = 7000;
float sp = 0.1; //real set point %
float spa = 0.100; //set point concentration analog value
float UCL = 0.108; //upper control limit
float LCL = 0.092; //lower control limit
float ctwo; //C2
float cone; //C1
float x; //mass of DI or salty water to add
int t; //time valve is left open
float FR = 9.2; //flow ratevoid setup () {
pinMode(11, OUTPUT); //DI valve
pinMode(12, OUTPUT); //salty valve
pinMode(10, OUTPUT);
Serial.begin(9600);
pinMode(1, OUTPUT); //serial port
Serial.print(12, BYTE);
Serial.print(17, BYTE); //Turn Backlight On
Serial.print(129, BYTE);
Serial.print("LCL");
Serial.print(136, BYTE);
Serial.print("SP");
Serial.print(143, BYTE);
Serial.print("UCL");
Serial.print(148, BYTE);
Serial.print(LCL, 3);
Serial.print(155, BYTE);
Serial.print(spa, 3);
Serial.print(162, BYTE);
Serial.print(UCL, 3);
Serial.print(169, BYTE);
Serial.print("off");
Serial.print(183, BYTE);
Serial.print("off");
Serial.print(188, BYTE);
Serial.print("salty");
Serial.print(194, BYTE);
Serial.print("current");
Serial.print(203, BYTE);
Serial.print("DI");
}void loop () {
basetime = millis(); //sets base time
digitalWrite(10, HIGH); //turns on conductivity sensor for 0.1s
delay(100);
int val = analogRead(0); //reads conductivity sensor value
digitalWrite(10, LOW); //turns off conductivity sensor for 1 s
delay(1000);
cone = ((2.0953E-32)*(pow(val, 11.1792)));
Serial.print(175, BYTE);
Serial.print(cone, 3);
if (cone > sp && (basetime-time > deadtime)) { aboveuppercontrol (); }
if( cone < sp && (basetime-time > deadtime)) {belowlowercontrol (); }
else {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
}void aboveuppercontrol () { //program for above UCL
ctwo = (cone-(cone-SP)G);
x = (m(cone-ctwo))/((1-OF)cone);
t = 1000(x/FR);
Serial.print(183, BYTE);
Serial.print("ON ");
digitalWrite(11, HIGH);
delay(t);
digitalWrite(11, LOW);
time = millis();}
void belowlowercontrol () { //program for below LCL
ctwo = (cone+((SP-cone)G)); //problematic: yields six digit number, should be small decimal
x = (m(cone-ctwo))/((OF-100)+cone*(100-OF));
t = ((1000*x)/(FR));
Serial.print(169, BYTE);
Serial.print("on ");
digitalWrite(12, HIGH);
delay(t);
digitalWrite(12, LOW);
delay(10);
Serial.print(169, BYTE);
Serial.print("off");
time = millis();}