Pages: [1] 2   Go Down
Author Topic: Project #3 - Love-O-Meter  (Read 2095 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* Baseline.PNG (53.96 KB, 514x608 - viewed 64 times.)
« Last Edit: January 14, 2014, 12:02:47 pm by dzulkiewski » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Posting code is better.
Like the compiler, I can't see "baseline" either.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
 
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Please use code tags when posting code.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
 
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have another look at reply #3.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if(temperature >= baselineTemp+2 &&   temperature < baseline+4)
and
Code:
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.
« Last Edit: January 14, 2014, 03:09:05 pm by AWOL » Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do, thank you for the assistance. That worked
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 15
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

"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.

Pages: [1] 2   Go Up
Jump to: