You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Homework 6 covers industrial environmental monitoring, fluid flow measurement, gas detection, multi-menu closed-loop control systems, and serial communication protocols:
MQ-4 Methane/Natural Gas Sensor (SnO2 Semiconductor): Principles of tin-dioxide chemiresistors, surface oxygen electron trapping, $D_0$ digital comparator thresholding, and leak alarm LED actuation.
DHT11 Climate Monitoring & Non-Blocking Multi-Menu Controller: Single-wire 40-bit digital protocol, LCD state machine (Default, Set Temp Menu, Set Humid Menu), proportional PWM fan speed control ($\Delta T$), and independent heater/humidifier closed-loop feedback.
MPX4115 Absolute Pressure Sensor Interfacing: Piezoresistive transfer function ($V_{\text{out}} = V_s(0.009P - 0.095)$), 12-bit ADC quantization, and $1\text{ s}$ interval LCD pressure display.
Industrial Water Tank Level Control & Automated Pump System: ADC tank level monitoring ($0 - 100%$), dual-LED state indicators (Red Low Alarm vs. Green Normal), and automated L293D DC motor pump control ($< 25%$ threshold).
๐น Question 1: MQ-4 Methane/Natural Gas Sensor (SnO2 Semiconductor)
1. Sensing Mechanism & Physics:
The MQ-4 sensor utilizes a heated Tin Dioxide ($\text{SnO}_2$) semiconductor surface:
Clean Air: An internal $5\text{ V}$ heater warms the $\text{SnO}_2$ layer. Oxygen molecules adsorb onto the surface, trapping free conduction electrons and creating a high electrical resistance barrier.
Gas Detection ($\text{CH}_4$ Methane): When methane or natural gas comes into contact with the heated surface, it chemically reacts with the adsorbed oxygen, releasing trapped electrons back into the conduction band. The sensor resistance drops drastically in proportion to gas concentration.
2. Interface Architecture:
Analog Output ($A_0$): Continuous voltage signal proportional to gas concentration.
Digital Output ($D_0$): LM393 comparator output toggles HIGH when concentration exceeds the potentiometer threshold.
STM32 Firmware Logic:PA0 (GPIO Input) reads $D_0$; if gas leak detected (1), PA1 turns ON the Red Alarm LED.
Figure 1.1: MQ-4 Sensor Module Pinout
Figure 1.2 Proteus Circuit Schematic
Figure 1.3: Clean Air State (LED OFF)
Figure 1.4: Gas Leak Detected (LED ON Alarm)
๐น Question 2: DHT11 Climate Controller & Non-Blocking Multi-Menu System
1. DHT11 Communication Protocol:
Single-Wire Digital Protocol: MCU initiates transfer with an $18\text{ ms}$ LOW pulse. The DHT11 responds with a 40-bit data packet:
Mode 2 (Set Humidity Menu):PB0 (Up) and PB1 (Down) adjust target humidity. Pressing PB2 returns to Mode 0.
3. Closed-Loop Feedback Control Logic:
Heater (PA1 Red LED): Turned ON if $T_{\text{measured}} < T_{\text{target}}$, otherwise OFF.
Humidifier (PA2 Blue LED): Turned ON if $H_{\text{measured}} < H_{\text{target}}$, otherwise OFF.
Ventilation Fan (DC Motor PWM on PA3): Turned ON if $T_{\text{measured}} > T_{\text{target}}$. Speed is proportionally modulated using TIM2 PWM; duty cycle increases linearly with temperature error ($T_{\text{measured}} - T_{\text{target}}$).
Highest Sensitivity: Triggers LED ON under slight light increases.
`Val: 0.33V
Threshold = 3
$0.99\text{ V}$
$1228$
Medium Sensitivity: Requires normal room ambient illumination.
`Val: 0.99V
Threshold = 5
$1.32\text{ V}$
$1638$
Lowest Sensitivity: Requires intense direct light source to switch.
`Val: 1.32V
Figure 3.1: LDR Module Circuit Schematic
Figure 3.2: Threshold = 1 Test
Figure 3.3: Threshold = 3 Test
Figure 3.4: Threshold = 5 Test
๐น Question 4: Turbine/Hall-Effect Pulse Flow Rate Meter
1. Flow Rate Conversion Physics:
Fluid flowing through the pipe spins an internal turbine wheel equipped with permanent magnets. A Hall Effect sensor detects each passing magnet, generating a square-wave pulse sequence whose frequency $f$ ($\text{Hz}$) is directly proportional to volumetric flow rate $Q$ ($\text{L/min}$):
According to the MPX4115 datasheet ($V_s = 5.0\text{ V}$ supply):
$$V_{\text{out}} = V_s \times (0.009 \cdot P - 0.095) \implies P = \frac{\frac{V_{\text{out}}}{V_s} + 0.095}{0.009} \quad [\text{kPa}]$$
2. STM32 Quantization & Simulation Results:
ADC1 12-bit on PA0 ($V_{\text{ref}} = 5.0\text{ V}$): $V_{\text{out}} = \text{ADC} \times \frac{5.0}{4095}$. Pressure is updated on the 16x2 LCD every $1\text{ second}$.
Applied Pressure ($P$)
Analog Voltage ($V_{\text{out}}$)
LCD Readout
Accuracy Verification
$26.4\text{ kPa}$
$0.713\text{ V}$
Pressure: / 26.40 kPa
Exact Datasheet Match
$50.0\text{ kPa}$
$1.775\text{ V}$
Pressure: / 50.00 kPa
Exact Datasheet Match
$59.8\text{ kPa}$
$2.216\text{ V}$
Pressure: / 59.80 kPa
Exact Datasheet Match
Figure 5.1: MPX4115 Sensor Circuit Schematic
Figure 5.2: $26.4\text{ kPa}$ Pressure Reading
Figure 5.3: $59.8\text{ kPa}$ Pressure Reading
๐น Question 6: Industrial Water Tank Level Control & Automated Pump System
1. System Logic & Thresholding:
Water Level Sensor: Potentiometer on PA0 (ADC1 12-bit) simulates tank filling level ($0 - 100%$).
Critical Low State ($< 25%$ Level): L293D DC motor pump (PA3) turns ON, Red Warning LED (PA1) turns ON, Green LED turns OFF.
Normal State ($\ge 25%$ Level): Pump turns OFF, Green LED (PA2) turns ON, Red LED turns OFF.
Real-Time LCD Display: Line 1: Level: XX.X%, Line 2: Pump: ON or OFF.
Figure 6.1: Tank Level Controller Schematic
Figure 6.2: Critical State ($20.0%$ Level, Pump ON, Red LED)
Figure 6.3: Normal State ($80.0%$ Level, Pump OFF, Green LED)
The BMP180 measures barometric pressure $P$ ($\text{hPa}$) via I2C bus (PB6 SCL, PB7 SDA). The estimated altitude above sea level $h$ ($\text{m}$) is calculated using the simplified barometric formula ($P_0 = 1013.25\text{ hPa}$):