Basic Electronics & Physics
Solid State Physics, Electronics & Digital Systems
From semiconductor physics to Arduino sensors โ master the complete foundation of modern electronics engineering across 6 comprehensive units.
โฑ๏ธ 30+ hrs | ๐ฏ GATE ~8โ12 marks | ๐ฐ โน5โ15 LPA | ๐ฌ VLSI to IoT
Solid State Physics
๐ฌ How a Grain of Silicon Powers Your Entire World
In 2024, Intel announced a $33 billion investment to build chip fabrication plants. Meanwhile, India's Semi-Conductor Laboratory (SCL) Mohali is being upgraded under the India Semiconductor Mission. Every smartphone, laptop, and satellite โ from your โน10,000 Redmi phone to ISRO's NavIC satellites โ runs on the physics you're about to learn.
A single modern processor contains 100+ billion transistors, each just 3 nanometers wide (30 atoms!). All of this is possible because of solid state physics โ the science of how electrons behave inside crystalline solids.
Free Electron Theory (Drude Model)
The free electron theory, proposed by Paul Drude in 1900, treats valence electrons in a metal as a "gas" of free particles that can move through the crystal lattice.
Key Assumptions of the Drude Model
- Valence electrons are free to move throughout the metal (they are not bound to any particular atom).
- Electrons do not interact with each other (independent electron approximation).
- Electrons collide with ion cores (lattice atoms), not with each other. The average time between collisions is the relaxation time $\tau$.
- After each collision, the electron's velocity is randomized โ it "forgets" its previous direction.
- Between collisions, electrons obey Newton's laws (classical mechanics).
Drift Velocity and Drift Current
Without an external field, electrons move randomly with zero net displacement. When an electric field $\vec{E}$ is applied, electrons acquire a small drift velocity $v_d$ superimposed on their random motion:
$$v_d = \frac{eE\tau}{m_e}$$where $e$ = electron charge, $m_e$ = electron mass, $\tau$ = relaxation time.
The drift current density is:
$$J = nev_d = \frac{ne^2\tau}{m_e}E = \sigma E$$where $n$ = number density of free electrons and $\sigma = \frac{ne^2\tau}{m_e}$ is the electrical conductivity.
Diffusion Current
When there is a concentration gradient of charge carriers (more electrons in one region than another), carriers diffuse from high to low concentration, creating a diffusion current:
$$J_{diff} = -qD_n\frac{dn}{dx} \quad \text{(for electrons)}$$ $$J_{diff} = qD_p\frac{dp}{dx} \quad \text{(for holes)}$$where $D_n, D_p$ are diffusion coefficients. The Einstein relation connects diffusion and mobility: $D = \frac{kT}{q}\mu$.
Fermi Energy & Fermi-Dirac Distribution
The Fermi energy $E_F$ is the highest energy level occupied by electrons at absolute zero (0 K). It represents the "top of the filled electron sea."
At any temperature $T$, the probability that a quantum state at energy $E$ is occupied is given by the Fermi-Dirac distribution function:
$$f(E) = \frac{1}{1 + e^{(E - E_F)/kT}}$$Key Properties of Fermi-Dirac Distribution
| Condition | f(E) | Meaning |
|---|---|---|
| $E = E_F$ | $\frac{1}{2}$ (always 50%) | Fermi level is the 50% probability point |
| $E \ll E_F$ | $\approx 1$ | States well below $E_F$ are fully occupied |
| $E \gg E_F$ | $\approx 0$ | States well above $E_F$ are empty |
| $T = 0$ K | Step function | All states below $E_F$ filled, all above empty |
| $T > 0$ K | Smooth curve | Some states near $E_F$ become partially occupied |
Band Theory of Solids
When atoms come together to form a solid, their discrete energy levels split into bands of closely spaced energy levels due to the interaction between atomic orbitals.
Formation of Energy Bands
Consider $N$ atoms of silicon brought together:
- Each atom has discrete energy levels (1s, 2s, 2p, 3s, 3p).
- As atoms approach, the Pauli exclusion principle forces the $N$ identical energy levels to split into $N$ closely spaced but distinct levels.
- These $N$ levels form a quasi-continuous band.
- The lower filled band = Valence Band (VB).
- The upper empty band = Conduction Band (CB).
- The gap between VB and CB = Forbidden Energy Gap ($E_g$).
| Material Type | Band Gap $E_g$ | Example | Behavior |
|---|---|---|---|
| Conductor | 0 eV (bands overlap) | Copper, Silver | Electrons flow freely |
| Semiconductor | 0.1 โ 3 eV | Si (1.1 eV), Ge (0.67 eV) | Conductivity increases with temperature |
| Insulator | > 3 eV | Diamond (5.5 eV), Glass | No conduction at room temp |
Concept of Effective Mass
Inside a crystal, an electron does not behave as a free particle because it interacts with the periodic potential of the lattice. We account for this by assigning it an effective mass $m^*$:
$$m^* = \frac{\hbar^2}{\frac{d^2E}{dk^2}}$$where $E$ is the electron energy and $k$ is the wave vector (from the E-k diagram).
- At the bottom of the conduction band, the band curves upward sharply โ small $m^*$ โ electrons are "light" and mobile.
- At the top of the valence band, the band curves downward โ negative $m^*$ โ this is mathematically treated as a positive particle called a hole.
Hall Effect (Complete Derivation)
The Hall effect, discovered by Edwin Hall in 1879, is used to determine the type (n or p), concentration, and mobility of charge carriers in a material.
Setup
Consider a rectangular conductor of width $w$, thickness $t$, carrying current $I$ along the x-direction. A magnetic field $\vec{B}$ is applied along the z-direction (perpendicular to the current).
Step-by-Step Derivation
Step 1: Electrons moving with drift velocity $v_d$ in the x-direction experience a Lorentz force:
$$\vec{F} = -e(\vec{v_d} \times \vec{B})$$This force pushes electrons toward one face of the conductor (say, the bottom face).
Step 2: Electrons accumulate on the bottom face, creating a transverse electric field $E_H$ (Hall field) pointing from top to bottom. This field exerts a force $eE_H$ on the electrons, opposing further accumulation.
Step 3: At equilibrium, the electric force balances the magnetic force:
$$eE_H = ev_dB$$ $$E_H = v_dB$$Step 4: The Hall voltage across the width $w$ is:
$$V_H = E_H \cdot w = v_d B w$$Step 5: Since current density $J = nev_d$ and $I = Jwt$, we get $v_d = \frac{I}{newt}$. Substituting:
$$\boxed{V_H = \frac{BI}{net}}$$Step 6: The Hall coefficient is defined as:
$$\boxed{R_H = \frac{1}{ne}} \quad \text{(for n-type: } R_H \text{ is negative)}$$ $$\boxed{R_H = \frac{1}{pe}} \quad \text{(for p-type: } R_H \text{ is positive)}$$Applications of the Hall Effect
- Determine carrier type: Sign of $V_H$ tells n-type vs p-type.
- Measure carrier concentration: $n = \frac{BI}{V_H e t}$.
- Calculate mobility: $\mu = |R_H| \sigma = \frac{|R_H|}{\rho}$.
- Hall sensors: Used in smartphones (compass), automotive (speed sensors), and brushless DC motors.
Solved Example: Hall Effect
Numerical Problem
Problem: A silicon sample has Hall coefficient $R_H = 3.66 \times 10^{-4}$ mยณ/C. If the conductivity is $\sigma = 112$ S/m, find: (a) carrier concentration, (b) carrier mobility.
Solution:
(a) $n = \frac{1}{R_H \cdot e} = \frac{1}{3.66 \times 10^{-4} \times 1.6 \times 10^{-19}} = 1.7 \times 10^{22}$ /mยณ
(b) $\mu = R_H \cdot \sigma = 3.66 \times 10^{-4} \times 112 = 0.041$ mยฒ/Vยทs $= 410$ cmยฒ/Vยทs
Semiconductors: Intrinsic & Extrinsic
Intrinsic Semiconductors
A pure semiconductor (no impurities). At 0 K, all valence band states are filled and the conduction band is empty โ it behaves as an insulator. At room temperature, thermal energy excites some electrons across the gap.
- Electron concentration = Hole concentration: $n_i = p_i$
- Fermi level lies approximately at the middle of the band gap: $E_F \approx \frac{E_C + E_V}{2}$
- Conductivity: $\sigma = n_i e(\mu_e + \mu_h)$
Extrinsic Semiconductors
Adding controlled impurities (doping) dramatically increases conductivity:
| Property | N-type | P-type |
|---|---|---|
| Dopant | Pentavalent (P, As, Sb) | Trivalent (B, Al, Ga, In) |
| Majority carrier | Electrons | Holes |
| Minority carrier | Holes | Electrons |
| Fermi level | Closer to conduction band | Closer to valence band |
| Dopant creates | Donor level near $E_C$ | Acceptor level near $E_V$ |
Direct vs Indirect Band Gap
| Property | Direct Band Gap | Indirect Band Gap |
|---|---|---|
| E-k diagram | CB minimum and VB maximum at same $k$ | CB minimum and VB maximum at different $k$ |
| Transition | Electron can directly emit/absorb photon | Requires phonon (lattice vibration) assist |
| Examples | GaAs, InP, GaN | Si, Ge |
| Applications | LEDs, Laser diodes, solar cells | Transistors, ICs, CPUs |
Solar Cells & Computational Applications
Solar Cell Basics
A solar cell is a PN junction operated under illumination. When photons with energy $h\nu \geq E_g$ strike the cell, electron-hole pairs are generated in the depletion region. The built-in electric field separates them โ electrons go to n-side, holes to p-side โ creating a photocurrent and photovoltage.
- Open-circuit voltage: $V_{OC} = \frac{kT}{q}\ln\left(\frac{I_L}{I_0} + 1\right)$
- Short-circuit current: $I_{SC} \approx I_L$ (photogenerated current)
- Efficiency: $\eta = \frac{P_{max}}{P_{incident}} = \frac{V_{OC} \cdot I_{SC} \cdot FF}{P_{in}}$ where $FF$ is the fill factor (~0.7โ0.85).
Computational Applications
CMOS Technology
CMOS (Complementary Metal-Oxide-Semiconductor) uses pairs of NMOS and PMOS transistors. A CMOS inverter has near-zero static power consumption because only one transistor is ON at a time. This is why modern CPUs can have billions of transistors without melting!
Memory Devices
SRAM: Uses 6 transistors per bit. Fast but expensive. Used in CPU cache.
DRAM: Uses 1 transistor + 1 capacitor per bit. Slower but dense. Used as main RAM.
Flash/SSD: Uses floating-gate transistors. Electrons trapped on the floating gate represent stored data. NAND flash stacks cells vertically (3D NAND) for massive storage.
AI Accelerator Chips & IoT Sensors
GPU: Thousands of small cores for parallel matrix multiplication โ ideal for neural network training.
TPU (Google's Tensor Processing Unit): Custom ASIC designed specifically for matrix operations in AI/ML.
IoT Sensors: Semiconductor-based sensors (temperature, pressure, gas, light) use changes in resistance, capacitance, or current due to physical stimuli.
MCQ Assessment โ Unit I
In the Drude model, the drift velocity of electrons is proportional to:
- Electric field strength
- Square of electric field
- Magnetic field
- Temperature
The Fermi-Dirac distribution function at $E = E_F$ gives a probability of:
- 0
- 1
- 0.5
- Depends on temperature
The band gap of Silicon at room temperature is approximately:
- 0.67 eV
- 1.12 eV
- 1.43 eV
- 5.5 eV
The Hall coefficient for an n-type semiconductor is:
- Positive
- Negative
- Zero
- Infinite
In a p-type semiconductor, the Fermi level is:
- At the middle of the band gap
- Close to the conduction band
- Close to the valence band
- Above the conduction band
Which material is used for LEDs because of its direct band gap?
- Silicon
- Germanium
- GaAs
- Diamond
Effective mass of an electron is determined from the E-k diagram by:
- Slope of the curve
- Curvature (second derivative)
- Area under the curve
- Y-intercept
Diffusion current in a semiconductor is caused by:
- Electric field
- Concentration gradient
- Magnetic field
- Temperature gradient only
In CMOS technology, zero static power consumption is achieved because:
- Both transistors are always ON
- Only one transistor (NMOS or PMOS) is ON at a time
- No transistors are used
- Capacitors store the charge
The fill factor of a solar cell is the ratio of:
- $V_{OC}$ to $I_{SC}$
- Maximum power to ($V_{OC} \times I_{SC}$)
- Input power to output power
- Band gap to photon energy
๐ Unit I Summary
- Drude Model: Free electrons, drift velocity $v_d = eE\tau/m$, conductivity $\sigma = ne^2\tau/m$
- Fermi-Dirac: $f(E) = 1/[1 + \exp((E-E_F)/kT)]$; $f(E_F) = 0.5$ always
- Band Gap: Conductor (0 eV), Semiconductor (0.1โ3 eV), Insulator (>3 eV)
- Effective Mass: $m^* = \hbar^2/(d^2E/dk^2)$; holes = missing electrons with positive mass
- Hall Effect: $V_H = BI/(net)$; $R_H = 1/(ne)$; determines carrier type, concentration, mobility
- Intrinsic: $n_i = p_i$, $E_F$ at midgap; N-type: $E_F$ near $E_C$; P-type: $E_F$ near $E_V$
- Direct bandgap (GaAs) โ LEDs/lasers; Indirect (Si) โ CPUs/ICs
Fundamentals of Electricity & Devices
โก India's Power Grid โ 1.4 Billion People, One Interconnected Circuit
India's power grid is the world's largest interconnected grid, connecting 1.4 billion people across 28 states. Reliance Jio laid 9 lakh km of optical fiber โ enough to wrap around Earth 22 times โ to bring 4G to every village. Every wire, every junction, every optical signal obeys the electrical laws you're about to master.
Fundamental Electrical Laws
Ohm's Law
The current $I$ through a conductor is directly proportional to the voltage $V$ across it:
$$V = IR$$Resistance depends on material and geometry: $R = \rho \frac{L}{A}$, where $\rho$ = resistivity, $L$ = length, $A$ = cross-sectional area.
Kirchhoff's Current Law (KCL)
The algebraic sum of all currents at any node is zero:
$$\sum I_{in} = \sum I_{out} \quad \text{or} \quad \sum I = 0$$Kirchhoff's Voltage Law (KVL)
The algebraic sum of all voltages around any closed loop is zero:
$$\sum V = 0$$Voltage & Current Division Rules
Voltage Division Rule (VDR) โ Derivation
For two resistors $R_1$ and $R_2$ in series connected to a source $V_s$:
Since series current is the same: $I = \frac{V_s}{R_1 + R_2}$
Voltage across $R_1$:
$$\boxed{V_1 = V_s \times \frac{R_1}{R_1 + R_2}}$$Voltage across $R_2$:
$$V_2 = V_s \times \frac{R_2}{R_1 + R_2}$$Solved Example โ VDR
Numerical
Problem: A 12V source is connected to $R_1 = 4\text{k}\Omega$ and $R_2 = 8\text{k}\Omega$ in series. Find voltage across each.
Solution: $V_1 = 12 \times \frac{4}{4+8} = 12 \times \frac{1}{3} = 4\text{V}$
$V_2 = 12 \times \frac{8}{12} = 8\text{V}$. Check: $4 + 8 = 12$ โ
Current Division Rule (CDR) โ Derivation
For two resistors $R_1$ and $R_2$ in parallel connected to a current source $I_s$:
Voltage across parallel combination: $V = I_s \times \frac{R_1 R_2}{R_1 + R_2}$
Current through $R_1$:
$$\boxed{I_1 = I_s \times \frac{R_2}{R_1 + R_2}}$$(Note: current through $R_1$ depends on the other resistor $R_2$.)
PN Junction Diode
Formation of PN Junction
When p-type and n-type semiconductors are joined:
- Electrons from n-side diffuse into p-side; holes from p-side diffuse into n-side.
- This creates a region depleted of free carriers: the depletion region.
- Immobile ions in the depletion region create a built-in potential $V_{bi}$ (โ0.7V for Si, 0.3V for Ge).
- The built-in field opposes further diffusion, establishing equilibrium.
Shockley Diode Equation
$$I = I_s\left(e^{qV/nkT} - 1\right)$$where $I_s$ โ 10โปยนยฒ A (reverse saturation current), $n$ = ideality factor (1โ2), $V_T = kT/q$ โ 26 mV at 300K.
V-I Characteristics
| Region | Condition | Current |
|---|---|---|
| Forward bias | $V > 0$ (p positive, n negative) | Exponentially increasing after $V_{bi}$ |
| Reverse bias | $V < 0$ | Small constant $-I_s$ (leakage) |
| Breakdown | $V < -V_{BR}$ | Sudden large reverse current |
Rectifier Applications
Half-Wave Rectifier: Uses one diode. Only positive half-cycle passes.
- $V_{dc} = \frac{V_m}{\pi} \approx 0.318 V_m$
- Ripple factor $\gamma = 1.21$ (very high)
- Efficiency $\eta = 40.6\%$
Full-Wave Rectifier (Bridge): Uses 4 diodes. Both half-cycles are rectified.
- $V_{dc} = \frac{2V_m}{\pi} \approx 0.636 V_m$
- Ripple factor $\gamma = 0.48$ (much better)
- Efficiency $\eta = 81.2\%$
| Parameter | Half-Wave | Full-Wave (Bridge) |
|---|---|---|
| No. of diodes | 1 | 4 |
| $V_{dc}$ | $V_m/\pi$ | $2V_m/\pi$ |
| Ripple factor | 1.21 | 0.48 |
| Efficiency | 40.6% | 81.2% |
| Transformer | Not needed | Not needed |
Bipolar Junction Transistor (BJT)
A BJT has three regions: Emitter (heavily doped), Base (thin, lightly doped), Collector (moderately doped, large area).
Current Relations
$$I_E = I_B + I_C$$ $$\alpha = \frac{I_C}{I_E} \quad (\text{common-base current gain, } \approx 0.95\text{โ}0.99)$$ $$\beta = \frac{I_C}{I_B} \quad (\text{common-emitter current gain, } \approx 50\text{โ}300)$$ $$\beta = \frac{\alpha}{1 - \alpha} \quad \text{and} \quad \alpha = \frac{\beta}{\beta + 1}$$Regions of Operation
| Region | BE Junction | BC Junction | Use |
|---|---|---|---|
| Active | Forward biased | Reverse biased | Amplification |
| Saturation | Forward biased | Forward biased | Switch ON |
| Cutoff | Reverse biased | Reverse biased | Switch OFF |
Solved Example โ BJT
Numerical
Problem: A BJT has $\beta = 100$ and $I_B = 20\mu$A. Find $I_C$ and $I_E$.
Solution: $I_C = \beta \cdot I_B = 100 \times 20\mu\text{A} = 2\text{ mA}$
$I_E = I_C + I_B = 2\text{ mA} + 0.02\text{ mA} = 2.02\text{ mA}$
$\alpha = \beta/(\beta+1) = 100/101 = 0.99$. Check: $\alpha \cdot I_E = 0.99 \times 2.02 = 2$ mA = $I_C$ โ
Optical Fiber Communication
Optical fibers transmit data as light pulses via Total Internal Reflection (TIR).
Critical angle (from Snell's law): When $\theta_r = 90ยฐ$:
$$n_1 \sin\theta_c = n_2 \sin 90ยฐ \implies \boxed{\theta_c = \sin^{-1}\left(\frac{n_2}{n_1}\right)}$$Numerical Aperture: $NA = \sqrt{n_1^2 - n_2^2}$ determines the light-gathering ability.
| Type | Single-Mode | Multi-Mode |
|---|---|---|
| Core diameter | 8โ10 ฮผm | 50โ62.5 ฮผm |
| Distance | Up to 100 km | Up to 2 km |
| Bandwidth | Very high | Moderate |
| Use | Long-haul telecom | LAN, data centers |
Wireless Communication โ Basics
Wireless signals use electromagnetic waves modulated to carry information:
- AM (Amplitude Modulation): Signal varies the amplitude of the carrier wave. Used in AM radio.
- FM (Frequency Modulation): Signal varies the frequency. Better noise immunity. Used in FM radio.
- Digital Modulation: ASK, FSK, PSK โ used in WiFi, 4G, 5G.
MCQ Assessment โ Unit II
In voltage division, the voltage across a resistor in series is proportional to:
- Its own resistance
- The other resistance
- Total current
- Total power
The built-in potential of a silicon PN junction is approximately:
- 0.3 V
- 0.7 V
- 1.1 V
- 5.0 V
The ripple factor of a full-wave bridge rectifier is:
- 1.21
- 0.48
- 0.00
- 2.00
If $\beta = 200$ for a BJT and $I_C = 4$ mA, the base current is:
- 20 ฮผA
- 200 ฮผA
- 0.8 A
- 2 mA
In an optical fiber, total internal reflection occurs when:
- Angle of incidence < critical angle
- Angle of incidence > critical angle
- Core has lower refractive index than cladding
- Light exits through the cladding
๐ Unit II Summary
- Ohm's Law: $V = IR$; KCL: $\sum I = 0$; KVL: $\sum V = 0$
- VDR: $V_1 = V_s \cdot R_1/(R_1+R_2)$; CDR: $I_1 = I_s \cdot R_2/(R_1+R_2)$
- Diode: $I = I_s(e^{V/nV_T}-1)$; $V_{bi}$ โ 0.7V (Si), 0.3V (Ge)
- HWR: $V_{dc} = V_m/\pi$, $\gamma = 1.21$; FWR: $V_{dc} = 2V_m/\pi$, $\gamma = 0.48$
- BJT: $I_E = I_B + I_C$, $\beta = I_C/I_B$, $\alpha = I_C/I_E = \beta/(\beta+1)$
- Optical Fiber: $\theta_c = \sin^{-1}(n_2/n_1)$; $NA = \sqrt{n_1^2 - n_2^2}$
Number Systems & Logic Gates
๐ป Every Google Search = Billions of Binary Operations
When you type a query on Google, your keystrokes are converted to binary numbers (ASCII codes), processed through logic gates inside the CPU, transmitted as binary packets across fiber optic cables, and matched against an index using Boolean algebra. The entire internet runs on the mathematics of 0s and 1s.
Number System Conversions
A number $N$ in base $r$: $N_r = d_n r^n + d_{n-1} r^{n-1} + \dots + d_0 r^0 + d_{-1} r^{-1} + \dots$
Decimal to Binary (Division-by-2 Method)
Example: Convert $(45)_{10}$ to Binary
45 รท 2 = 22 remainder 1 (LSB) 22 รท 2 = 11 remainder 0 11 รท 2 = 5 remainder 1 5 รท 2 = 2 remainder 1 2 รท 2 = 1 remainder 0 1 รท 2 = 0 remainder 1 (MSB) Read remainders bottom to top: (101101)โ
Verify: $1(32) + 0(16) + 1(8) + 1(4) + 0(2) + 1(1) = 32 + 8 + 4 + 1 = 45$ โ
Binary โ Octal โ Hexadecimal
- Binary โ Octal: Group bits in 3s from right. Example: $101\,101_2 = 55_8$
- Binary โ Hex: Group bits in 4s from right. Example: $0010\,1101_2 = 2D_{16}$
Codes
BCD (Binary Coded Decimal)
Each decimal digit is represented by its 4-bit binary equivalent. Example: $93_{10} = 1001\,0011_{BCD}$.
Gray Code (Binary โ Gray Conversion)
Binary to Gray: MSB stays same. Each subsequent bit = XOR of adjacent binary bits.
Gray to Binary: MSB stays same. Each subsequent bit = XOR of previous binary bit with current gray bit.
Example: Convert Binary 1011 to Gray
Binary: 1 0 1 1
โ โ โ โ
Gray: 1 1 1 0
โ โ โ โ
โ 1โ0 0โ1 1โ1
MSB same
$G_3 = B_3 = 1$; $G_2 = B_3 \oplus B_2 = 1 \oplus 0 = 1$; $G_1 = B_2 \oplus B_1 = 0 \oplus 1 = 1$; $G_0 = B_1 \oplus B_0 = 1 \oplus 1 = 0$
Answer: 1110
Excess-3 Code
Add 3 to each decimal digit, then convert to BCD. Example: $5_{10} โ 5+3 = 8 โ 1000_{Excess-3}$
Complements & Binary Arithmetic
1's Complement
Flip all bits: $1's(1010) = 0101$
2's Complement
Flip all bits + add 1: $2's(1010) = 0101 + 1 = 0110$
Subtraction Using 2's Complement
Example: Compute 7 - 3 using 2's complement (4-bit)
7 in binary: 0111 3 in binary: 0011 2's comp of 3: 1101 (flip: 1100, add 1: 1101) 0111 + 1101 ------- 1|0100 โ Discard carry. Result = 0100 = 4 โ
Logic Gates
| Gate | Symbol | Expression | 0,0 | 0,1 | 1,0 | 1,1 |
|---|---|---|---|---|---|---|
| AND | AยทB | $Y = A \cdot B$ | 0 | 0 | 0 | 1 |
| OR | A+B | $Y = A + B$ | 0 | 1 | 1 | 1 |
| NOT | A' | $Y = \overline{A}$ | Inverts: 0โ1, 1โ0 | |||
| NAND | (AยทB)' | $Y = \overline{AB}$ | 1 | 1 | 1 | 0 |
| NOR | (A+B)' | $Y = \overline{A+B}$ | 1 | 0 | 0 | 0 |
| XOR | AโB | $Y = A \oplus B$ | 0 | 1 | 1 | 0 |
| XNOR | (AโB)' | $Y = \overline{A \oplus B}$ | 1 | 0 | 0 | 1 |
Boolean Algebra
Important Laws
| Law | AND Form | OR Form |
|---|---|---|
| Identity | $A \cdot 1 = A$ | $A + 0 = A$ |
| Null | $A \cdot 0 = 0$ | $A + 1 = 1$ |
| Idempotent | $A \cdot A = A$ | $A + A = A$ |
| Complement | $A \cdot \overline{A} = 0$ | $A + \overline{A} = 1$ |
| Absorption | $A(A+B) = A$ | $A + AB = A$ |
De Morgan's Theorems
Theorem 1: $\overline{A \cdot B} = \overline{A} + \overline{B}$ (Break the bar, change the sign)
Theorem 2: $\overline{A + B} = \overline{A} \cdot \overline{B}$
SOP and POS Forms
- SOP (Sum of Products): OR of AND terms = $\sum m(minterms)$. Example: $F = \overline{A}B + AB = \sum m(1,3)$
- POS (Product of Sums): AND of OR terms = $\prod M(maxterms)$. Example: $F = (A+B)(\overline{A}+B)$
Karnaugh Map (K-Map)
A visual method for simplifying Boolean expressions. Adjacent cells differ by only one variable.
Grouping Rules
- Groups must contain $2^n$ cells (1, 2, 4, 8, 16)
- Groups must be rectangular
- Groups can wrap around edges
- Every 1 must be covered by at least one group
- Make groups as large as possible to eliminate more variables
4-Variable K-Map Solved Example
Simplify $F(A,B,C,D) = \sum m(0,1,2,3,8,9,10,11)$
Map the minterms:
| AB\CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 | 1 | 1 | 1 |
| 01 | 0 | 0 | 0 | 0 |
| 11 | 0 | 0 | 0 | 0 |
| 10 | 1 | 1 | 1 | 1 |
Group all 8 ones: A changes (0โ1), C changes, D changes. Only B stays 0 throughout.
Answer: $F = \overline{B}$
MCQ Assessment โ Unit III
$(255)_{10}$ in hexadecimal is:
- EE
- FF
- FE
- 1F
The 2's complement of 8-bit number 00110100 is:
- 11001011
- 11001100
- 11001010
- 00110101
Which gate is a universal gate?
- AND
- OR
- XOR
- NAND
De Morgan's theorem states $\overline{A+B}$ equals:
- $\overline{A} + \overline{B}$
- $\overline{A} \cdot \overline{B}$
- $A \cdot B$
- $A + B$
The Excess-3 code for decimal 4 is:
- 0100
- 0111
- 1000
- 0011
In a 4-variable K-map, a group of 4 cells eliminates how many variables?
- 1
- 2
- 3
- 4
๐ Unit III Summary
- Number Systems: Binary (base 2), Octal (base 8), Decimal (base 10), Hex (base 16)
- Codes: BCD (8421), Gray (adjacent differ by 1 bit), Excess-3 (BCD + 3)
- 2's Complement: Flip bits + add 1. Used for subtraction via addition.
- Universal Gates: NAND and NOR can implement any function
- De Morgan's: $\overline{AB} = \overline{A}+\overline{B}$; $\overline{A+B} = \overline{A}\cdot\overline{B}$
- K-Map: Group $2^n$ cells โ eliminate $n$ variables. Groups wrap around.
Combinational Logic Circuits
๐งฎ The ALU โ The Calculator Inside Every Processor
Every time your phone adds two numbers, your laptop compares passwords, or a UPI payment is processed, the Arithmetic Logic Unit (ALU) inside the processor uses combinational circuits โ adders, multiplexers, decoders โ to compute results in nanoseconds. The ALU in Apple's M3 chip performs 11 trillion operations per second.
Adders & Subtractors
Half Adder
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
$Sum = A \oplus B$ $Carry = A \cdot B$
Full Adder
| A | B | $C_{in}$ | Sum | $C_{out}$ |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
A Full Adder = Two Half Adders + OR gate.
Half Subtractor
| A | B | Difference | Borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
$D = A \oplus B$ $B_{out} = \overline{A} \cdot B$
Full Subtractor
$$D = A \oplus B \oplus B_{in}$$ $$B_{out} = \overline{A}B + \overline{A}B_{in} + BB_{in} = \overline{A}B + B_{in}(\overline{A} \oplus B)$$Multiplexer (MUX)
A MUX selects one of $2^n$ inputs and routes it to a single output using $n$ select lines.
4:1 MUX
$$Y = \overline{S_1}\overline{S_0}I_0 + \overline{S_1}S_0 I_1 + S_1\overline{S_0}I_2 + S_1 S_0 I_3$$Implementing Boolean Functions with MUX
Example: Implement $F(A,B,C) = \sum m(1,2,6,7)$ using 8:1 MUX
Connect A, B, C to select lines $S_2, S_1, S_0$.
For each minterm present, connect corresponding input to 1; otherwise to 0:
| Minterm | A B C | MUX Input | Value |
|---|---|---|---|
| $m_0$ | 0 0 0 | $I_0$ | 0 |
| $m_1$ | 0 0 1 | $I_1$ | 1 |
| $m_2$ | 0 1 0 | $I_2$ | 1 |
| $m_3$ | 0 1 1 | $I_3$ | 0 |
| $m_4$ | 1 0 0 | $I_4$ | 0 |
| $m_5$ | 1 0 1 | $I_5$ | 0 |
| $m_6$ | 1 1 0 | $I_6$ | 1 |
| $m_7$ | 1 1 1 | $I_7$ | 1 |
De-Multiplexer (DEMUX)
A DEMUX routes a single input to one of $2^n$ outputs using $n$ select lines. It is the reverse of a MUX.
1:4 DEMUX: Input $D$, select lines $S_1, S_0$:
$Y_0 = D \cdot \overline{S_1} \cdot \overline{S_0}$, $Y_1 = D \cdot \overline{S_1} \cdot S_0$, $Y_2 = D \cdot S_1 \cdot \overline{S_0}$, $Y_3 = D \cdot S_1 \cdot S_0$
Decoder & Encoder
2:4 Decoder
| $A_1$ | $A_0$ | $Y_0$ | $Y_1$ | $Y_2$ | $Y_3$ |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
Each output represents one minterm. A decoder with an enable input can function as a DEMUX.
Priority Encoder (4:2)
If multiple inputs are active, the highest priority input is encoded.
| $D_3$ | $D_2$ | $D_1$ | $D_0$ | $A_1$ | $A_0$ | V (valid) |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | X | X | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | X | 0 | 1 | 1 |
| 0 | 1 | X | X | 1 | 0 | 1 |
| 1 | X | X | X | 1 | 1 | 1 |
2-Bit Magnitude Comparator
Compares two 2-bit numbers $A = A_1A_0$ and $B = B_1B_0$. Three outputs: $A>B$, $A=B$, $A
Equality: $A = B$ when $A_1=B_1$ AND $A_0=B_0$:
$$\boxed{(A=B) = (A_1 \odot B_1)(A_0 \odot B_0)}$$where $\odot$ is XNOR.
Greater than: $A > B$ when $A_1>B_1$, or $A_1=B_1$ and $A_0>B_0$:
$$\boxed{(A>B) = A_1\overline{B_1} + (A_1 \odot B_1)A_0\overline{B_0}}$$ $$\boxed{(AMCQ Assessment โ Unit IV
A Full Adder has how many inputs and outputs?
- 2 inputs, 1 output
- 3 inputs, 2 outputs
- 2 inputs, 2 outputs
- 3 inputs, 3 outputs
A 4:1 MUX has how many select lines?
- 1
- 2
- 3
- 4
The borrow output of a Half Subtractor is:
- $A \cdot B$
- $\overline{A} \cdot B$
- $A \oplus B$
- $A + B$
A 3:8 decoder has how many output lines?
- 3
- 6
- 8
- 16
In a priority encoder, if both $D_2$ and $D_0$ are high, the output code represents:
- $D_0$
- $D_2$
- Both
- Invalid
๐ Unit IV Summary
- Half Adder: $S = A \oplus B$, $C = AB$
- Full Adder: $S = A \oplus B \oplus C_{in}$, $C_{out} = AB + C_{in}(A \oplus B)$
- Half Subtractor: $D = A \oplus B$, $B_{out} = \overline{A}B$
- MUX: $2^n$ inputs โ 1 output using $n$ select lines
- DEMUX: 1 input โ $2^n$ outputs (reverse of MUX)
- Decoder: $n$ inputs โ $2^n$ outputs (each output = one minterm)
- Priority Encoder: Encodes highest-priority active input
- Comparator: $(A=B) = (A_1 \odot B_1)(A_0 \odot B_0)$
Sequential Logic Circuits
โฐ Flip-Flops โ The Memory Cells That Keep Time
Every second, the quartz crystal inside your laptop vibrates 3.2 billion times (3.2 GHz clock). Each tick of this clock triggers millions of flip-flops to update their state โ storing the next instruction, the next pixel, the next packet. Without flip-flops, computers would have no memory and no concept of "before" and "after."
Latches
Key Difference: A latch is level-sensitive (transparent when enable is high). A flip-flop is edge-triggered (changes only on clock edge).
SR Latch (using NOR gates)
| S | R | $Q_{next}$ | $\overline{Q}_{next}$ | State |
|---|---|---|---|---|
| 0 | 0 | $Q$ | $\overline{Q}$ | Hold / No change |
| 0 | 1 | 0 | 1 | Reset |
| 1 | 0 | 1 | 0 | Set |
| 1 | 1 | 0 | 0 | โ Invalid / Forbidden |
D Latch
Eliminates the invalid state by using a single data input $D$. Internally: $S = D$, $R = \overline{D}$.
| Enable | D | $Q_{next}$ | Action |
|---|---|---|---|
| 0 | X | $Q$ | Hold |
| 1 | 0 | 0 | Reset |
| 1 | 1 | 1 | Set |
Characteristic equation: $Q_{next} = D$ (when enabled)
Flip-Flops
SR Flip-Flop
Characteristic equation: $Q_{next} = S + \overline{R} \cdot Q$ with constraint $SR = 0$
| S | R | $Q_{next}$ |
|---|---|---|
| 0 | 0 | $Q$ (Hold) |
| 0 | 1 | 0 (Reset) |
| 1 | 0 | 1 (Set) |
| 1 | 1 | โ Invalid |
Excitation Table (given desired transition, find required inputs):
| $Q$ | $Q_{next}$ | S | R |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | X | 0 |
JK Flip-Flop
Solves the invalid state problem of SR. When J=K=1, the output toggles.
Characteristic equation: $\boxed{Q_{next} = J\overline{Q} + \overline{K}Q}$
| J | K | $Q_{next}$ | Action |
|---|---|---|---|
| 0 | 0 | $Q$ | Hold |
| 0 | 1 | 0 | Reset |
| 1 | 0 | 1 | Set |
| 1 | 1 | $\overline{Q}$ | Toggle |
Excitation Table:
| $Q$ | $Q_{next}$ | J | K |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | X |
| 1 | 0 | X | 1 |
| 1 | 1 | X | 0 |
D Flip-Flop
Characteristic equation: $Q_{next} = D$. Most widely used in registers and memory.
Excitation Table: $Q \rightarrow Q_{next}$: D = $Q_{next}$ (always!)
T Flip-Flop (Toggle)
Characteristic equation: $Q_{next} = T \oplus Q = T\overline{Q} + \overline{T}Q$
| T | $Q_{next}$ | Action |
|---|---|---|
| 0 | $Q$ | Hold |
| 1 | $\overline{Q}$ | Toggle |
T flip-flops are ideal for counters because each stage divides the frequency by 2.
Master-Slave JK Flip-Flop
The basic JK flip-flop has a race condition: if J=K=1 and the clock pulse is wide, the output may toggle multiple times during a single clock pulse.
Solution: Master-Slave configuration:
- Master (first FF): Captures input on the positive edge (clock = 1)
- Slave (second FF): Transfers master's output on the negative edge (clock = 0)
- Since master and slave never operate simultaneously, race condition is eliminated.
Flip-Flop Conversion
General Procedure:
- Write the characteristic table of the desired flip-flop.
- Write the excitation table of the available flip-flop.
- For each row, determine the required inputs of the available FF.
- Use K-maps to derive the expressions connecting desired inputs to available inputs.
Solved Example: Convert JK โ D Flip-Flop
JK to D Conversion
D flip-flop: $Q_{next} = D$. We need to express J and K in terms of D and Q.
| $Q$ | $D$ (input) | $Q_{next}$ | $J$ (needed) | $K$ (needed) |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | X |
| 0 | 1 | 1 | 1 | X |
| 1 | 0 | 0 | X | 1 |
| 1 | 1 | 1 | X | 0 |
From the table: $J = D$ and $K = \overline{D}$.
Circuit: Connect $D$ to the $J$ input and $\overline{D}$ (through an inverter) to the $K$ input of the JK flip-flop.
Convert D โ T Flip-Flop
T FF: $Q_{next} = T \oplus Q$. D FF excitation: $D = Q_{next}$.
So: $D = T \oplus Q$. Circuit: XOR gate with T and Q feeding into D input.
Shift Registers
| Type | Input | Output | Application |
|---|---|---|---|
| SISO | Serial | Serial | Time delay |
| SIPO | Serial | Parallel | Serial-to-parallel conversion |
| PISO | Parallel | Serial | Parallel-to-serial conversion |
| PIPO | Parallel | Parallel | Temporary storage, buffer |
SISO Operation Example
Loading data 1011 into a 4-bit SISO register (MSB first):
| Clock | Input | $Q_3$ | $Q_2$ | $Q_1$ | $Q_0$ |
|---|---|---|---|---|---|
| Initial | โ | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 |
| 2 | 0 | 0 | 1 | 0 | 0 |
| 3 | 1 | 1 | 0 | 1 | 0 |
| 4 | 1 | 1 | 1 | 0 | 1 |
After 4 clock pulses, data appears serially at $Q_0$ output.
Asynchronous (Ripple) Counters
3-Bit UP Counter
Uses 3 T flip-flops with T=1 (always toggle). Clock of each FF is connected to the Q output of the previous FF.
| Clock | $Q_2$ | $Q_1$ | $Q_0$ | Decimal |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 |
| 2 | 0 | 1 | 0 | 2 |
| 3 | 0 | 1 | 1 | 3 |
| 4 | 1 | 0 | 0 | 4 |
| 5 | 1 | 0 | 1 | 5 |
| 6 | 1 | 1 | 0 | 6 |
| 7 | 1 | 1 | 1 | 7 |
| 8 | 0 | 0 | 0 | 0 (repeat) |
Counts from 0 to $2^N - 1$. For 3 bits: 0 to 7. DOWN counter: Connect clock to $\overline{Q}$ instead of $Q$.
Mod-N Counter
A Mod-N counter counts from 0 to N-1 and then resets. Design: Use enough flip-flops ($\lceil \log_2 N \rceil$) and add reset logic.
Design: Mod-5 Counter
Need to count: 0, 1, 2, 3, 4, then reset to 0. Need 3 flip-flops ($\lceil \log_2 5 \rceil = 3$).
Count 5 in binary = 101. When $Q_2Q_1Q_0 = 101$, apply RESET.
Reset logic: NAND gate detecting $Q_2 = 1$ AND $Q_0 = 1$ โ Clear all flip-flops.
Note: State 101 appears momentarily before reset (called a glitch).
MCQ Assessment โ Unit V
The characteristic equation of a JK flip-flop is:
- $Q_{next} = J + K$
- $Q_{next} = J\overline{Q} + \overline{K}Q$
- $Q_{next} = JK$
- $Q_{next} = J \oplus K$
The SR latch has an invalid state when:
- S=0, R=0
- S=0, R=1
- S=1, R=0
- S=1, R=1
A T flip-flop with T=1 connected to a 10 MHz clock produces an output frequency of:
- 10 MHz
- 20 MHz
- 5 MHz
- 1 MHz
To convert a JK flip-flop to a D flip-flop, connect:
- J=D, K=D
- J=D, K=$\overline{D}$
- J=$\overline{D}$, K=D
- J=1, K=D
A Mod-6 counter requires how many flip-flops?
- 2
- 3
- 4
- 6
Which register type converts serial data to parallel?
- SISO
- SIPO
- PISO
- PIPO
๐ Unit V Summary โ All Characteristic Equations
| Flip-Flop | Characteristic Equation | Special Feature |
|---|---|---|
| SR | $Q_{next} = S + \overline{R}Q$, SR=0 | Invalid state at S=R=1 |
| JK | $Q_{next} = J\overline{Q} + \overline{K}Q$ | Toggle at J=K=1 |
| D | $Q_{next} = D$ | Most used in registers |
| T | $Q_{next} = T \oplus Q$ | Used in counters |
- Master-Slave: Eliminates race condition by two-phase clocking
- Registers: SISO (delay), SIPO (serialโparallel), PISO (parallelโserial), PIPO (buffer)
- Counters: N flip-flops โ count 0 to $2^N-1$. Mod-N: reset at N using feedback logic.
Introduction to Arduino & Sensors
๐พ IoT Revolution โ From Smart Farms to Smart Cities
Indian startup Fasal uses IoT sensors (temperature, humidity, soil moisture) connected to microcontrollers to help farmers reduce water usage by 40% and increase crop yield by 25%. Globally, there are over 15 billion IoT devices โ more than twice the world's population. Arduino, a โน500 microcontroller board, is the gateway to this revolution.
Analog vs Digital Signals
| Property | Analog Signal | Digital Signal |
|---|---|---|
| Nature | Continuous (smooth wave) | Discrete (0s and 1s) |
| Values | Infinite values in a range | Only two levels (HIGH/LOW) |
| Noise immunity | Low (susceptible to noise) | High (noise can be filtered) |
| Processing | Op-amps, analog circuits | Microcontrollers, logic gates |
| Example | Temperature, audio, voltage | Switch state, serial data |
| Storage | Difficult, degrades over time | Easy, perfect copies |
ADC (Analog-to-Digital Converter): Converts continuous signals to discrete digital values. An $n$-bit ADC has $2^n$ levels. Arduino's 10-bit ADC โ $2^{10} = 1024$ levels (0 to 1023).
DAC (Digital-to-Analog Converter): Converts digital values back to analog. Arduino uses PWM (Pulse Width Modulation) to simulate DAC.
Arduino Uno Board
Technical Specifications
| Parameter | Value |
|---|---|
| Microcontroller | ATmega328P |
| Clock Speed | 16 MHz |
| Flash Memory | 32 KB (0.5 KB for bootloader) |
| SRAM | 2 KB |
| EEPROM | 1 KB |
| Digital I/O Pins | 14 (6 provide PWM) |
| Analog Input Pins | 6 (A0โA5) |
| Operating Voltage | 5V |
| Input Voltage | 7โ12V (via Vin/barrel jack) |
| DC Current per I/O | 20 mA (max 40 mA) |
Pin Configuration
| Pin Category | Pins | Description |
|---|---|---|
| Power | Vin, 5V, 3.3V, GND | Power supply and ground connections |
| Digital I/O | D0โD13 | Digital input/output. D0/D1 = Serial (TX/RX) |
| PWM | D3, D5, D6, D9, D10, D11 | Analog-like output using pulse width modulation (marked with ~) |
| Analog Input | A0โA5 | 10-bit ADC (0โ1023 for 0โ5V) |
| Communication | D10โD13 (SPI), A4/A5 (I2C) | SPI and I2C protocols for sensors/displays |
| Other | RESET, AREF, ICSP | Reset button, analog reference, in-circuit programming |
Arduino Program Structure
// Every Arduino program has two mandatory functions void setup() { // Runs ONCE when board powers on or resets pinMode(13, OUTPUT); // Set pin 13 as output Serial.begin(9600); // Start serial communication } void loop() { // Runs REPEATEDLY forever digitalWrite(13, HIGH); // LED ON delay(1000); // Wait 1 second digitalWrite(13, LOW); // LED OFF delay(1000); // Wait 1 second }
Sensors
IR Sensor
Working Principle: An IR LED emits infrared light. A photodiode detects the reflected IR. When an obstacle is present, IR bounces back โ photodiode receives signal โ output goes LOW (active low).
Connections: VCC โ 5V, GND โ GND, OUT โ Digital pin
// IR Sensor โ Obstacle Detection const int irPin = 2; void setup() { pinMode(irPin, INPUT); Serial.begin(9600); } void loop() { int val = digitalRead(irPin); if (val == LOW) { Serial.println("Obstacle Detected!"); } else { Serial.println("No Obstacle"); } delay(200); }
LDR (Light Dependent Resistor)
Working Principle: Made of Cadmium Sulfide (CdS). Resistance decreases with increasing light intensity. In dark: ~1 Mฮฉ. In bright light: ~1 kฮฉ.
Circuit: Use a voltage divider with a fixed resistor (10kฮฉ). Connect the junction to an analog pin.
// LDR โ Automatic Street Light const int ldrPin = A0; const int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { int lightLevel = analogRead(ldrPin); // 0-1023 Serial.print("Light: "); Serial.println(lightLevel); if (lightLevel < 300) { // Dark โ turn ON street light digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } delay(500); }
Ultrasonic Sensor (HC-SR04)
Working Principle: Sends a 40 kHz ultrasonic pulse via the Trigger pin. The pulse bounces off an object and returns to the Echo pin. The time taken for the round trip determines the distance.
Formula:
$$Distance = \frac{Time \times Speed\ of\ Sound}{2} = \frac{Time\ (\mu s) \times 0.034}{2} \text{ cm}$$Pins: VCC (5V), Trig (digital out), Echo (digital in), GND
// HC-SR04 Ultrasonic Distance Measurement const int trigPin = 9; const int echoPin = 10; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); } void loop() { // Send 10ฮผs pulse digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Measure echo duration long duration = pulseIn(echoPin, HIGH); float distance = duration * 0.034 / 2; Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm"); delay(500); }
Temperature Sensor (DHT11 / DHT22)
Measures both temperature and humidity using a capacitive humidity sensor and a thermistor.
| Parameter | DHT11 | DHT22 |
|---|---|---|
| Temperature Range | 0โ50ยฐC | -40โ80ยฐC |
| Temp Accuracy | ยฑ2ยฐC | ยฑ0.5ยฐC |
| Humidity Range | 20โ80% RH | 0โ100% RH |
| Humidity Accuracy | ยฑ5% | ยฑ2โ5% |
| Sampling Rate | 1 Hz (once/sec) | 0.5 Hz (once/2 sec) |
| Price | ~โน50 | ~โน200 |
| Resolution | Integer only | 0.1ยฐ decimal |
Data Format: 40-bit serial data = 8-bit humidity integer + 8-bit humidity decimal + 8-bit temperature integer + 8-bit temperature decimal + 8-bit checksum.
// DHT11 Temperature & Humidity (using DHT library) #include "DHT.h" #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { float humidity = dht.readHumidity(); float tempC = dht.readTemperature(); if (isnan(humidity) || isnan(tempC)) { Serial.println("Sensor read failed!"); return; } Serial.print("Humidity: "); Serial.print(humidity); Serial.print("% | Temp: "); Serial.print(tempC); Serial.println("ยฐC"); delay(2000); }
Mini-Projects
๐ ๏ธ Project 1: Smart Parking System
Use an ultrasonic sensor at each parking slot. If distance < 10 cm โ slot occupied (Red LED). If distance > 10 cm โ slot available (Green LED). Display count on Serial Monitor.
๐ค๏ธ Project 2: IoT Weather Station
Use DHT22 (temperature + humidity) + LDR (light level). Log readings to Serial Monitor every 5 seconds. Can be extended with ESP8266 WiFi module to upload data to ThingSpeak cloud.
๐ค Project 3: Line Follower Robot
Use 2 IR sensors mounted under the robot. Left sensor detects line โ turn left. Right sensor detects line โ turn right. Both detect โ go straight. Neither detects โ stop. Motors controlled via L298N driver.
MCQ Assessment โ Unit VI
Arduino Uno uses which microcontroller?
- ATmega2560
- ATmega328P
- ESP8266
- STM32
The resolution of Arduino's built-in ADC is:
- 8-bit (256 levels)
- 10-bit (1024 levels)
- 12-bit (4096 levels)
- 16-bit
The HC-SR04 ultrasonic sensor uses which formula for distance?
- $d = v \times t$
- $d = (t \times 0.034) / 2$
- $d = t / 340$
- $d = 2t \times v$
DHT22 is better than DHT11 in terms of:
- Price
- Sampling speed
- Accuracy and range
- Power consumption
An LDR's resistance in bright light is approximately:
- 1 Mฮฉ
- 100 kฮฉ
- 10 kฮฉ
- 1 kฮฉ
Which Arduino pins support PWM output?
- All digital pins
- Only analog pins
- D3, D5, D6, D9, D10, D11
- D0 and D1 only
๐ Unit VI Summary
- Analog vs Digital: Analog = continuous; Digital = discrete (0/1). ADC converts analog โ digital.
- Arduino Uno: ATmega328P, 16 MHz, 14 digital pins, 6 analog, 6 PWM, 10-bit ADC
- IR Sensor: Emits IR, detects reflection. Output LOW = obstacle detected.
- LDR: Resistance โ with light โ. Use voltage divider + analogRead().
- HC-SR04: $d = (t \times 0.034)/2$ cm. Trigger pulse โ measure echo time.
- DHT11/22: Temperature + humidity. 40-bit serial data with checksum.