Iot Expt 3
Iot Expt 3
Aim:
To design and test an application for measuring temperature and light intensity using sensors with
Raspberry Pi, and to simulate the experiment online.
Apparatus Required
1. Online Simulator
Components:
Background Theory
Temperature Sensor (DHT11 or DHT22): The DHT series of sensors can measure both
temperature and humidity. The DHT11 is suitable for basic projects, while the DHT22 provides a
wider range of temperature and humidity measurement. The sensor outputs a digital signal which is
processed by Raspberry Pi to get the temperature reading.
Light Sensor (LDR or Photoresistor): An LDR is a resistor whose resistance changes with light
intensity. It’s typically used in light-sensitive applications like street lighting or brightness adjustment
in electronic devices. The Raspberry Pi can read the varying voltage using its analog-to-digital
converter (ADC) or by using a simple voltage divider circuit.
Algorithm
4. Process Data:
● Convert the raw sensor data into readable temperature (°C) and light intensity (lux) values.
● If the light level is above a threshold, turn on the LED (or perform another action like sending
data to a cloud server).
Procedure
1. Hardware Setup in Raspberry Pi:
2. Software Setup:
3. Simulation:
1. Run the Python script on your Raspberry Pi.
2. Monitor the console output for temperature, humidity, and light intensity readings.
3. Optionally, visualize the data on an IoT platform like ThingSpeak or Blynk.
4. Use real-time data to trigger actions (e.g., send alerts or automate devices based on
environmental conditions).
Program
import dht
from machine import Pin
import time
import random # To simulate slight changes
# Temperature Threshold
temp_threshold = 25 # LED will blink if temperature > 25°C
while True:
try:
sensor.measure()
temperature = sensor.temperature() + random.uniform(-3, 3) # Simulate variation
prev_temp = temperature
except OSError as e:
print("Failed to read from DHT22 sensor:", e)
Result
1. Successfully read temperature and humidity data using the DHT11 sensor connected
to the Raspberry Pi.
2. The Serial Monitor displayed the temperature (in Celsius) and humidity (in percentage)
values in real-time.
3. The LDR (Light Dependent Resistor) successfully detected the ambient light intensity,
with the status displayed as "High" or "Low" based on the surrounding light conditions.
4. An LED was used for visual feedback, and it blinked when the light intensity was
low, indicating that the LDR detected low light levels.