Arduino Program to Display Temperature
Arduino Program to Display Temperature
Monitor
We will use the DHT11 or DHT22 temperature sensor to measure the temperature and display it
on the Serial Monitor.
🛠️ Required Components
🔌 Circuit Connections
DHT Sensor Pin Arduino Pin
VCC (Power) 5V
GND (Ground) GND
DATA (Signal) D2
(For DHT22, connect a 10kΩ resistor between VCC and DATA pin.)
📜 Arduino Code
cpp
CopyEdit
#include <DHT.h> // Include the DHT library
void setup() {
Serial.begin(9600); // Start Serial Monitor
Serial.println("DHT Sensor Initialized");
dht.begin(); // Start the DHT sensor
}
void loop() {
float temperature = dht.readTemperature(); // Read temperature in °C
📖 Code Explanation
1⃣ Including the DHT Library
cpp
CopyEdit
#include <DHT.h>
makefile
CopyEdit
DHT Sensor Initialized
Temperature: 28.5 °C
Temperature: 28.6 °C
Temperature: 28.4 °C