arduino code for temperature and humidity sensor

Arduino Code for Temperature and Humidity Sensor

Arduino Code for Temperature and Humidity Sensor


Temperature and humidity sensors are commonly used in various applications, including home automation, weather
monitoring, and greenhouse management. Arduino, an open-source electronics platform, can be easily paired with such sensors to create a versatile and customizable system. In this article, we will explore how to write Arduino code for a temperature and humidity sensor and implement it effectively.

Arduino Code

To begin with, you will need to gather the necessary hardware components: an Arduino board, a temperature and humidity
sensor (such as the DHT11 or DHT22), and connecting wires. Once you have the hardware set up, you can proceed to write
the Arduino code.

Here is a sample code snippet that demonstrates how to read data from a DHT11 sensor:

#include <DHT.h>
#define DHTPIN 2     // Pin connected to the sensor
#define DHTTYPE DHT11   // DHT 11
void setup() {
void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  Serial.print("Temperature: ");
  Serial.print("Humidity: ");



Now that you have the Arduino code, it’s time to implement it. Connect the temperature and humidity sensor to the
appropriate pins on the Arduino board. Make sure to refer to the datasheet or sensor documentation for the correct pin

Upload the code to the Arduino board using the Arduino IDE. Open the serial monitor to view the temperature and
humidity readings. You should see the values being printed every two seconds.


In conclusion, writing Arduino code for a temperature and humidity sensor is a straightforward process. By following
the provided code example and properly connecting the sensor to the Arduino board, you can easily retrieve accurate
temperature and humidity data. This opens up endless possibilities for monitoring and controlling environmental
conditions in various applications.

Related Post

What is a Thermocouple Transmitter?

A thermocouple transmitter is a device designed to convert the temperature readings obtained from a thermocouple sensor into a standardized electrical signal. This electrical signal can then be transmitted over

Shopping Cart
Scroll to Top
Scroll to Top