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

The lights tell me if the temp is above or below the baseline
Logged

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

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.

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

Who is they?
Logged

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

This stuff
Code:
int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);
isn't there for decoration.
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: 16
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm brand new to this, so I apologize for my lack of knowledge, but I have no idea what you are getting at. I see the line of code on my screen. What are you trying to point out? Is there something I am supposed to change?
Logged

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

What I'm pointing out is that the sketch has a built-in mechanism for reporting the actual values read from the sensor.
This is what you should be looking at, not the lights.
This will help indicate whether you have your sensor wired correctly and if it is working as expected.
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: 16
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you.
I have it working now (wire was not pushed all the way in on the bread board).
Logged

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

That's one of the other things about debugging - use as many different approaches as you can to examine the problem or its symptoms, but make sure you understand the limitations of each method.
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: 16
High School Teacher - Design & Technology Education Bloomfield Hills Schools Bloomfield Hills, MI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I appreciate the input
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Could you explain to me why do we have to remove -0,5 to convert the voltage temperature, I don't understand why it's neceesary to create an offset.

Thanks in advance ;-)
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you open the serial monitor you will see the value being returned from the temperature sensor,  go to line two of your code -"const float baselineTemp = 20.0;" and change the 20.0 to the value shown in the serial monitor. This will calibrate your program correctly.

If you want the code to calibrate itself simply remove the "const" from line 2 and ad the line "baselineTemp = analogRead(sensorPin);" to your setup void. This will record the initial value returned from the sensor and use that as your base line. Since you will be doing this in the setup void it will happen only once each time the arduino is reset or turned on.

Another option is to add a push button to your setup and add the appropriate code to set your baseline when the button is pressed. This can turn your Love-o-meter into a Who's Hotter game!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another option is to add a push button to your setup and add the appropriate code to set your baseline when the button is pressed. This can turn your Love-o-meter into a Who's Hotter game!

I want to do this with a push button but I can't seem to get it working. I have set up a circuit with the button feeding into a pin and tested that the button works with a little program that prints something to the serial monitor when the button is pressed/not pressed. I think it must be something to do with my code. I would be super grateful if someone would take a look and let me know what I'm doing wrong. I've tried to simply replicate the button pressing code from an earlier project...

Code:
const int sensorPin = A0; // name the analog pin for temp
int switchState = 0; //set a variable for the pushbutton on/off
float baselineTemp = 0.0; //introduce the baselineTemp variable

/*set the various pins to output and default off*/
void setup() {
   for(int pinNumber = 2; pinNumber<5; pinNumber++) {
    pinMode (pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
  pinMode (7, INPUT); //set the pushbutton pin to input
}

void loop() {
  int sensorVal = analogRead(sensorPin); //set a variable that holds the sensor value
  float voltage = (sensorVal/1024.0) * 5.0; //convert sensor value to voltage
  float temperature = (voltage - .5) * 100; //convert voltage to temp C
  float temperaturef = (temperature *1.8) + 32; //convert temp C to temp F

  
  switchState = digitalRead(7); //check pin 7 for current
  if(switchState == HIGH) { //if button is pushed
  float baselineTemp = temperaturef; //change baselineTemp to currently measured temp
  }  
  
  /*The rest of the code is the stock LED on/off code from the text and works fine*/
  
  else if(temperaturef < baselineTemp){
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  }
  
else if(temperaturef >= baselineTemp+2 &&
temperaturef < baselineTemp+4) {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
}

else if(temperaturef >= baselineTemp+4 &&
temperaturef < baselineTemp+6) {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
}else if(temperaturef >= baselineTemp+6) {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
}
delay(1);
}

edit: I put a Serial.print command after the button push to see if it was seeing the button push. It IS seeing the button push, but the change to the variable baselineTemp doesn't seem to be happening.
« Last Edit: May 02, 2014, 10:56:15 am by asimplecapsule » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry its been a while, have you sorted this out yet?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't! I went on to other projects, but I'd still be interested in knowing how to do this, since it seems like a useful thing to be able to do.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, well right off the top in your code you are setting the value for baselinetemp when the button is pressed. I would recomend creating a seperate function for callibration, call that routine in you setup funtion and then in your loop function when the button is pressed. You may need to integrate some debouncing on the button as well. Also take a look at the MAP function, it will certainly simplify your conversions.
Logged

Pages: 1 [2] 3   Go Up
Jump to: