Group B

Q10: Write a program to read the temperature sensor and send the values to the serial monitor on the computer.

Temperature Sensor

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

temperature.cpp Download
// For question 10 --> open the serial monitor for output
// For question 12 --> open the serial plotter for output

#include <dht.h>

dht DHT;
#define DHT11_PIN A1

void setup()
{
  Serial.begin(9600);
  Serial.println("Humidity (%),\tTemperature (C)");
}

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

  // DISPLAY DATA (Humidity and Temperature)
  Serial.print("Humidity: ");
  Serial.print(DHT.humidity, 1);  // Print humidity with one decimal place
  Serial.print("%\t");

  Serial.print("Temperature: ");
  Serial.println(DHT.temperature, 1);  // Print temperature with one decimal place

  delay(1000);  // Wait 1 second before reading again
}

Other Questions in Internet of Things

See All Available Questions
Download