Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Prac 10

This Arduino code initializes a DHT11 temperature and humidity sensor and continuously reads and prints the temperature in both Celsius and Fahrenheit, as well as the humidity percentage. If the sensor fails to read values, it outputs an error message. The readings are updated every 2 seconds.

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)
23 views1 page

Prac 10

This Arduino code initializes a DHT11 temperature and humidity sensor and continuously reads and prints the temperature in both Celsius and Fahrenheit, as well as the humidity percentage. If the sensor fails to read values, it outputs an error message. The readings are updated every 2 seconds.

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"

DHT dht(12, DHT11); // Creates a DHT object

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {
float f = dht.readTemperature(true); // Read temperature in Fahrenheit
float c = dht.readTemperature(); // Read temperature in Celsius
float h = dht.readHumidity(); // Read humidity

if (isnan(f) || isnan(c) || isnan(h)) {


Serial.println("Sensor not working");
return;
}

Serial.print("Temperature = ");
Serial.print(c);
Serial.print("°C | ");
Serial.print(f);
Serial.println("°F");

Serial.print("Humidity = ");
Serial.print(h);
Serial.println("%");

delay(2000);
}

You might also like