Back to Parent

int sensorPin = A0;
int sensorVal = 0;
int baselineTemp = 10;
int number = 4;
int LedPin [4] = {D0, D1, D2, D3};
float temperature = 0;

void setup(){
  Serial.begin(9600);
  for (int x=0; x<5; x++){
    pinMode(x, OUTPUT);
    digitalWrite(x, LOW);

  }
  Particle.variable ("sensorValue",&sensorVal,INT);
}

void loop(){
  sensorVal = analogRead(sensorPin);
  Serial.print (sensorVal);
  Serial.print ("ADC");
  float Voltage = (sensorVal/1024.0)*5.0;
  Serial.print (Voltage);
  Serial.print ("Volts,");
  temperature = (Voltage * 4) + 7;
  Serial.print (temperature);
  Serial.print ("degrees C");
  if (temperature < baselineTemp){
    digitalWrite(LedPin[0], LOW);
    digitalWrite(LedPin[1], LOW);
    digitalWrite(LedPin[2], LOW);
    digitalWrite(LedPin[3], LOW);
    Particle.publish ("TempCold", "cold");
  }
   else if (temperature >= baselineTemp && temperature < baselineTemp+10){
     digitalWrite(LedPin[0], HIGH);
     digitalWrite(LedPin[1], LOW);
     digitalWrite(LedPin[2], LOW);
     digitalWrite(LedPin[3], LOW);
     Particle.publish ("TempCool", "cool");
   }
   else if (temperature >= baselineTemp+10 && temperature < baselineTemp+20){
     digitalWrite(LedPin[0], HIGH);
     digitalWrite(LedPin[1], HIGH);
     digitalWrite(LedPin[2], LOW);
     digitalWrite(LedPin[3], LOW);
     Particle.publish ("TempWarm", "warm");
   }
   else if (temperature >= baselineTemp+20 && temperature < baselineTemp+30){
     digitalWrite(LedPin[0], HIGH);
     digitalWrite(LedPin[1], HIGH);
     digitalWrite(LedPin[2], HIGH);
     digitalWrite(LedPin[3], LOW);
     Particle.publish ("TempPerfect", "perfect");
   }
   else if (temperature >= baselineTemp+30 && temperature < baselineTemp+40){
     digitalWrite(LedPin[0], HIGH);
     digitalWrite(LedPin[1], HIGH);
     digitalWrite(LedPin[2], HIGH);
     digitalWrite(LedPin[3], HIGH);
     Particle.publish ("TempHot", "hot");
   }
   delay(1000);
  }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0