Group B

Q11: Write a program so it displays the temperature in Fahrenheit as well as the maximum and minimum temperatures it has seen.

Temperature Display

Solution and implementation for Q11 from Internet of Things (iotl).

temperature_display.cpp Download
// Note: This code was provided by our teacher. 
// However, it does not include functionality to print the minimum and maximum temperatures.
// Please refer to Code 2 for the complete version with min and max temperature printing.

#include <dht.h>

dht DHT;
#define DHT11_PIN A1
float min_t,max_t;

void setup()
{
  Serial.begin(9600);
  Serial.println("Humidity (%),\tTemperature (C),\t Temperature(F)");
  min_t = 0xffff;
  max_t=0x00;
}

void loop()
{
  // READ DATA
  int chk = DHT.read11(DHT11_PIN);
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print("\t");
  Serial.println(DHT.temperature, 1);
  Serial.println("\t");
  Serial.println((DHT.temperature*1.8)+32, 1);
  Serial.println("\t");
  delay(1000);
}
temperature_display_2.cpp Download
//this Code includes printing of min and max
//however this code is not TESTED

#include <dht.h>

dht DHT;

#define DHT11_PIN A1
float min_f, max_f;

void setup()
{
  Serial.begin(9600);
  Serial.println("Humidity (%),\tTemp (C),\tTemp (F),\tMin Temp (F),\tMax Temp (F)");

  min_f = 9999;
  max_f = -9999;
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);

  float currentF = DHT.temperature * 1.8 + 32;

  // Update min/max
  if (currentF < min_f) min_f = currentF;
  if (currentF > max_f) max_f = currentF;

  // Display all values
  Serial.print(DHT.humidity, 1);
  Serial.print("\t\t");
  Serial.print(DHT.temperature, 1);
  Serial.print("\t\t");
  Serial.print(currentF, 1);
  Serial.print("\t\t");
  Serial.print(min_f, 1);
  Serial.print("\t\t");
  Serial.println(max_f, 1);

  delay(1000);
}

Other Questions in Internet of Things

See All Available Questions
Download