Hi, so I'm building a water temperature measuring device for a school project and I'm trying to combine 2 pre existing pieces of code and I've gotten to a point where no matter what I do I cannot seem to get passed this one line (17) I've spent now 2 days looking for help and I finally decided to come to this forums page.
Here is my code
const int hot = 87; //set hot parameter
const int cold = 75; //set cold parameter
void setup() {
pinMode(A0, INPUT); //ThermistorPin
pinMode(2, OUTPUT); //blue
pinMode(3, OUTPUT); //green
pinMode(4, OUTPUT); //red
Serial.begin(9600);
}
void loop() {
int ThermistorPin = analogRead(A0);
int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
A0 = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T = T - 273.15;
T = (T * 9.0)/ 5.0 + 32.0;
Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" F");
if (tempF < cold) { //cold
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
Serial.println(" It's Cold.");
}
else if (tempF >= hot) { //hot
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
Serial.println(" It's Hot.");
}
else { //fine
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
Serial.println(" It's Fine.");
delay(500);
}
Here is the error message that popped up with it
C:\Users\DRAGON~1\AppData\Local\Temp\arduino_modified_sketch_585364\Digital_Inputs.ino: In function 'void loop()':
Digital_Inputs:17:32: error: assignment of read-only variable 'A0'
A0 = analogRead(ThermistorPin);
^
Digital_Inputs:28:5: error: 'tempF' was not declared in this scope
if (tempF < cold) { //cold
^~~~~
C:\Users\DRAGON~1\AppData\Local\Temp\arduino_modified_sketch_585364\Digital_Inputs.ino:28:5: note: suggested alternative: 'memcpy'
if (tempF < cold) { //cold
^~~~~
memcpy
Digital_Inputs:46:1: error: expected '}' at end of input
}
^
exit status 1
assignment of read-only variable 'A0'
If there is nothing you can do with this can you at least help me get going in the right direction? Thank you for taking the time to read this.