Jump to content

IPDL - 4: IoT Sensor Interface with Arduino

From cognifront

IPDL - 4: IoT Sensors Interface with Arduino (Temperature/Light Sensors)

Objective

To interface an LDR and DHT11 temperature sensor with Arduino Uno and read light intensity and temperature values through the Serial Monitor.

Required Components

  • Arduino Uno
  • LDR (Light Dependent Resistor) sensor/module
  • DHT11 temperature sensor
  • Breadboard
  • Jumper wires
  • 10 kΩ resistor (if using a bare LDR)
  • USB cable

Circuit Diagram

Board Connections

Pin Connections

Component Connection
LDR VCC Arduino 5V
LDR GND Arduino GND
LDR Analog Output Arduino A0
DHT11 VCC Arduino 5V
DHT11 GND Arduino GND
DHT11 DATA Arduino Digital Pin 2


Working Principle

The LDR (Light Dependent Resistor) changes its resistance according to the amount of light falling on it. Its analog output is connected to Arduino analog pin A0. The Arduino reads this value using analogRead().

The DHT11 is a digital temperature and humidity sensor. It sends temperature and humidity readings to the Arduino through its data pin. In this experiment, the DHT11 data pin is connected to digital pin 2.

The Arduino reads both sensors and displays their values on the Serial Monitor.

Arduino Code

// © 2025, Cognifront. Member of The IoT Kits Family.

// Experiment: IoT Sensors Interface with Arduino
// Sensors: LDR and DHT11

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

int ldrPin = A0;

DHT dht(DHTPIN, DHTTYPE);

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

  dht.begin();

  Serial.println("LDR and DHT11 Sensor Monitoring Started...");
}

void loop() {
  // Read LDR value
  int ldrValue = analogRead(ldrPin);

  // Read temperature and humidity
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  Serial.print("LDR Value: ");
  Serial.println(ldrValue);

  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("DHT11 reading failed!");
  }
  else {
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");
  }

  Serial.println("-------------------------");

  delay(2000);
}

Required Arduino Library

The code uses the DHT sensor library.

Install it from:

GitHub Repository, visit [1].

Observation

  • The LDR value changes when the amount of light falling on the sensor changes.
  • The DHT11 displays the surrounding temperature in °C.
  • The DHT11 also provides the surrounding humidity value.
  • Sensor readings are displayed on the Serial Monitor at 9600 baud.
  • DHT11 readings are taken every 2 seconds.

Result

The LDR and DHT11 sensors were successfully interfaced with Arduino Uno, and their readings were displayed on the Serial Monitor.

Conclusion

This experiment demonstrates how Arduino Uno can interface with different types of IoT sensors. The LDR provides an analog light-level reading, while the DHT11 provides digital temperature and humidity data.