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

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

VB NET DHT11.ino

This Arduino code initializes a DHT11 temperature and humidity sensor connected to pin 2. It takes readings from the sensor in a loop, printing the humidity and temperature values to the serial monitor every 2 seconds. The code includes the DHT sensor library, defines the sensor as a DHT11, initializes it, then reads the humidity and temperature inside the loop, checking for errors and printing the values if readings are successful.

Uploaded by

Emcee Cisse
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)
58 views1 page

VB NET DHT11.ino

This Arduino code initializes a DHT11 temperature and humidity sensor connected to pin 2. It takes readings from the sensor in a loop, printing the humidity and temperature values to the serial monitor every 2 seconds. The code includes the DHT sensor library, defines the sensor as a DHT11, initializes it, then reads the humidity and temperature inside the loop, checking for errors and printing the values if readings are successful.

Uploaded by

Emcee Cisse
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 "DHT.

h" //--> Include the DHT Sensor Library

#define DHTTYPE DHT11 //--> Defines the type of DHT sensor used (DHT11, DHT21, and
DHT22), in this project the sensor used is DHT11.
const int DHTPin = 2; //--> The pin used for the DHT11
DHT dht(DHTPin, DHTTYPE); //--> Initialize DHT sensor, DHT dht(Pin_used,
Type_of_DHT_Sensor);

//----------------------------------------Setup
void setup(){
Serial.begin(9600);
delay(100);
dht.begin(); //--> Start reading DHT11 sensors
}

//----------------------------------------Loop
void loop(){

int humidity = dht.readHumidity(); //--> Read humidity


float temperature = dht.readTemperature(); //--> Read temperature as Celsius
(the default). If you want to read the temperature sensor in Fahrenheit, use this -
> float t = dht.readTemperature (true);

if (isnan(humidity) || isnan(temperature)) { //--> Check if any reads failed and


exit early (to try again).
Serial.println("Failed to read from DHT sensor!");
}
else {
Serial.print("H");
Serial.println(humidity);
Serial.print("T");
Serial.println(temperature);
}
delay(2000); //--> The value is the same as the interval value in the
TimerSerial in the VB application
}

You might also like