Introduction

During the Input Devices week, I learned about different sensors and how they work with a microcontroller. I understood that sensors detect changes such as light, temperature, motion, and distance, and send this information to the microcontroller for processing. I also learned the difference between analog and digital signals. Analog signals change continuously, while digital signals have only two states: HIGH and LOW. During the practical session, I connected sensors to the ESP32-C3 and ESP32, viewed their readings using the Serial Monitor, and observed the signal changes. I also used an oscilloscope to understand how sensor signals are displayed and measured. This hands-on experience helped me better understand how input devices and sensors work in embedded systems.

Individual assignment

Task:

During this week, my individual assignment was to connect all the sensors to the microcontroller board and check their output. I tested each sensor and verified that it was working correctly by reading the sensor values.

Group assignment

Task:

During this week, we observed analog and digital signals using an oscilloscope. We also measured the voltage and current of the IR sensor using a multimeter. Additionally, we compared the features and performance of the DHT11 and DHT22 sensors.

Introduction

During this week’s group assignment, we learned about analog and digital signals using the ESP32-C3 microcontroller. We observed the analog and digital signals by monitoring the LED blinking with an oscilloscope. We also used a multimeter to measure the voltage and current of the IR sensor. Additionally, we compared the DHT11 and DHT22 sensors based on their specifications and performance. This activity helped us understand how the microcontroller works with digital signals.

Digital signal

Using led

Hardware components we used:-

  • XIAO ESP32C3
  • LED
  • oscilloscope
  • Connceting wires

Comparative Analysis of DHT11 and DHT22 Sensors.

The DHT11 and DHT22 are both used to measure temperature and humidity. The DHT22 is more accurate and can measure a wider range of temperature and humidity than the DHT11. The DHT11 is cheaper and is good for simple projects. The DHT22 is better for projects that need more accurate readings.

FeatureDHT11DHT22
Temperature Range0°C to 50°C-40°C to 80°C
Humidity Range20% to 80% RH0% to 100% RH
AccuracyLowerHigher
Resolution1°C, 1% RH0.1°C, 0.1% RH
CostLowerHigher
Best ForSimple projectsMore accurate projects

Measurement of IR Sensor Voltage and Current Using a Multimeter.

Voltage Measurement of the IR Sensor.

As part of our group assignment, we connected the IR sensor to the ESP32 microcontroller and measured its voltage using a digital multimeter. We placed the multimeter probes between the VCC and OUT pins and recorded a voltage of 0.71 V. This activity helped us learn how to measure the voltage of an IR sensor and understand its output during operation.

Current Measurement of the IR Sensor

As part of our group assignment, we connected the IR sensor to the ESP32 microcontroller and measured its current using a digital multimeter. We connected the multimeter in series with the sensor circuit to measure the current consumed during operation. The measured current was 1.17 mA. This activity helped us learn how to measure the current of an IR sensor and understand its power consumption while it was working.

Input Devices

An input device is a device that sends information to a microcontroller. It detects changes such as light, temperature, distance, motion, or sound and converts them into electrical signals. The microcontroller reads these signals and performs the required action. In simple words, an input device provides data to the system.

What is sensor?

A sensor is a device that detects changes in the environment and sends the information to a microcontroller. It can detect things such as light, temperature, sound, distance, motion, or humidity. The sensor converts these changes into electrical signals, which the microcontroller reads and processes. In simple words, a sensor collects information from the surroundings and provides it to the system.

Types of sensors:-

Digital signal

A digital signal has only two states: HIGH (1) and LOW (0). It is used by microcontrollers to detect whether a signal is ON or OFF. Digital signals are commonly used with switches, buttons, LEDs, and digital sensors.

Analog signal

An analog signal changes continuously and can have many different values. It is used to measure real-world data such as temperature, light, sound, and pressure. The microcontroller reads these changing values and processes them accordingly.

Sensors

1.AHT2415C

The AHT2415C is a digital temperature and humidity sensor that measures the surrounding temperature and humidity. It provides accurate readings and sends the data to a microcontroller through the I²C communication protocol. The sensor is easy to connect, has low power consumption, and works well with boards such as the ESP32 and Arduino. It is widely used in projects that require reliable environmental monitoring.

Pin description

  • VCC – Connects to the 3.3V or 5V power supply.
  • GND – Connects to the ground (GND) of the microcontroller.
  • SDA – Data line used to transfer temperature and humidity data.
  • SCL – Clock line used for I²C communication.

Internal structure of AHT2415C

The AHT2415C contains a temperature sensing element, a humidity sensing element, and an internal Analog-to-Digital Converter (ADC). The temperature sensor measures the surrounding temperature, while the humidity sensor detects the moisture in the air. The ADC converts these measurements into digital data, which is sent to the microcontroller through the SDA and SCL pins using the I²C communication protocol.

Applications

  • Weather stations
  • Smart home systems
  • HVAC systems
  • Environmental monitoring
  • Industrial automation
  • IoT projects

Here is the code I used:-

                            
#include <Wire.h>
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

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

  Wire.begin(8, 9);   // SDA = GPIO8 , SCL = GPIO9

  if (!aht.begin()) {
    Serial.println("AHT sensor not detected");   
  }

  Serial.println("AHT sensor ready");   
}
 

void loop() {

  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);


  Serial.print("Temp: ");
  Serial.print(temp.temperature);
  Serial.print(" °C  ");

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

  
  delay(2000);     
}










2.Sound sensor

A sound sensor is an electronic device that detects sound or noise from the surrounding environment. It uses a small microphone to capture sound waves and converts them into electrical signals. The sensor sends these signals to a microcontroller, which can detect the presence or intensity of sound. It is commonly used with ESP32, Arduino, and other microcontroller boards.

Pin description

  • VCC – Connects to the 3.3V or 5V power supply.
  • GND – Connects to the ground (GND).
  • DO – Digital output that gives a HIGH or LOW signal based on the sound level.

The structure of sound sensor

The sound sensor consists of a microphone, an amplifier, and a comparator circuit. The microphone detects sound waves and converts them into electrical signals. The amplifier strengthens the signal, and the comparator compares it with a preset threshold to generate a digital output. The sensor can provide both analog and digital signals depending on the module.

Applications

  • Noise level monitoring
  • Clap switch projects
  • Security and alarm systems
  • Home automation
  • Smart devices
  • Robotics and IoT projects

Developed System

Here is the code I used:-

#define SOUND_SENSOR 4
#define LED 5
#define BUZZER 2

void setup() {
  pinMode(SOUND_SENSOR, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(BUZZER, OUTPUT);

  digitalWrite(LED, LOW);
  digitalWrite(BUZZER, LOW);

  Serial.begin(115200);
}

void loop() {

  int sound = digitalRead(SOUND_SENSOR);

  Serial.println(sound);

  if (sound == HIGH) {      // Sound detected
    digitalWrite(LED, HIGH);
    digitalWrite(BUZZER, HIGH);

    delay(2000);            // ON for 2 seconds

    digitalWrite(LED, LOW);

3.MQ2 Sensor

The MQ2 Gas Sensor is a gas detection sensor used to detect LPG, propane, methane, hydrogen, smoke, and other flammable gases. It measures the concentration of gases in the air and sends the data to a microcontroller. The sensor provides both analog and digital outputs, making it easy to interface with ESP32, Arduino, and other microcontroller boards. It is widely used for gas leak detection and safety monitoring.

Pin description

  • VCC – Connects to the 5V power supply.
  • GND – Connects to the ground (GND) of the microcontroller.
  • AO – Analog output that provides the gas concentration value.
  • DO – Digital output that gives a HIGH or LOW signal when the gas level exceeds the preset threshold.

The structure of MQ2 Sensor

The MQ2 sensor contains a gas-sensitive material (SnO₂ – Tin Dioxide) and a heating element. When gas is present, the resistance of the sensing material changes. The internal circuit converts this change into an electrical signal. The analog output provides the gas concentration level, while the digital output is generated using a comparator circuit when the gas concentration crosses a preset limit.

Applications

  • Gas leak detection
  • Smoke detection systems
  • Fire safety systems
  • Home and industrial safety
  • Air quality monitoring
  • IoT and automation projects

Developed System

Here is the code I used:-

#define MQ2_PIN 4
#define LED_PIN 2
#define BUZZER_PIN 5

void setup() {
  pinMode(MQ2_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  Serial.begin(115200);

  digitalWrite(LED_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  int smoke = digitalRead(MQ2_PIN);

  if (smoke == LOW) {   // Smoke detected
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
    Serial.println("Smoke Detected");
  } else {
    digitalWrite(LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
    Serial.println("No Smoke");
  }
}

4. Float Sensor

The Float Sensor is a sensor used to detect the liquid level in a tank or container. It works by using a floating object that moves up and down with the water level. When the water reaches a certain level, the sensor changes its output and sends a signal to the microcontroller. Float sensors are simple, reliable, and commonly used with ESP32, Arduino, and other microcontroller boards.

Pin description

  • VCC – Connects to the power supply (if required by the module).
  • GND – Connects to the ground (GND).

The structure of Float Sensor

The float sensor consists of a floating magnet and a reed switch inside a sealed tube. As the liquid level rises or falls, the float moves up or down. The magnet inside the float activates the reed switch, opening or closing the electrical circuit. This change is detected by the microcontroller as a digital HIGH or LOW signal.

Applications

  • Water level monitoring
  • Water tank automation
  • Overflow protection systems
  • Industrial liquid level monitoring
  • Pump control systems
  • Smart irrigation systems
  • IoT water management projects

Developed System

Here is the code I used:-

#define FLOAT_SENSOR 4   // Float sensor pin
#define LED_PIN      8   // Onboard or external LED

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

  pinMode(FLOAT_SENSOR, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);
}

void loop() {
  int sensorState = digitalRead(FLOAT_SENSOR);

  if (sensorState == LOW) {
    Serial.println("Water Level: HIGH");

    digitalWrite(LED_PIN, HIGH);      // LED ON
  } else {
    Serial.println("Water Level: LOW");

    digitalWrite(LED_PIN, LOW);       // LED OFF
  }

  delay(500);
}

4. Ultrasonic Sensor

The Ultrasonic Sensor is a distance-measuring sensor that uses ultrasonic sound waves to detect the distance between the sensor and an object. It sends out an ultrasonic pulse and measures the time taken for the echo to return. Based on this time, the microcontroller calculates the distance. The sensor is easy to use and is commonly connected to ESP32, Arduino, and other microcontroller boards.

Pin description

  • VCC – Connects to the 5V power supply.
  • GND – Connects to the ground (GND).
  • TRIG – Trigger pin used to send an ultrasonic pulse.
  • ECHO – Echo pin used to receive the reflected pulse from the object.

The structure of Ultrasonic Sensor

The ultrasonic sensor contains an ultrasonic transmitter, an ultrasonic receiver, and a control circuit. The transmitter sends high-frequency sound waves (typically 40 kHz), and the receiver detects the reflected waves after they bounce off an object. The control circuit measures the time between sending and receiving the pulse and converts it into distance data, which is sent to the microcontroller.

Applications

  • Distance measurement
  • Obstacle detection
  • Robot navigation
  • Water level monitoring
  • Parking assistance systems
  • Smart dustbins
  • IoT and automation projects

Developed System

Here is the code I used:-

#define TRIG_PIN 4
#define ECHO_PIN 5
#define LED_PIN 2

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

  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  long duration;
  float distance;

  // Send ultrasonic pulse
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);

  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);

  digitalWrite(TRIG_PIN, LOW);

  // Read echo time
  duration = pulseIn(ECHO_PIN, HIGH);

  // Calculate distance in cm
  distance = duration * 0.0343 / 2;

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // LED control
  if (distance > 0 && distance <= 20) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }

  delay(200);
}

5. Infrared Sensor

The IR (Infrared) Sensor is an electronic sensor used to detect nearby objects without touching them. It works by transmitting infrared light and detecting the reflected light from an object. When an object comes in front of the sensor, it sends a signal to the microcontroller. The IR sensor is easy to use and is commonly connected to ESP32, Arduino, and other microcontroller boards.

Pin description

  • VCC – Connects to the 3.3V or 5V power supply.
  • GND – Connects to the ground (GND).
  • OUT – Digital output pin that sends a HIGH or LOW signal to the microcontroller when an object is detected.

The structure of IR Sensor

The IR sensor contains an IR LED (transmitter), an IR photodiode (receiver), and a comparator circuit. The IR LED emits infrared light, and the photodiode receives the reflected light from an object. The comparator processes the received signal and generates a digital HIGH or LOW output, which is read by the microcontroller.

Applications

  • Obstacle detection
  • Object detection
  • Line-following robots
  • Automatic doors
  • Security systems
  • Industrial automation
  • Robotics and IoT projects

Developed System

Here is the code I used:-

#define IR_PIN 4
#define LED_PIN 2

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

  pinMode(IR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int sensorState = digitalRead(IR_PIN);

  // Most IR obstacle sensors output LOW when an object is detected
  if (sensorState == LOW) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Object Detected");
  } else {
    digitalWrite(LED_PIN, LOW);
    Serial.println("No Object");
  }

  delay(100);
}

6. PIR Sensor

The PIR (Passive Infrared) Sensor is used to detect the motion of people or animals. It works by sensing changes in the infrared (heat) radiation emitted by living objects. When motion is detected, the sensor sends a digital signal to the microcontroller. The PIR sensor is easy to use and is commonly connected to ESP32, Arduino, and other microcontroller boards.

Pin description

  • VCC – Connects to the 5V or 3.3V power supply.
  • GND – Connects to the ground (GND).
  • OUT – Digital output pin that sends a HIGH signal when motion is detected and a LOW signal when no motion is detected.

The structure of PIR Sensor

The PIR sensor contains a pyroelectric sensor, a Fresnel lens, and a signal processing circuit. The Fresnel lens focuses infrared radiation onto the pyroelectric sensor. When a warm object, such as a person, moves in front of the sensor, the infrared radiation changes. The signal processing circuit detects this change and generates a digital HIGH or LOW output, which is read by the microcontroller.

Applications

  • Motion detection systems
  • Security and burglar alarms
  • Automatic lighting
  • Smart home automation
  • Occupancy detection
  • Energy-saving systems
  • Robotics and IoT projects

Developed System

Here is the code I used:-

#define PIR_PIN 4
#define LED_PIN 2
#define BUZZER_PIN 5

void setup() {
  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  Serial.begin(115200);

  digitalWrite(LED_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  int motion = digitalRead(PIR_PIN);

  if (motion == HIGH) {
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
    Serial.println("Motion Detected");
  } else {
    digitalWrite(LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
    Serial.println("No Motion");
  }

7. DHT22 Sensor

The DHT22 is a digital sensor used to measure temperature and humidity. It provides more accurate readings and a wider measurement range than the DHT11. The sensor sends digital data directly to a microcontroller through a single data pin. It is easy to use and is commonly connected to ESP32, Arduino, and other microcontroller boards for environmental monitoring.

Pin description

  • VCC – Connects to the 3.3V or 5V power supply.
  • DATA – Sends temperature and humidity data to the microcontroller.
  • GND – Connects to the ground (GND).

The structure of DHT22 Sensor

The DHT22 contains a humidity sensing element, a temperature sensor, and an internal signal processing circuit. The humidity sensor measures the moisture in the air, while the temperature sensor measures the surrounding temperature. The internal circuit converts these measurements into digital data and sends them to the microcontroller through the DATA pin.

Applications

  • Weather stations
  • Smart home systems
  • HVAC systems
  • Greenhouse monitoring
  • Environmental monitoring
  • Industrial monitoring
  • IoT projects

Developed System

Here is the code I used:-

#include <DHT.h>

#define DHTPIN 13      // DHT22 DATA pin connected to GPIO 13
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  Serial.println("DHT22 Sensor Test");
  dht.begin();
}

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT22 sensor!");
    delay(2000);
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print(" °C\t");

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

  delay(2000);
}

8. MQ 7 Sensor

The MQ-7 is a gas sensor used to detect carbon monoxide (CO) in the air. It measures the concentration of carbon monoxide and sends the data to a microcontroller. The sensor provides both analog and digital outputs, making it easy to interface with ESP32, Arduino, and other microcontroller boards. It is widely used in gas leak detection and air quality monitoring systems.

Pin description

  • VCC – Connects to the 5V power supply.
  • GND – Connects to the ground (GND).
  • AO – Analog output that provides the carbon monoxide concentration value.
  • DO – Digital output that gives a HIGH or LOW signal when the CO gas level exceeds the preset threshold.

The structure of MQ7 Sensor

The MQ-7 sensor contains a gas-sensitive sensing element (Tin Dioxide – SnO₂), a heating element, and a signal processing circuit. When carbon monoxide gas is present, the resistance of the sensing material changes. The internal circuit converts this change into an electrical signal. The analog output provides the gas concentration value, while the comparator circuit generates a digital HIGH or LOW output when the gas level exceeds the preset threshold.

Applications

  • Carbon monoxide leak detection
  • Home safety systems
  • Industrial gas monitoring
  • Air quality monitoring
  • Fire safety systems
  • Smart home automation
  • IoT and environmental monitoring projects

Developed System

Here is the code I used:-

#define MQ7_PIN 4
#define LED_PIN 2

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

  pinMode(MQ7_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int gasState = digitalRead(MQ7_PIN);

  // Most MQ-7 modules output LOW when gas is detected
  if (gasState == LOW) {
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Carbon Monoxide Detected!");
  } else {
    digitalWrite(LED_PIN, LOW);
    Serial.println("Air is Normal");
  }

  delay(200);
}