Jump to content

MDM331AID/Experiment 1

From cognifront
Revision as of 14:14, 2 October 2026 by CogWikiEditor (talk | contribs) (Created page with "= Experiment 1: Develop an Application for the Connectivity of the Arduino UNO/Raspberry Pi Circuit with Sensors = '''Course:''' MDM331AID – Internet of Things '''Program:''' TE Artificial Intelligence and Data Science Engineering '''University:''' Savitribai Phule Pune University (SPPU) ---- == 1. Aim == To develop an application for interfacing sensors with Arduino UNO and Raspberry Pi, acquire sensor data, process the readings and display the output through a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Experiment 1: Develop an Application for the Connectivity of the Arduino UNO/Raspberry Pi Circuit with Sensors

Course: MDM331AID – Internet of Things

Program: TE Artificial Intelligence and Data Science Engineering

University: Savitribai Phule Pune University (SPPU)


1. Aim

To develop an application for interfacing sensors with Arduino UNO and Raspberry Pi, acquire sensor data, process the readings and display the output through a serial monitor or terminal.

2. Objectives

  • Understand sensor interfacing with Arduino UNO and Raspberry Pi.
  • Interface an LDR sensor with Arduino UNO and acquire analog sensor data.
  • Interface a DHT11 sensor with Raspberry Pi to acquire temperature and humidity readings.
  • Develop programs to read, process and display sensor data.
  • Understand the differences between analog and digital sensor interfacing.

3. Required Components

Sr. No. Component Quantity Kit
1 Arduino UNO 1 COG-U1
2 Raspberry Pi 4 (4 GB) 1 COG-RPI4
3 LDR Sensor 1 COG-U1
4 DHT11 Temperature and Humidity Sensor 1 COG-MSBA
5 Breadboard (if required) 1 Additional
6 10 kΩ resistor for LDR voltage divider (if using bare LDR) 1 Additional
7 USB Data Cable 1 COG-U1
8 Raspberry Pi power supply 1 COG-RPI4
9 Patch cords As required Available kits

Software Requirements

  • Arduino IDE
  • Python 3
  • Raspberry Pi OS
  • Adafruit CircuitPython DHT library
  • Adafruit Blinka library

Note: The experiment uses two independent implementations. The Arduino UNO implementation reads the LDR, while the Raspberry Pi implementation reads the DHT11. An external ADC such as MCP3008 is additionally required if the LDR is to be read directly by the Raspberry Pi.

4. Theory

4.1 Sensor Interfacing

A sensor is an electronic device that detects physical parameters such as temperature, humidity, light intensity, pressure or motion and converts them into an electrical signal.

Sensor interfacing is the process of connecting sensors to a microcontroller or single-board computer to acquire and process environmental data.

4.2 LDR Sensor

An LDR (Light Dependent Resistor) is a passive sensor whose resistance changes with the intensity of incident light.

  • In bright light, its resistance decreases.
  • In darkness, its resistance increases.

By connecting an LDR in a voltage divider circuit, the Arduino UNO can measure the resulting voltage through an analog input pin.

4.3 DHT11 Sensor

The DHT11 is a digital sensor used to measure temperature and relative humidity.

It communicates with a controller using a single-wire digital communication protocol.

The sensor provides:

  • Temperature in degrees Celsius.
  • Relative humidity in percentage.

4.4 Arduino UNO and Raspberry Pi

Arduino UNO is a microcontroller development board with built-in analog input channels and digital GPIO pins.

Raspberry Pi is a single-board computer that runs a Linux operating system and supports programming in Python, C and other languages.

Unlike the Arduino UNO, Raspberry Pi does not have built-in analog input pins. Digital sensors such as DHT11 can be interfaced directly with suitable GPIO pins.

5. Pin Connections

5.1 LDR Sensor with Arduino UNO

LDR Circuit Point Arduino UNO Pin Description
Voltage divider output A0 Analog sensor input
One end of LDR 5V Supply connection
Other end of LDR A0 Voltage divider junction
10 kΩ resistor lower end GND Ground connection

Circuit arrangement:

        Arduino UNO 5V
              |
             LDR
              |
              +---------- A0
              |
            10 kΩ
              |
             GND

This arrangement produces a higher analog voltage in brighter conditions, assuming the LDR is connected to 5V and the resistor to GND.

5.2 DHT11 Sensor with Raspberry Pi

The following connections assume a DHT11 module with an onboard pull-up resistor.

DHT11 Pin Raspberry Pi Pin Physical Pin Number
VCC 3.3V 1
DATA GPIO4 (BCM) 7
GND Ground 6

Important: Do not connect a 5V pull-up signal directly to a Raspberry Pi GPIO. Raspberry Pi GPIO pins are 3.3V tolerant only. If using a bare DHT11 sensor, a suitable pull-up resistor is required between DATA and 3.3V.

6. Connection Diagram

6.1 Arduino UNO with LDR

       +----------------------+
       |     Arduino UNO      |
       |                      |
       | 5V o-----------------+
       |                      |
       | A0 o-------+         |
       |            |         |
       | GND o---+  |         |
       +---------|--|---------+
                 |  |
              10kΩ  LDR
                 |  |
                GND +5V

6.2 Raspberry Pi with DHT11

       +----------------------+
       |    Raspberry Pi 4    |
       |                      |
       | Pin 1 (3.3V) o-------+------ VCC
       |                      |
       | Pin 7 (GPIO4) o------------- DATA
       |                      |
       | Pin 6 (GND) o---------------- GND
       +----------------------+

                 DHT11

7. Program Code

7.1 Arduino UNO Program for LDR Sensor

const int LDR_PIN = A0;

void setup()
{
    Serial.begin(9600);
    Serial.println("LDR Sensor Monitoring");
}

void loop()
{
    int ldrValue = analogRead(LDR_PIN);

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

    delay(1000);
}

7.2 Raspberry Pi Program for DHT11 Sensor

Step 1: Install the required libraries in the Python environment.

python3 -m venv --system-site-packages dht_env
source dht_env/bin/activate
pip install adafruit-blinka adafruit-circuitpython-dht

Install the system GPIO library dependency if required by your Raspberry Pi OS version, following the Adafruit CircuitPython DHT installation instructions.

Step 2: Create a Python program named `dht11_sensor.py`.

import time
import board
import adafruit_dht

dht = adafruit_dht.DHT11(board.D4)

print("DHT11 Sensor Monitoring")

try:
    while True:
        try:
            temperature = dht.temperature
            humidity = dht.humidity

            if temperature is not None and humidity is not None:
                print("Temperature: {:.1f} C".format(temperature))
                print("Humidity: {:.1f} %".format(humidity))
                print("----------------------")

        except RuntimeError as error:
            print("Reading error:", error)

        time.sleep(2)

except KeyboardInterrupt:
    print("Monitoring stopped")

finally:
    dht.exit()

Step 3: Execute the program.

python dht11_sensor.py

8. Code Explanation

8.1 Arduino UNO Code

  • `const int LDR_PIN = A0;` defines the analog input pin used for the LDR.
  • `Serial.begin(9600);` initializes serial communication at 9600 baud.
  • `analogRead(LDR_PIN);` reads the analog voltage and returns a value between 0 and 1023.
  • `Serial.print()` displays the sensor reading.
  • `delay(1000);` introduces a one-second delay between readings.

8.2 Raspberry Pi Code

  • `import board` provides board pin definitions.
  • `import adafruit_dht` imports the DHT sensor library.
  • `adafruit_dht.DHT11(board.D4)` initializes the sensor on GPIO4.
  • `dht.temperature` reads the temperature.
  • `dht.humidity` reads the relative humidity.
  • `try` and `except` handle transient communication errors.
  • `time.sleep(2)` allows an interval between readings.
  • `dht.exit()` releases the sensor resources when the program ends.

9. Procedure

9.1 Arduino UNO with LDR

  1. Connect the LDR and resistor in a voltage divider arrangement.
  2. Connect the voltage divider output to Arduino analog pin A0.
  3. Connect the Arduino UNO to the computer using the USB data cable.
  4. Open Arduino IDE and select the appropriate Arduino UNO board and COM port.
  5. Enter the Arduino program.
  6. Compile and upload the program.
  7. Open the Serial Monitor and select 9600 baud.
  8. Observe the sensor readings under different light conditions.

9.2 Raspberry Pi with DHT11

  1. Ensure Raspberry Pi OS is installed and the Raspberry Pi is powered.
  2. Connect the DHT11 module to the Raspberry Pi according to the pin connection table.
  3. Create and activate the Python virtual environment.
  4. Install the required Python libraries.
  5. Create the Python program.
  6. Execute the program using the terminal.
  7. Observe the temperature and humidity readings.
  8. Compare the readings under different environmental conditions.

10. Observation and Output

10.1 LDR Sensor Observation

Sr. No. Light Condition LDR Analog Reading Observation
1 Bright light
2 Normal room light
3 Dim light
4 Dark condition

The analog readings should generally increase with increasing light intensity in the given voltage divider arrangement. Actual readings depend on the LDR and ambient lighting conditions.

10.2 DHT11 Sensor Observation

Sr. No. Environmental Condition Temperature (°C) Humidity (%)
1 Normal room condition
2 Warmer condition
3 Different humidity condition

Expected Output (Illustrative)

DHT11 Sensor Monitoring
Temperature: 27.0 C
Humidity: 58.0 %
----------------------
Temperature: 27.0 C
Humidity: 59.0 %
----------------------

The values shown are illustrative only and are not measured experimental results.

11. Result

The interfacing of an LDR sensor with Arduino UNO and a DHT11 sensor with Raspberry Pi was demonstrated through separate sensor-monitoring applications.

The Arduino UNO acquired analog light sensor data, while the Raspberry Pi acquired digital temperature and humidity data using Python.

12. Conclusion

This experiment demonstrates the fundamental process of interfacing sensors with Arduino UNO and Raspberry Pi. It provides practical understanding of analog and digital sensor communication, GPIO interfacing, data acquisition and displaying sensor measurements.

13. Viva Questions

  1. What is sensor interfacing?
  2. What is the operating principle of an LDR?
  3. Why is a voltage divider used with an LDR?
  4. What is the resolution of the Arduino UNO ADC?
  5. Why does Raspberry Pi require an external ADC to read an LDR?
  6. What parameters can be measured using DHT11?
  7. What is the difference between analog and digital sensors?
  8. Why are Raspberry Pi GPIO pins limited to 3.3V?
  9. What is the purpose of a pull-up resistor?
  10. Why is a delay introduced between DHT11 readings?
  11. What is the difference between Arduino UNO and Raspberry Pi?
  12. What are the advantages of connecting sensors to IoT devices?