Go Down

Topic: Problem on Project 3 Love-O-Meter (Read 698 times) previous topic - next topic

Hatred_Realm

Dec 15, 2016, 02:21 am Last Edit: Dec 15, 2016, 02:35 am by Hatred_Realm Reason: Using quote instead code to put a code
Hello.
I'm new to arduino and electronic.
I was doing a project 3 Love-O-Meter and expanded the project from 3 LED to 6 LED.
3 Red LED is to measure the hot environment and 3 Blue Led is to measure the cold environment.
But, i am facing a problems during this project and i would like to ask a few question.
My question is :

1. Why the temperature shown in the serial monitor is sometimes unstable ?



But when i touch the sensor, the temperature increase and it become stable.



2. Why the temperature shown the in serial monitor changed drastically when i shake or move the breadboard or arduino for a few cm ?



3. Is the code i write to measure the cold environment is the simplest one or are there more simplest than this ?

Code: [Select]

const int sensorPin = A0;
const float baselineTemp = 27.0;

void setup()
{
  Serial.begin(9600);
  for(int pinNumber = 2; pinNumber < 8; pinNumber ++)
  {
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void loop()
{
  int sensorVal = analogRead(sensorPin);

  Serial.print("Sensor Value : ");
  Serial.print(sensorVal);
 
  float voltage = (sensorVal/1024.0)*5.0;

  Serial.print("Volts : ");
  Serial.print(voltage);
  Serial.print("Degrees C : ");

  float temperature = (voltage-.5)*100;

  Serial.println(temperature);

  if(temperature >= baselineTemp+2 && temperature < baselineTemp+4)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }

  else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }

  else if(temperature >= baselineTemp+6)
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }

  else if (temperature < baselineTemp && temperature >= baselineTemp-2)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }

  else if (temperature < baselineTemp-2 && temperature >= baselineTemp-4)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
  }

  else if (temperature < baselineTemp-4)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }

  delay(1);
}


Thank you very much.

Go Up