0% found this document useful (0 votes)
7 views1 page

Prac 11

This Arduino code reads temperature data from a DHT11 sensor connected to pin 12. It continuously monitors and updates the maximum and minimum temperatures recorded, displaying them in both Celsius and Fahrenheit. The program includes error handling for sensor reading failures and prints relevant temperature information to the serial monitor.

Uploaded by

trishak2305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Prac 11

This Arduino code reads temperature data from a DHT11 sensor connected to pin 12. It continuously monitors and updates the maximum and minimum temperatures recorded, displaying them in both Celsius and Fahrenheit. The program includes error handling for sensor reading failures and prints relevant temperature information to the serial monitor.

Uploaded by

trishak2305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <Arduino.

h>
#include <DHT.h>
#define outPin 12 // Pin to which the sensor is connected
#define DHTTYPE DHT11

DHT dht(12, DHT11);

float maxTemp = -9999;


float minTemp = 9999;

void setup() {
Serial.begin(9600);
Serial.println("Working properly !");
dht.begin();
}

void loop() {
delay(2000);

float c = dht.readTemperature();

if (isnan(c)) {
Serial.println("Failed to read temperature from the sensor!");
return;
}

if (c > maxTemp) {
maxTemp = c;
}
if (c < minTemp) {
minTemp = c;
}

Serial.print("Temperature: ");
Serial.print(c);
Serial.println(" °C");

Serial.print("Max Temperature: ");


Serial.print(maxTemp);
Serial.println(" °C");

Serial.print("Min Temperature: ");


Serial.print(minTemp);
Serial.println(" °C");

delay(2000);

float f = dht.readTemperature(true);
if (isnan(f))
{
Serial.println("Not Working !");
}

Serial.println("Temperature (in Farheniet) is :");


Serial.println(f);
delay(1000);
}

You might also like