Go Down

Topic: Project #3 - Love-O-Meter (Read 11449 times) previous topic - next topic

dzulkiewski

Jan 14, 2014, 05:34 pm Last Edit: Jan 14, 2014, 06:02 pm by dzulkiewski Reason: 1
I am new to Arduino and am working my way through the project book. I am having trouble with the coding from Project #3. I have typed and re-typed the code and still run into the same problem when verifying: 'baseline' was not declared in this scope. I have attached a screen shot of the error. Thanks

AWOL

Posting code is better.
Like the compiler, I can't see "baseline" either.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

Here is the entire code:
const int sensorPin = A0;
const float baselineTemp = 20.0;
void setup (){
  Serial.begin(9600); //open serial port
  for(int pinNumber = 2; pinNumber<5; pinNumber++){
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}
void loop(){
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts:");
  Serial.print(voltage);
  Serial.print(",degrees C:");
  // convert the voltage to temerpature in degrees
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  if(temperature < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }else if(temperature >= baselineTemp+2 &&
    temperature < baseline+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }else if(temperature >=baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }else if(temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
  delay(1);
}
 

AWOL

So, nothing called "baseline", when "baselineTemp" is used everywhere else.

Please use code tags when posting code.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

Sorry, I'm new to all of this, so bare with me. What are code tags and how do I use them and post them? I typed the code word for word from the book and have re-typed it twice with the same results.

AWOL

The clue is
Quote
nothing called "baseline", when "baselineTemp" is used everywhere else.


Quote
so bare with me

Never on a first date.

Code tags are explained here, in bold at the top of just about every section of the forum.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

Code: [Select]
const int sensorPin = A0;
const float baselineTemp = 20.0;
void setup (){
  Serial.begin(9600); //open serial port
  for(int pinNumber = 2; pinNumber<5; pinNumber++){
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}
void loop(){
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts:");
  Serial.print(voltage);
  Serial.print(",degrees C:");
  // convert the voltage to temerpature in degrees
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  if(temperature < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }else if(temperature >= baselineTemp+2 &&
    temperature < baseline+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }else if(temperature >=baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }else if(temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
  delay(1);
}

 

AWOL

Have another look at reply #3.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

I'm sorry I am new to this and very unexperienced, but I have no idea which one is reply 3. Please get right to the point and let me know what I need to do to get help with this.

AWOL

#9
Jan 14, 2014, 08:43 pm Last Edit: Jan 14, 2014, 09:09 pm by AWOL Reason: 1
Quote
but I have no idea which one is reply 3

It's the one on this page labelled "Reply #3"

The clue is also repeated in reply #5.


Further hints:look carefully at these two snippets of code
Code: [Select]
if(temperature >= baselineTemp+2 &&   temperature < baseline+4)and
Code: [Select]
if(temperature >=baselineTemp+4 && temperature < baselineTemp+6){

Notice any similarities?
Notice any glaring differences?

Not surprisingly, I don't have the Arduino starter kit, so I can't verify you copied the code correctly or not.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

I do, thank you for the assistance. That worked

AWOL

OK, thanks for getting back.

Was the code correct in the book, or was there a typo?
If in the book, it should be possible to reach the author and get the correction in for the future.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dzulkiewski

I made the error, the book was correct.
I typed the code twice and must have missed it both times.

dzulkiewski

I have uploaded the code and all 3 lights turn on. I have tried blowing hot air on the sensor and also putting a bag of snow next to the sensor, but all 3 lights remain on. What am I doing wrong?
I found the calibration page on the Arduino website, can I plug that code into the Love-O-Meter code or do I need to calibrate separately?

AWOL

Fine - glad you got it sorted out.

I'm sorry about the oblique pointers to the solution, but software's often like that, and it is useful to develop a different way of thinking, and working around the problem, based on what the tools are telling you.

Like what Indiana Jones said in The Last Crusade, "...and 'X'' never marks the spot" (even though in his case, it did!)

Quote
I have uploaded the code and all 3 lights turn on.

OK, now comes the first tool of debugging - the serial print.
What do they tell you?
(Ignore the lights)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up