Basic weather station with temperature, humidity, and light level

Learn to build a basic Arduino weather station measuring temperature humidity and light level using DHT11 sensor and photoresistor with serial output.

Brief Introduction

Basic weather station with temperature, humidity, and light level (arduino)
DESCRIPTION:
A simple Arduino project that reads temperature and humidity from a DHT11 sensor and light level from a photoresistor (LDR). The data is displayed on the serial monitor. Useful for learning analog and digital readings and handling common sensors.

ADDITIONAL NOTES:
The DHT11 sensor is inexpensive and easy to use but has limited accuracy and slow response times. The photoresistor measures ambient light approximately via resistance variation. The code prints data to the serial monitor, useful for debugging and basic visualization. For a more advanced project, an LCD display or sending data to a server can be added.

EXPLANATIONS:
- Inclusion of the DHT library to handle the temperature and humidity sensor.
- Pin definitions: DHT connected to digital pin 2, LDR to analog pin A0.
- In setup, serial communication and the DHT sensor are initialized.
- In loop, humidity and temperature are read from the DHT11, with error checking (NaN).
- The analog value from the photoresistor is read, which varies based on ambient light.
- Values are printed to the serial monitor with a 2-second delay between readings to avoid spam.

Example Code: arduino

#include <DHT.h>  // Library for DHT sensor

#define DHTPIN 2          // Digital pin connected to the DHT11 sensor
#define DHTTYPE DHT11     // Type of DHT sensor
#define LDRPIN A0         // Analog pin connected to the photoresistor

DHT dht(DHTPIN, DHTTYPE);  // Initialize the DHT sensor

void setup() {
  Serial.begin(9600);          // Initialize serial communication
  dht.begin();                 // Start the DHT sensor
  // No special configuration for LDR, it is an analog input
}

void loop() {
  // Read temperature and humidity from DHT11
  float umidita = dht.readHumidity();
  float temperatura = dht.readTemperature(); // Celsius

  // Check if the reading is valid
  if (isnan(umidita) || isnan(temperatura)) {
    Serial.println("Error reading from DHT11 sensor");
  } else {
    Serial.print("Humidity: ");
    Serial.print(umidita);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(temperatura);
    Serial.println(" *C");
  }

  // Read light level from photoresistor
  int valoreLDR = analogRead(LDRPIN);  // Value from 0 (dark) to 1023 (bright light)
  Serial.print("Light level (LDR): ");
  Serial.println(valoreLDR);

  Serial.println("-----------------------------");
  delay(2000);  // Wait 2 seconds before next reading
}
×
×
×
Do you want to regenerate the answer?
×
Export chat
Choose export format
Generazione PDF in corso…
Allegati
×
You are about to close the chat and switch to the image generator. If you are not logged in, you will lose our chat. Do you confirm?
You are viewing a shared chat in temporary mode. It will not be saved.
×
Saved prompts
×
Private note
×
Label
×
Search all chats
×
Your insights
Analyzing…
×
AI Preferences
Assistant name 30
Answer length
AI model
Structured answers
Include examples
Use emojis
Guide me, don't solve Hints and questions instead of a ready answer
More settings →
×
Share this chat
Anyone opening this link can view the chat or add it to their profile as their own chat.
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
Shared chat
Someone shared a chat with you. Do you want to just view it or add it to your chats?
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
×

Saved messages

Loading...

×

Chat History

example-programs · CHAT HISTORY

Loading...

AI Preferences

×
  • BasicQuick and essential answers for study
  • MediumHigher quality for study and programming
  • AdvancedComplex reasoning and detailed analysis
Explain Steps

What do you need?

Arduino Uno (x1)

DHT11 sensor (temperature and humidity) (x1)

Photoresistor (LDR) (x1)

10kΩ resistor (for LDR) (x1)

Male-to-male jumper wires

Breadboard (optional)

CONNECTIONS: DHT11 VCC -> 5V Arduino

CONNECTIONS: DHT11 GND -> GND Arduino

CONNECTIONS: DHT11 DATA -> D2 Arduino

CONNECTIONS: LDR connected in series with 10kΩ resistor between 5V and GND; junction point of LDR-resistor connected to Arduino analog input A0

Similar Topics