Introduction

In Week 3, our target was to study different types of input sensors and understand their working principles. We learned how sensors detect physical changes such as temperature, light, sound, motion, gas, humidity, pressure, magnetic fields, and touch, and convert them into electrical signals that a microcontroller can process.

We also studied the internal structure of different sensors, including the materials and sensing elements used inside them. This helped us understand how each sensor detects specific physical changes and generates an electrical output. we learned the difference between analog and digital sensors,

Through this study, we gained knowledge about the working principle, internal construction, pin configuration, applications, and interfacing of various input sensors with a microcontroller.

Input Devices

Input devices are electronic components or sensors that detect changes in the environment or receive user input and convert them into electrical signals that a microcontroller or computer can process. They provide the data required for a system to make decisions or perform specific actions.

What is a Sensor?

sensor is an electronic device that detects or measures a physical property or environmental change, such as temperature, light, sound, motion, pressure, humidity, gas concentration, or magnetic fields, and converts it into an electrical signal. This signal is then processed by a microcontroller, computer, or other electronic system to perform a specific action or display information.

Sensors are the input devices of embedded systems and IoT devices because they collect real-world data and provide it to the controller for processing.

Examples of sensors:

  • Temperature Sensor (DHT11, DHT22)
  • Light Sensor (LDR)
  • PIR Motion Sensor
  • Sound Sensor
  • Gas Sensor (MQ2, MQ7)
  • RFID Reader (RC522)
  • Ultrasonic Sensor
  • Soil Moisture Sensor
  • Hall Effect Sensor
  • Flame Sensor.

Characteristics of Sensors

CharacteristicDescription
SensitivityAbility to detect small changes in the input.
AccuracyCloseness of the measured value to the actual value.
PrecisionAbility to produce the same reading repeatedly.
RangeMinimum and maximum values the sensor can measure.
ResolutionSmallest change the sensor can detect.
Response TimeTime taken to respond to a change in input.
LinearityOutput changes proportionally with the input.
RepeatabilityAbility to give consistent results under the same conditions.
StabilityAbility to maintain consistent performance over time.
ReliabilityAbility to operate correctly without failure for a long period.
SelectivityAbility to detect a specific parameter while ignoring others.
Power ConsumptionAmount of electrical power required to operate the sensor.

Classification of Sensors Based on Power Requirement

1. Active Sensors

  • Require an external power supply to operate.
  • They need electrical energy to produce an output signal.

Examples:

  • DHT11
  • Ultrasonic Sensor (HC-SR04)
  • PIR Sensor
  • MQ-2 Gas Sensor
  • IR Sensor Module

2. Passive Sensors

  • Do not require an external power source for the sensing element.
  • They detect changes in the environment and produce an output based on those changes. (In practical circuits, some modules may still need power for signal conditioning.)

Examples:

  • LDR (Light Dependent Resistor)
  • Thermistor
  • Thermocouple
  • Strain Gauge
  • Piezoelectric Sensor

classification based on output

Analog Signal

An analog signal is a continuous signal that changes smoothly over time. It can have many different voltage levels between the minimum and maximum values. Analog sensors provide variable outputs that are read using the analog input pins of a microcontroller. These signals are commonly used to measure values such as temperature, light intensity, sound level, and gas concentration.

Digital Signal

digital signal has only two possible states: HIGH (1) and LOW (0). It does not vary continuously like an analog signal. Digital sensors provide discrete outputs that are read using the digital input pins of a microcontroller. These signals are commonly used for detecting conditions such as motion, touch, button presses, or object presence.

ADC (Analog-to-Digital Converter)

ADC (Analog-to-Digital Converter) is an electronic circuit that converts an analog signal (continuous voltage) into a digital value (binary number) that a microcontroller can understand and process.

some types of sensors and their information

1.LDR (Light Dependent Resistor)

What it Measures

An LDR (Light Dependent Resistor) measures the intensity of light falling on its surface.

  • Bright light → Low resistance
  • Darkness → High resistance

Pin Connection

Bare LDR (2 Pins)

PinConnection
Pin 15V (through a resistor as a voltage divider)
Pin 2Arduino Analog Pin (A0) and GND through resistor

LDR Module

PinConnection
VCC3.3V–5V
GNDGND
AOAnalog Input (A0)
DODigital Input (D2, D3, etc.)

Output

  • Bare LDR: Analog
  • LDR Module: Analog (AO) and Digital (DO)

Working Principle

An LDR works on the principle of photoconductivity.

  • In darkness, very few electrons are free to conduct electricity, so the resistance is very high (up to several megaohms).
  • When light falls on the LDR, photons release more electrons inside the semiconductor material.
  • This increases conductivity and reduces the resistance.
  • The Arduino reads the change in voltage (using a voltage divider) and determines the light intensity.

Internal Structure

The internal parts of an LDR include:

  • Cadmium Sulfide (CdS) photosensitive layer
  • Interdigitated metal electrodes
  • Ceramic substrate
  • Transparent protective coating
  • Connecting leads

Applications

  • Automatic street lights
  • Solar garden lights
  • Mobile and laptop brightness control
  • Camera light meters
  • Security alarm systems
  • Light intensity measurement
  • Smart home lighting
  • Day/night detection systems

2.LM35 Temperature Sensor

What it Measures

The LM35 measures temperature.

  • Temperature Range: −55°C to +150°C
  • Accuracy: ±0.5°C (around 25°C)

Pin Connection

LM35 (Flat Side Facing You)

PinConnection
Pin 1 (VCC)4V–30V (5V with Arduino)
Pin 2 (VOUT)Arduino Analog Pin (A0)
Pin 3 (GND)Ground

Output

  • Analog

The LM35 provides an analog voltage proportional to the temperature.

  • 10 mV per °C
  • Example:
    • 25°C → 250 mV
    • 30°C → 300 mV
    • 100°C → 1000 mV (1 V)

Working Principle

The LM35 is a precision integrated-circuit temperature sensor.

  • It senses the surrounding temperature using semiconductor junctions.
  • As the temperature changes, the output voltage changes linearly.
  • The Arduino reads this analog voltage through an analog input pin and converts it into temperature.

Internal Structure

The LM35 consists of:

  • Temperature sensing transistor
  • Band-gap reference circuit
  • Signal amplifier
  • Voltage output stage
  • Protective silicon package

Applications

  • Digital thermometers
  • Weather stations
  • Air conditioning systems (HVAC)
  • Industrial temperature monitoring
  • Fire alarm systems
  • Battery temperature monitoring
  • Medical equipment
  • Arduino and IoT temperature projects

3.DHT11 Temperature and Humidity Sensor

What it Measures

The DHT11 measures:

  • Temperature: 0°C to 50°C
  • Relative Humidity: 20% to 90% RH

Pin Connection

DHT11 Sensor (4-Pin)

PinConnection
Pin 1 (VCC)3.3V–5V
Pin 2 (DATA)Arduino Digital Pin (e.g., D2)
Pin 3 (NC)Not Connected
Pin 4 (GND)Ground

Output

  • Digital

The DHT11 sends temperature and humidity values as digital data through a single-wire communication protocol.

Working Principle

The DHT11 contains two sensing elements:

  • humidity sensor that measures moisture in the air.
  • An NTC thermistor that measures temperature.

An internal 8-bit microcontroller reads both sensors, converts the values into digital data, and transmits them to the microcontroller through the DATA pin.

Internal Structure

The DHT11 consists of:

  • Humidity sensing element
  • NTC thermistor
  • 8-bit microcontroller (IC)
  • Signal processing circuit
  • Protective plastic housing

Applications

  • Weather stations
  • Smart home automation
  • HVAC (Heating, Ventilation, and Air Conditioning)
  • Greenhouse monitoring
  • IoT environmental monitoring
  • Indoor climate monitoring
  • Data logging systems
  • Educational Arduino projects

4.Ultrasonic Sensor

What it Measures

  • Distance to an object
  • Measuring Range: 2 cm to 400 cm (4 m)

Pin Connection

PinConnection
VCC5V
TRIGArduino Digital Output Pin
ECHOArduino Digital Input Pin
GNDGround

Output

  • Digital

Working Principle

The Arduino sends a 10 µs pulse to the TRIG pin. The sensor transmits 40 kHz ultrasonic waves through the transmitter. When the waves hit an object, they are reflected back to the receiver. The ECHO pin stays HIGH for the time taken by the sound wave to travel to the object and back. The Arduino calculates the distance using this time.

Internal Structure

  • Ultrasonic Transmitter (40 kHz)
  • Ultrasonic Receiver
  • Control IC
  • Oscillator Circuit
  • Signal Processing Circuit
  • PCB (Printed Circuit Board)

Applications

  • Obstacle detection
  • Robot navigation
  • Distance measurement
  • Parking assistance systems
  • Water level monitoring
  • Automatic door systems
  • Smart dustbins
  • Industrial automation

5.PIR (Passive Infrared) Motion Sensor

What it Measures

  • Motion by detecting changes in infrared (IR) radiation emitted by humans and animals.

Pin Connection

PinConnection
VCC5V (or 3.3V–5V depending on module)
OUTArduino Digital Pin
GNDGround

Output

  • Digital

Working Principle

The PIR sensor contains a pyroelectric sensor that detects changes in infrared radiation. When a warm object, such as a person, moves within its detection range, the infrared energy changes. The sensor processes this change and sets the OUT pin HIGH. When no motion is detected, the OUT pin remains LOW.

Internal Structure

  • Fresnel lens
  • Pyroelectric sensor
  • Dual sensing elements
  • Signal amplifier
  • Comparator circuit
  • Control IC
  • Sensitivity and delay adjustment potentiometers (on HC-SR501 module)

Applications

  • Motion detection systems
  • Burglar alarms
  • Automatic lighting
  • Smart home automation
  • Automatic doors
  • Security cameras
  • Energy-saving lighting systems
  • Occupancy detection

6.IR (Infrared) Sensor

What it Measures

  • Object detection
  • Obstacle detection
  • Proximity (short-distance detection)

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
OUTArduino Digital Pin

Note: Some IR sensor modules also provide an AO (Analog Output) pin.

Output

  • Digital (Most obstacle detection modules)
  • Analog and Digital (Some modules)

Working Principle

The IR sensor consists of an IR LED (transmitter) and an IR photodiode/phototransistor (receiver). The IR LED emits infrared light. When an object comes in front of the sensor, the IR light is reflected back to the receiver. The receiver detects the reflected light, and the control circuit changes the OUT pin to indicate the presence of an object.

Internal Structure

  • IR LED (Transmitter)
  • IR Photodiode/Phototransistor (Receiver)
  • LM393 Comparator IC
  • Signal Processing Circuit
  • Sensitivity Adjustment Potentiometer
  • PCB (Printed Circuit Board)

Applications

  • Obstacle avoidance robots
  • Line-following robots
  • Automatic doors
  • Object counting systems
  • Proximity sensing
  • Industrial automation
  • Security systems
  • Conveyor belt object detection

7.Soil Moisture Sensor

What it Measures

  • Soil moisture (water content in soil)

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
AOArduino Analog Pin (A0)
DOArduino Digital Pin (D2, D3, etc.)

Output

  • Analog (AO)
  • Digital (DO)

Working Principle

The soil moisture sensor has two metal probes that are inserted into the soil. A small current flows between the probes. Wet soil conducts electricity better than dry soil, so the sensor measures the change in electrical conductivity (or resistance). The module provides an analog output proportional to the moisture level and a digital output based on a user-adjustable threshold.

Internal Structure

  • Two metal probe electrodes
  • LM393 Comparator IC
  • Signal conditioning circuit
  • Sensitivity adjustment potentiometer
  • PCB (Printed Circuit Board)

Applications

  • Automatic plant watering systems
  • Smart irrigation systems
  • Agriculture monitoring
  • Greenhouse automation
  • Garden soil monitoring
  • IoT farming projects
  • Environmental monitoring

8.MQ-2 Gas Sensor

What it Measures

  • Smoke
  • LPG (Liquefied Petroleum Gas)
  • Propane
  • Methane (CH₄)
  • Hydrogen (H₂)
  • Alcohol vapors

Pin Connection

PinConnection
VCC5V
GNDGround
AOArduino Analog Pin (A0)
DOArduino Digital Pin (D2, D3, etc.)

Output

  • Analog (AO)
  • Digital (DO)

Working Principle

The MQ-2 sensor contains a tin dioxide (SnO₂) sensing element heated by an internal heater coil. In clean air, the sensor has high resistance. When combustible gases or smoke are present, the resistance of the sensing material decreases. The module converts this change into an analog voltage, while the LM393 comparator provides a digital output when the gas concentration exceeds the set threshold.

Internal Structure

  • Stainless steel mesh cover
  • Tin dioxide (SnO₂) sensing layer
  • Ceramic tube
  • Nickel-chromium (Ni-Cr) heating coil
  • LM393 comparator IC
  • Sensitivity adjustment potentiometer
  • PCB (Printed Circuit Board)

Applications

  • LPG gas leak detection
  • Smoke detection
  • Fire alarm systems
  • Home safety systems
  • Industrial gas monitoring
  • Air quality monitoring
  • Arduino and IoT gas detection projects

Group assignment

After studying the theory of different input sensors, we completed the Group Assignment. In this assignment, we explored different types of sensors, their internal structuresworking principlespin configurations, and whether they provide analog or digital outputs. We also learned what each sensor measures and discussed their real-world applications, which helped us understand how sensors are used in embedded systems and Arduino-based projects.

information of sensors we discussed

1.Rain Sensor

What it Measures

  • Rainfall
  • Water droplets on a surface
  • Moisture level

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
AOArduino Analog Pin (A0)
DOArduino Digital Pin (D2, D3, etc.)

Output

  • Analog (AO)
  • Digital (DO)

Working Principle

The rain sensor has a sensing plate with parallel conductive tracks. When raindrops fall on the plate, they connect the tracks, changing the electrical resistance (or conductivity). The module converts this change into an analog voltage, while the LM393 comparator provides a digital output when the water level exceeds the set threshold.

Internal Structure

  • Rain sensing plate (conductive tracks)
  • LM393 comparator IC
  • Signal conditioning circuit
  • Sensitivity adjustment potentiometer
  • PCB (Printed Circuit Board)

Applications

  • Automatic windshield wipers
  • Smart irrigation systems
  • Rain detection alarms
  • Weather monitoring stations
  • Smart windows
  • Home automation
  • Arduino and IoT weather projects

2.Hall Effect Sensor

What it Measures

  • Magnetic field
  • Presence of a magnet
  • Magnetic field strength (depending on the sensor type)

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
OUTArduino Digital Pin (or Analog Pin for analog Hall sensors)

Output

  • Digital (e.g., A3144 Hall Effect Sensor)
  • Analog (for linear Hall Effect sensors)

Working Principle

The Hall Effect sensor works on the Hall Effect principle. When a magnetic field is applied perpendicular to the sensor, it generates a small voltage (Hall voltage). The internal circuit detects this voltage and changes the output state. A digital Hall sensor outputs HIGH or LOW, while a linear Hall sensor provides an analog voltage proportional to the magnetic field strength.

Internal Structure

  • Hall sensing element
  • Signal amplifier
  • Comparator (digital sensors)
  • Voltage regulator
  • Output driver circuit

Applications

  • Speed measurement
  • Position sensing
  • Magnetic proximity detection
  • Brushless DC (BLDC) motors
  • Wheel speed sensors
  • Door open/close detection
  • Industrial automation
  • Arduino and IoT projects

3.Flame Sensor

What it Measures

  • Flame
  • Infrared (IR) radiation emitted by fire

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
AOArduino Analog Pin (A0)
DOArduino Digital Pin (D2, D3, etc.)

Output

  • Analog (AO)
  • Digital (DO)

Working Principle

The flame sensor uses an infrared (IR) photodiode that is highly sensitive to the infrared light emitted by flames (typically in the 760–1100 nm wavelength range). When a flame is detected, the sensor generates an electrical signal. The module provides an analog output based on flame intensity and a digital output through the LM393 comparator when the flame exceeds the set threshold.

Internal Structure

  • IR photodiode (flame detector)
  • LM393 comparator IC
  • Signal conditioning circuit
  • Sensitivity adjustment potentiometer
  • PCB (Printed Circuit Board)

Applications

  • Fire detection systems
  • Fire alarm systems
  • Industrial safety monitoring
  • Flame detection in gas burners
  • Smart home safety systems
  • Arduino and IoT fire detection projects.

4.Sound Sensor

What it Measures

  • Sound intensity
  • Noise level
  • Clap or sound detection

Pin Connection

PinConnection
VCC3.3V–5V
GNDGround
AOArduino Analog Pin (A0)
DOArduino Digital Pin (D2, D3, etc.)

Output

  • Analog (AO)
  • Digital (DO)

Working Principle

The sound sensor uses an electret condenser microphone to detect sound waves. The microphone converts sound vibrations into electrical signals. These signals are amplified and sent to the analog output, while the LM393 comparator generates a digital output when the sound level exceeds the set threshold.

Internal Structure

  • Electret condenser microphone
  • Signal amplifier
  • LM393 comparator IC
  • Sensitivity adjustment potentiometer
  • PCB (Printed Circuit Board)

Applications

  • Clap switch
  • Noise level monitoring
  • Voice detection
  • Security alarm systems
  • Sound-activated lighting
  • Smart home automation
  • Arduino and IoT projects

Group assignment

1.comparision of DHT 11 and DHT 22

After studying different input sensors, we performed a Group Assignment in which we compared the DHT11 and DHT22 temperature and humidity sensors. We analyzed their measurement accuracy, temperature and humidity ranges, pin configurations, operating voltage, and current consumption. We interfaced both sensors with an Arduino Uno and an ESP32-WROOM to observe their performance on different microcontroller platforms. This comparison helped us understand the advantages and limitations of each sensor and identify the most suitable sensor for different embedded and IoT applications..

FeatureDHT11DHT22
Temperature Range0°C to 50°C-40°C to 80°C
Humidity Range20–90% RH0–100% RH
AccuracyLower (±2°C, ±5% RH)Higher (±0.5°C, ±2% RH)
OutputDigitalDigital
Operating Voltage3.3V–5.5V3.3V–6V
Current Consumption~0.5 mA~1.5 mA
PinsVCC, DATA, NC, GNDVCC, DATA, NC, GND
CostLowerHigher

Tested with

  • Arduino Uno
  • ESP32-WROOM

During the group assignment, both sensors were interfaced with Arduino Uno and ESP32-WROOM, and their temperature and humidity readings, operating voltage, current consumption, and accuracy were compared. The DHT22 provided more accurate readings and a wider measurement range, while the DHT11 was suitable for basic, low-cost applications.

2.measuring of current and voltage of IR sensor

After comparing the DHT11 and DHT22 sensors, we measured the operating voltage and current of an IR sensor using an Arduino Uno and a digital multimeter. We connected the IR sensor to the Arduino Uno, measured the supply voltage across the sensor, and measured the current consumed during operation. This activity helped us understand the electrical characteristics and power consumption of the IR sensor in a practical embedded system.

connecting IR sensor to arduino uno and start measuring current and voltage

Group assignment

oscilloscope

digital waves on oscilloscope

After completing the sensor experiments, we learned how to use an oscilloscope to observe electrical signals. We connected an LED to an Arduino Uno and uploaded a simple LED Blink program. To observe the signal, we connected the oscilloscope probe tip to the positive terminal (anode) of the LED and the ground (crocodile) clip to the negative terminal (cathode/GND).

After adjusting the oscilloscope settings, such as the time/div and voltage/div, we observed the LED’s digital signal waveform. The waveform alternated between HIGH (5 V) and LOW (0 V), producing a square wave that matched the LED blinking pattern. As part of the group assignment, we captured and analyzed the digital waveform, helping us understand how digital signals appear on an oscilloscope and how they relate to the operation of a microcontroller..

Experience

This activity gave me my first practical experience using an oscilloscope. I learned how to connect the probe correctly, adjust the oscilloscope settings, and observe digital signals generated by an Arduino Uno. By uploading the LED blink program, I was able to see the HIGH and LOW states as a square waveform on the oscilloscope screen. This experiment helped me understand the relationship between the Arduino program and the actual electrical signal. It also improved my confidence in using measurement instruments and analyzing digital waveforms in embedded systems.

Individual Assignment

In my individual assignment, I connected different types of sensors to the Arduino Uno and Seeed XIAO ESP32-C3. I uploaded the code for each sensor and checked whether it was working correctly. Through this activity, I learned how to connect sensors, read their outputs, and fix simple wiring and coding problems. This hands-on practice helped me understand how sensors work with different microcontroller boards.

sensors connection with arduino uno

1.PIR Sensor and Buzzer

First, I connected a PIR motion sensor and a buzzer to the Arduino Uno. I uploaded the Arduino code and tested the circuit. When the PIR sensor detected motion, the buzzer turned ON, and when no motion was detected, the buzzer turned OFF. This activity helped me understand how a motion sensor detects movement and how it can be used to control an output device such as a buzzer.

code for PIR motion sensor

// PIR Motion Sensor with Buzzer

const int pirPin = 2; // PIR sensor OUT pin
const int buzzerPin = 8; // Buzzer pin

void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}

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

if (motion == HIGH) {
Serial.println(“Motion Detected!”);

// Beep 5 timesfor (int i = 0; i < 5; i++) {  digitalWrite(buzzerPin, HIGH);  delay(200);  digitalWrite(buzzerPin, LOW);  delay(200);}

} else {
digitalWrite(buzzerPin, LOW);
Serial.println(“No Motion”);
}

delay(100);
}

2.Sound Sensor and Buzzer

Next, I connected a sound sensor and a buzzer to the Arduino Uno. I uploaded the Arduino code and tested the circuit. The sound sensor detected sounds such as a clap, and when the sound level crossed the set threshold, the buzzer turned ON. This activity helped me understand how a sound sensor detects noise and how its output can be used to control other electronic devices.

code for sound sensor

const int soundPin = 2;
const int buzzerPin = 8;

void setup() {
pinMode(soundPin, INPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
Serial.begin(9600);
}

void loop() {
if (digitalRead(soundPin) == HIGH) {

Serial.println("Clap Detected!");digitalWrite(buzzerPin, HIGH);delay(500);                 // Buzzer ON for 0.5 seconddigitalWrite(buzzerPin, LOW);// Wait until sound sensor output becomes LOWwhile (digitalRead(soundPin) == HIGH) {  delay(10);}delay(200); // Debounce

}
}

3.Ultrasonic Sensor and Buzzer

Next, I connected an ultrasonic sensor and a buzzer to the Arduino Uno. After uploading the Arduino code, I tested the circuit by placing an object in front of the sensor. The ultrasonic sensor measured the distance to the object, and when the object came within the set distance, the buzzer turned ON. When the object moved away, the buzzer turned OFF. This activity helped me understand how ultrasonic sensors measure distance and how they can be used for obstacle detection.

code for ultrasonic sensor

// HC-SR04 Ultrasonic Sensor + Active Buzzer

const int trigPin = 9;
const int echoPin = 10;
const int buzzerPin = 8;

long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);

Serial.begin(9600);
}

void loop() {

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

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

digitalWrite(trigPin, LOW);

// Read echo
duration = pulseIn(echoPin, HIGH);

// Calculate distance (cm)
distance = duration * 0.034 / 2;

Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” cm”);

if (distance <= 10) {
// Object very close -> Continuous buzzer
digitalWrite(buzzerPin, HIGH);
}
else if (distance <= 20) {
// Medium distance -> Fast beep
digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);
delay(100);
}
else if (distance <= 30) {
// Farther away -> Slow beep
digitalWrite(buzzerPin, HIGH);
delay(300);
digitalWrite(buzzerPin, LOW);
delay(300);
}
else {
// No nearby object
digitalWrite(buzzerPin, LOW);
}

delay(50);
}

4.MQ-2 Smoke Sensor and Buzzer

Next, I connected an MQ-2 smoke sensor and a buzzer to the Arduino Uno. After uploading the Arduino code, I tested the circuit by bringing smoke near the sensor. When the sensor detected smoke, the buzzer turned ON to indicate the presence of smoke. When the smoke was removed, the buzzer turned OFF. This activity helped me understand how a gas and smoke sensor works and how it can be used in smoke detection and fire safety applications.

code for gas sensor

// MQ-2 Gas Sensor with Active Buzzer

const int gasPin = 2; // MQ-2 Digital Output (DO)
const int buzzerPin = 8; // Active Buzzer

void setup() {
pinMode(gasPin, INPUT);
pinMode(buzzerPin, OUTPUT);

digitalWrite(buzzerPin, LOW);

Serial.begin(9600);
}

void loop() {

int gas = digitalRead(gasPin);

if (gas == LOW) { // MQ-2 modules usually output LOW when gas is detected
Serial.println(“Gas Detected!”);
digitalWrite(buzzerPin, HIGH);
}
else {
Serial.println(“Air Normal”);
digitalWrite(buzzerPin, LOW);
}

delay(100);
}

5.Float Sensor and Buzzer

Next, I connected a float sensor and a buzzer to the Arduino Uno. After uploading the Arduino code, I tested the circuit by changing the water level. When the water reached the set level, the float sensor detected it and the buzzer turned ON. When the water level dropped, the buzzer turned OFF. This activity helped me understand how a float sensor can be used to monitor water levels and give an alert when the tank is full or reaches a specific level.

code for float sensor

// Float Sensor + Active Buzzer

const int floatPin = 2;
const int buzzerPin = 8;

void setup() {
pinMode(floatPin, INPUT_PULLUP); // Internal pull-up resistor
pinMode(buzzerPin, OUTPUT);

digitalWrite(buzzerPin, LOW);

Serial.begin(9600);
}

void loop() {

int waterLevel = digitalRead(floatPin);

if (waterLevel == LOW) { // Float switch closed
Serial.println(“Water Level HIGH”);
digitalWrite(buzzerPin, HIGH);
}
else {
Serial.println(“Water Level LOW”);
digitalWrite(buzzerPin, LOW);
}

delay(100);
}

6.RFID RC522

Next, I connected an RFID RC522 module to the Arduino Uno. After uploading the Arduino code, I tested the circuit by bringing an RFID card near the reader. When the card was detected, the Arduino read its unique ID (UID) and displayed it on the Serial Monitor. This activity helped me understand how RFID technology works and how it can be used for access control, attendance systems, and identification projects.

code for RFID

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();

Serial.println(“Scan your RFID card…”);
}

void loop() {

// Check if a new card is present
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Read the card
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

// Print UID
Serial.print(“Card UID: “);

for (byte i = 0; i < mfrc522.uid.size; i++) {
if (mfrc522.uid.uidByte[i] < 0x10)
Serial.print(“0”);

Serial.print(mfrc522.uid.uidByte[i], HEX);Serial.print(" ");

}

Serial.println();

// Stop reading
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();

delay(1000);
}

Experience with Arduino Uno

Working with the Arduino Uno gave me practical experience in connecting and testing different sensors. I learned how to make the correct wiring, upload programs, and read sensor outputs. While testing, I also faced some wiring and coding errors, but I solved them by checking the connections and debugging the code. Through these experiments, I gained a better understanding of how sensors communicate with a microcontroller and how Arduino can be used to build simple embedded system projects. This hands-on practice improved my confidence in working with electronic circuits and sensors.

sensors connection with seeed XIAO ESP32 C3

Individual Assignment – XIAO ESP32-C3

After completing the Arduino Uno tasks, my individual assignment was to connect different sensors with the Seeed XIAO ESP32-C3. I connected the sensors, uploaded the programs, and tested their outputs. Through this activity, I learned how to interface sensors with the XIAO ESP32-C3, understand its pin configuration, and compare it with the Arduino Uno. This assignment helped me become familiar with another microcontroller board and improved my embedded programming skills..

1.Ultrasonic Sensor

First, I connected an ultrasonic sensor and a buzzer to the Seeed XIAO ESP32-C3. After uploading the code, I tested the circuit by placing an object in front of the sensor. The ultrasonic sensor measured the distance, and when the object came within the set range, the buzzer turned ON. When the object moved away, the buzzer turned OFF. This activity helped me understand how to interface an ultrasonic sensor with the XIAO ESP32-C3 and use it for distance and obstacle detection.

code for ultrasonic sensor

// XIAO ESP32-C3 + HC-SR04 + Buzzer

#define TRIG_PIN 2
#define ECHO_PIN 3
#define BUZZER_PIN 4

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

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

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

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

digitalWrite(TRIG_PIN, LOW);

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

// Calculate distance (cm)
float distance = duration * 0.0343 / 2;

Serial.print(“Distance: “);
Serial.print(distance);
Serial.println(” cm”);

// Turn buzzer ON if object is within 20 cm
if (distance > 0 && distance <= 20) {
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(BUZZER_PIN, LOW);
}

delay(200);
}

2.PIR Sensor

PIR Sensor and Buzzer with XIAO ESP32-C3

Next, I connected a PIR motion sensor and a buzzer to the Seeed XIAO ESP32-C3. After uploading the code, I tested the circuit by moving in front of the sensor. When the PIR sensor detected motion, the buzzer turned ON. When no motion was detected, the buzzer turned OFF. This activity helped me understand how to interface a PIR sensor with the XIAO ESP32-C3 and use it for simple motion detection and alert systems.

code for PIR motion sensor

// XIAO ESP32-C3
// PIR Sensor + Buzzer

const int pirPin = 2; // PIR OUT connected to GPIO2
const int buzzerPin = 3; // Buzzer connected to GPIO3

void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(115200);
}

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

if (motion == HIGH) {
digitalWrite(buzzerPin, HIGH);
Serial.println(“Motion Detected!”);
} else {
digitalWrite(buzzerPin, LOW);
Serial.println(“No Motion”);
}

delay(100);
}

3.Sound Sensor

Next, I connected a sound sensor and a buzzer to the Seeed XIAO ESP32-C3. I wrote and uploaded the Arduino code to the board and tested the circuit. When the sound sensor detected a loud sound, such as a clap, it sent a signal to the XIAO ESP32-C3, which turned the buzzer ON. When no sound was detected, the buzzer remained OFF. This activity helped me understand how to interface a sound sensor with the XIAO ESP32-C3 and how sensor inputs can be used to control output devices through programming.

code for sound sensor

// XIAO ESP32-C3
// Sound Sensor + Buzzer

const int soundPin = 2; // Sound sensor DO pin
const int buzzerPin = 3; // Buzzer pin

void setup() {
pinMode(soundPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(115200);
}

void loop() {
int sound = digitalRead(soundPin);

if (sound == HIGH) { // Sound detected
digitalWrite(buzzerPin, HIGH);
Serial.println(“Sound Detected!”);
} else {
digitalWrite(buzzerPin, LOW);
Serial.println(“No Sound”);
}

delay(100);
}

4.MQ-7 Gas Sensor and Buzzer

Next, I connected an MQ-7 gas sensor and a buzzer to the Seeed XIAO ESP32-C3. After uploading the Arduino code, I tested the circuit by exposing the sensor to carbon monoxide (CO) gas in a controlled manner. When the gas concentration exceeded the set threshold, the sensor sent a signal to the XIAO ESP32-C3, and the buzzer turned ON. When the gas level dropped below the threshold, the buzzer turned OFF. This activity helped me understand how a gas sensor detects harmful gases and how it can be used to create simple gas leakage and safety alert systems.

code for gas sensor

// XIAO ESP32-C3
// MQ-7 Gas Sensor + Buzzer

const int gasPin = 2; // MQ-7 DO pin connected to GPIO2
const int buzzerPin = 3; // Buzzer connected to GPIO3

void setup() {
pinMode(gasPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(115200);
}

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

if (gasState == LOW) { // Gas detected (most MQ-7 modules output LOW when gas is detected)
digitalWrite(buzzerPin, HIGH);
Serial.println(“Gas Detected!”);
} else {
digitalWrite(buzzerPin, LOW);
Serial.println(“Air is Clean”);
}

delay(100);
}

5.Float Sensor and Buzzer

Next, I connected a float sensor and a buzzer to the Seeed XIAO ESP32-C3. After uploading the Arduino code, I tested the circuit by changing the water level. When the water reached the set level, the float sensor detected it and sent a signal to the XIAO ESP32-C3, which turned the buzzer ON. When the water level dropped, the buzzer turned OFF. This activity helped me understand how a float sensor can be used to monitor water levels and provide an alert when the tank is full or reaches a specific level.

code for float sensor

// XIAO ESP32-C3
// Float Sensor + Buzzer

const int floatPin = 2; // Float sensor connected to GPIO2
const int buzzerPin = 3; // Buzzer connected to GPIO3

void setup() {
pinMode(floatPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
Serial.begin(115200);
}

void loop() {
int waterLevel = digitalRead(floatPin);

if (waterLevel == LOW) { // Water level reached
digitalWrite(buzzerPin, HIGH);
Serial.println(“Water Level High!”);
} else {
digitalWrite(buzzerPin, LOW);
Serial.println(“Water Level Normal”);
}

delay(100);
}

Experience with XIAO ESP32-C3

Working with the Seeed XIAO ESP32-C3 was a good learning experience. I connected different sensors, uploaded the code, and tested each circuit. I learned how to connect sensors correctly, use the GPIO pins, and check the sensor outputs. I also fixed some small wiring and coding mistakes during testing. This activity helped me improve my programming and hardware skills and gave me more confidence in using the XIAO ESP32-C3 for embedded system projects.

Overall Experience

This week was very useful because I learned about different types of input sensors and how they work. I studied their working principles, internal structures, pin connections, and analog and digital outputs. During the group assignment, I compared the DHT11 and DHT22 sensors, measured voltage and current, and learned how to use an oscilloscope to observe digital signals. In the individual assignment, I connected different sensors with the Arduino Uno and Seeed XIAO ESP32-C3, uploaded the code, and tested their outputs. These activities improved my understanding of sensors, microcontrollers, circuit connections, and programming. Overall, this week gave me valuable hands-on experience and increased my confidence in working on embedded system projects.

End of week 3 ..