Pages: 1 2 [3]   Go Down
Author Topic: Project #3 - Love-O-Meter  (Read 9670 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry don't have as much time today as I though.... I was wrong about using the map function (unless you want to forget about actual temperature and just work on a scale of x to y) here is my code that I used you can compare it to yours and perhaps figure out your issue...
Code:
const int sensorPin = A0;
float baselineTemp = 0.0;
int sensorVal = 0;
float voltage = 0.0;
float  temperature = 0.0;
int buttonPin = 5;
int button = 0;
int oldbutton = 0;


void setup()
{
  Serial.begin(9600); //open serial port
  for(int pinNumber = 2; pinNumber < 5; pinNumber++) //define pins 2,3, and 4 as outputs and make sure they are off
  {
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
  pinMode(buttonPin, INPUT);
  //callibrate baseline temperature
  calibrate();
}

void loop()
{
  button = digitalRead(buttonPin);
  if ((button == HIGH) && (button != oldbutton))
  {
    calibrate();
  }
  oldbutton = button;
  sensorVal = analogRead(sensorPin); //read value from sensor
  /*Serial.print("Sensor Value: ");
  Serial.print(sensorVal); //send current sensor reading
  voltage = (sensorVal/1024.0) * 5.0; //convert analog reading to voltage
  Serial.print(" , Volts: ");
  Serial.print(voltage); //send output voltage
  temperature = (voltage - .5) * 100; //convert voltage to actual temp.
  Serial.print(" , degrees C: ");
  Serial.println(temperature); //send temp.*/
 
  if(temperature < baselineTemp)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  if(temperature >= baselineTemp+2 && temperature < baselineTemp+4)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  if(temperature >= baselineTemp+4 && temperature < baselineTemp+6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  }
  if(temperature >= baselineTemp+6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
  delay(1);
}

void calibrate()
{
  sensorVal = analogRead(sensorPin); //read sensor
  voltage = (sensorVal/1024.0) * 5; //convert to voltage
  temperature = (voltage - .5) * 100; // convert to temp
  baselineTemp = temperature; //set baseline
}
Logged

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