Comprehensive Assignments, Mathematical Modeling, Circuit Simulations & STM32 Firmware
This repository contains homework assignments, mathematical modeling, circuit schematics, Proteus simulations, and STM32 C firmware for the Instrumentation course taught by Dr. Mohammadreza Nayeri at the University of Tehran (Spring 1405 / 2026). The projects cover sensor calibration, signal conditioning, active filtering, data acquisition, and embedded microcontroller control.
Topic: Statistical analysis of sensor data, calibration, and error modeling.
- Q1: Statistical analysis of raw sensor data (Mean, Variance, Standard Error).
- Q2 & Q3: Least Squares (LS) and Recursive Least Squares (RLS) fitting (degrees 1, 3, 9) and convergence rate comparison.
- Q4: Hysteresis analysis and calculation of %FS hysteresis error.
-
Q5: Thermal drift rate quantification (Zero Drift
$8\text{ mV/}^\circ\text{C}$ , Sensitivity Drift $-2\text{ mV/(mm}\cdot^\circ\text{C})$) and 2nd-order dynamic system identification. π Read HW1 Full README
Topic: Modeling measurement systems, Op-Amps, active filters, and bio-potential amplifiers.
-
Q1: 1st and 2nd order system modeling in Simulink and
$50\text{ Hz}$ LC Notch filter noise suppression. - Q2: Multi-stage LM324 Op-Amp comparator circuit for NTC thermistor temperature thresholding.
- Q3: 4-Bit R-2R DAC, 74HC161 staircase generator, RC low-pass filter, and 74HC191 Up/Down counter triangular wave generator.
-
Q4: 4-Stage ECG Bio-Potential Instrumentation Amplifier (
$5000\times$ Gain,$10-100\text{ Hz}$ BPF, CMRR$50\text{ Hz}$ noise rejection, AD620 Wheatstone bridge). π Read HW2 Full README
Topic: Embedded C programming with STM32CubeMX, Timers, EXTI interrupts, and ADC classifiers.
-
Q1: Common Cathode 7-Segment Elevator floor display with zero-latency EXTI emergency holds (
PB1/PB2). -
Q2:
$1\text{ kHz}$ TIM2 PWM DC Motor speed scaling via 12-bit ADC and L298 driver direction toggling. -
Q3: Precision
$500\text{ ms}$ TIM3 Timer Interrupt countdown system with 16x2 LCD display,$1\text{ Hz}$ alarm, and reset switch. - Q4: Automatic Industrial Sensor Classifier (LM35 Temp, HIH-4000 Humidity, MPX4115 Pressure, MQ-135 Gas) via 12-bit ADC. π Read HW3 Full README
Topic: Transducer physics (RTD, Thermocouple, Thermistor), I2C digital sensors, and loadcell digital scale.
-
Q1: Multi-sensor temperature characterization (PT100 4-wire RTD
$1\text{ mA}$ current loop, Type K Seebeck amplifier$A_v=100$ , NTC Thermistor$\beta=4804\text{ K}$ ). - Q2: I2C Communication with LM75 digital temperature sensor (`0.5^\circ\text{C}$ resolution) and LCD integration.
-
Q3: Load Cell & Digital Scale implementation (
$0-2\text{ kg}$ Loadcell, 3-Op-Amp Inst Amp$A_v=500$ , 2nd-order damped vibration simulation, active LPF$f_c=0.5\text{ Hz}$ , EXTI zero-offset Tare calibration). π Read HW4 Full README
Topic: Electromechanical actuation, Time-of-Flight rangefinding, Optocounters, and Quadrature Encoder decoding.
- Q1: DC Motor speed and direction control using L293D H-Bridge driver and PWM duty cycle modulation.
-
Q2: Solar Tracker Panel angle control using
$1.8^\circ$ Stepper Motor and ULN2003A driver (Manual mode, Auto tracking$1.8^\circ / 2\text{ s}$ , high-speed$10\text{ ms}$ Reset rewind, Full-Step vs Half-Step analysis). -
Q3: ToF Ultrasonic Distance Meter (
$d = \frac{t \cdot 0.034}{2}\text{ cm}$ ) and active reflection IR proximity obstacle sensor. -
Q4: Potentiometer angle sensing (
$0.0659^\circ$ resolution), Optocounter speed sensing ($N = 23$ slots), and Incremental Rotary Encoder Quadrature Decoding (1x, 2x, and 4x modes down to$0.342^\circ$ resolution). π Read HW5 Full README
Topic: Gas chemiresistors, single-wire climate sensors, turbine flow meters, and USART serial telemetry.
-
Q1: MQ-4 Methane/Natural Gas Sensor (
$\text{SnO}_2$ heated semiconductor physics) with$D_0$ digital leak alarm. -
Q2: DHT11 Climate Controller with non-blocking multi-menu LCD interface, proportional PWM fan speed control (
$\Delta T$ ), and independent heater/humidifier feedback. -
Q3: LDR Light Module sensitivity thresholding (
$SRV = 10\text{ k}\Omega$ , Threshold = 1, 3, 5). -
Q4: Turbine/Hall-Effect Pulse Flow Rate Meter (
$f = 7.5 Q \implies Q = \frac{f}{7.5}\text{ L/min}$ ). - Q5: MPX4115 Absolute Pressure Sensor ($V_{\text{out}} = V_s(0.009P - 0.095)$) with 12-bit ADC quantization.
-
Q6: Industrial Water Tank Liquid Level Control (
$< 25%$ critical threshold, L293D DC motor pump, dual status LEDs). -
Q7: BMP180 Barometric Pressure & Altitude Sensor ($h = 44330 \left(1 - (P/P_0)^{0.1903}\right)$) with USART1 Virtual Terminal stream and
$>40^\circ\text{C}$ over-temperature warnings. π Read HW6 Full README
| Category | Tools & Hardware |
|---|---|
| Microcontrollers | STM32F103C8T6 (Blue Pill), STM32F103R6 (ARM Cortex-M3) |
| IDE & Toolchain | STM32CubeIDE, Keil uVision, STM32CubeMX |
| Simulation | Proteus 9 Professional, MATLAB R2025b, Simulink |
| Libraries | STM32 HAL Library, CMSIS |
| Sensors | DHT11, BMP180, HC-SR04, Sharp IR, MQ-4, MQ-135, LM75, PT100 RTD, Type K Thermocouple, NTC Thermistor, LDR, Load Cell, Hall Flow Turbine |
| Actuators & Drivers | DC Motors, Servo Motors, 1.8Β° Stepper Motors, L298 H-Bridge, L293D H-Bridge, ULN2003A Darlington Array |
Instrumentation-Course-Spring05/
βββ HW1/ # Sensor Data Analysis & Curve Fitting (MATLAB)
βββ HW2/ # Simulink & Proteus Active Filters, Op-Amps & ECG Amplifier
βββ HW3/ # Timers, EXTI Interrupts, PWM Motor & ADC Sensor Classifier
βββ HW4/ # Temperature Sensors, LM75 I2C & Digital Scale
βββ HW5/ # DC/Stepper Motors, Ultrasonic/IR & 4x Encoder Decoding
βββ HW6/ # Advanced Environmental Sensors, DHT11 & BMP180 Altitude
βββ LICENSE # MIT License
βββ README.md # Main Repository README
cd HW1/
run curveFit.m % Or any other script- Open target project in STM32CubeIDE.
- Load the corresponding
.iocconfiguration file. - Build project (
Ctrl + B) to generate output.hexbinary.
- Open the
.pdsprjfile in Proteus 9 Professional. - Assign the compiled
.hexfile to the microcontroller component. - Click Play to start the simulation.
Each homework directory includes complete, professionally written LaTeX PDF reports:
HW1/Inst-HW1-810102443.pdfHW2/Instr-HW2-810102443.pdfHW3/Inst-HW3-810102443.pdfHW4/Instr-HW4-810102443.pdfHW5/Report.pdfHW6/Report.pdf
Amirali Dehghani | Electrical Engineering Student (Control)
University of Tehran, School of Electrical & Computer Engineering
This project is licensed under the MIT License. See the LICENSE file for details.
β If you found this repository helpful, please give it a star!