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

Unit I

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.

Intel India๐Ÿ‡ฎ๐Ÿ‡ณ SCL MohaliTSMCSamsung๐Ÿ‡ฎ๐Ÿ‡ณ ISRO

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

  1. Valence electrons are free to move throughout the metal (they are not bound to any particular atom).
  2. Electrons do not interact with each other (independent electron approximation).
  3. Electrons collide with ion cores (lattice atoms), not with each other. The average time between collisions is the relaxation time $\tau$.
  4. After each collision, the electron's velocity is randomized โ€” it "forgets" its previous direction.
  5. 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.

Drift velocity in copper is only about 0.1 mm/s! Yet when you flip a switch, the light turns on almost instantly because the electric field propagates at nearly the speed of light, pushing ALL electrons simultaneously.

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

Conditionf(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$ KStep functionAll states below $E_F$ filled, all above empty
$T > 0$ KSmooth curveSome states near $E_F$ become partially occupied
Students often confuse Fermi energy with Fermi level. Fermi energy is defined at 0 K. Fermi level is the energy at which $f(E) = 1/2$ at any temperature $T$. They are equal only at 0 K.

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 TypeBand Gap $E_g$ExampleBehavior
Conductor0 eV (bands overlap)Copper, SilverElectrons flow freely
Semiconductor0.1 โ€“ 3 eVSi (1.1 eV), Ge (0.67 eV)Conductivity increases with temperature
Insulator> 3 eVDiamond (5.5 eV), GlassNo 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.
A hole is not a physical particle โ€” it is the absence of an electron in the valence band. It behaves like a positive charge carrier with positive effective mass. When an electron moves left to fill a vacancy, the hole effectively moves right.

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

  1. Determine carrier type: Sign of $V_H$ tells n-type vs p-type.
  2. Measure carrier concentration: $n = \frac{BI}{V_H e t}$.
  3. Calculate mobility: $\mu = |R_H| \sigma = \frac{|R_H|}{\rho}$.
  4. 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:

PropertyN-typeP-type
DopantPentavalent (P, As, Sb)Trivalent (B, Al, Ga, In)
Majority carrierElectronsHoles
Minority carrierHolesElectrons
Fermi levelCloser to conduction bandCloser to valence band
Dopant createsDonor level near $E_C$Acceptor level near $E_V$

Direct vs Indirect Band Gap

PropertyDirect Band GapIndirect Band Gap
E-k diagramCB minimum and VB maximum at same $k$CB minimum and VB maximum at different $k$
TransitionElectron can directly emit/absorb photonRequires phonon (lattice vibration) assist
ExamplesGaAs, InP, GaNSi, Ge
ApplicationsLEDs, Laser diodes, solar cellsTransistors, ICs, CPUs
This is why Silicon is used for CPUs (doesn't need to emit light, excellent oxide layer) but GaAs is used for LEDs and lasers (efficient light emission due to direct band gap).

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.

India's Semi-Conductor Laboratory (SCL), Mohali is India's only chip fab. Under the India Semiconductor Mission (โ‚น76,000 crore budget), Tata Electronics and CG Power are building new fabs in Gujarat and Dholera. By 2028, India aims to produce chips for defense, automotive, and telecom sectors.

MCQ Assessment โ€” Unit I

Q1

In the Drude model, the drift velocity of electrons is proportional to:

  1. Electric field strength
  2. Square of electric field
  3. Magnetic field
  4. Temperature
โœ… A. $v_d = \frac{eE\tau}{m}$, so drift velocity is directly proportional to $E$.
Q2

The Fermi-Dirac distribution function at $E = E_F$ gives a probability of:

  1. 0
  2. 1
  3. 0.5
  4. Depends on temperature
โœ… C. At $E = E_F$, $f(E_F) = \frac{1}{1+e^0} = \frac{1}{2} = 0.5$ for all temperatures.
Q3

The band gap of Silicon at room temperature is approximately:

  1. 0.67 eV
  2. 1.12 eV
  3. 1.43 eV
  4. 5.5 eV
โœ… B. Si โ‰ˆ 1.12 eV. Ge โ‰ˆ 0.67 eV. GaAs โ‰ˆ 1.43 eV. Diamond โ‰ˆ 5.5 eV.
Q4

The Hall coefficient for an n-type semiconductor is:

  1. Positive
  2. Negative
  3. Zero
  4. Infinite
โœ… B. For n-type, $R_H = -\frac{1}{ne}$ (negative because majority carriers are electrons).
Q5

In a p-type semiconductor, the Fermi level is:

  1. At the middle of the band gap
  2. Close to the conduction band
  3. Close to the valence band
  4. Above the conduction band
โœ… C. In p-type, acceptor impurities create holes, pulling the Fermi level toward the valence band.
Q6

Which material is used for LEDs because of its direct band gap?

  1. Silicon
  2. Germanium
  3. GaAs
  4. Diamond
โœ… C. GaAs has a direct band gap allowing efficient photon emission.
Q7

Effective mass of an electron is determined from the E-k diagram by:

  1. Slope of the curve
  2. Curvature (second derivative)
  3. Area under the curve
  4. Y-intercept
โœ… B. $m^* = \hbar^2 / (d^2E/dk^2)$. Greater curvature = smaller effective mass.
Q8

Diffusion current in a semiconductor is caused by:

  1. Electric field
  2. Concentration gradient
  3. Magnetic field
  4. Temperature gradient only
โœ… B. Diffusion current arises from carrier concentration gradients: $J_{diff} = -qD(dn/dx)$.
Q9

In CMOS technology, zero static power consumption is achieved because:

  1. Both transistors are always ON
  2. Only one transistor (NMOS or PMOS) is ON at a time
  3. No transistors are used
  4. Capacitors store the charge
โœ… B. In a CMOS inverter, NMOS and PMOS are complementary โ€” only one conducts at any time, so no DC path from VDD to ground.
Q10

The fill factor of a solar cell is the ratio of:

  1. $V_{OC}$ to $I_{SC}$
  2. Maximum power to ($V_{OC} \times I_{SC}$)
  3. Input power to output power
  4. Band gap to photon energy
โœ… B. $FF = \frac{P_{max}}{V_{OC} \cdot I_{SC}}$. Typical values: 0.7โ€“0.85.

๐Ÿ“‹ 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
Unit II

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.

๐Ÿ‡ฎ๐Ÿ‡ณ Power Grid CorpReliance JioBharti Airtel๐Ÿ‡ฎ๐Ÿ‡ณ BSNL

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:

  1. Electrons from n-side diffuse into p-side; holes from p-side diffuse into n-side.
  2. This creates a region depleted of free carriers: the depletion region.
  3. Immobile ions in the depletion region create a built-in potential $V_{bi}$ (โ‰ˆ0.7V for Si, 0.3V for Ge).
  4. 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

RegionConditionCurrent
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\%$
ParameterHalf-WaveFull-Wave (Bridge)
No. of diodes14
$V_{dc}$$V_m/\pi$$2V_m/\pi$
Ripple factor1.210.48
Efficiency40.6%81.2%
TransformerNot neededNot 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

RegionBE JunctionBC JunctionUse
ActiveForward biasedReverse biasedAmplification
SaturationForward biasedForward biasedSwitch ON
CutoffReverse biasedReverse biasedSwitch 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.

TypeSingle-ModeMulti-Mode
Core diameter8โ€“10 ฮผm50โ€“62.5 ฮผm
DistanceUp to 100 kmUp to 2 km
BandwidthVery highModerate
UseLong-haul telecomLAN, 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

Q1

In voltage division, the voltage across a resistor in series is proportional to:

  1. Its own resistance
  2. The other resistance
  3. Total current
  4. Total power
โœ… A. $V_1 = V_s \times R_1/(R_1+R_2)$, proportional to its own resistance.
Q2

The built-in potential of a silicon PN junction is approximately:

  1. 0.3 V
  2. 0.7 V
  3. 1.1 V
  4. 5.0 V
โœ… B. Si โ‰ˆ 0.7V, Ge โ‰ˆ 0.3V.
Q3

The ripple factor of a full-wave bridge rectifier is:

  1. 1.21
  2. 0.48
  3. 0.00
  4. 2.00
โœ… B. Full-wave bridge: $\gamma = 0.48$. Half-wave: $\gamma = 1.21$.
Q4

If $\beta = 200$ for a BJT and $I_C = 4$ mA, the base current is:

  1. 20 ฮผA
  2. 200 ฮผA
  3. 0.8 A
  4. 2 mA
โœ… A. $I_B = I_C/\beta = 4\text{mA}/200 = 20\mu$A.
Q5

In an optical fiber, total internal reflection occurs when:

  1. Angle of incidence < critical angle
  2. Angle of incidence > critical angle
  3. Core has lower refractive index than cladding
  4. Light exits through the cladding
โœ… B. TIR occurs when the angle of incidence exceeds the critical angle and core has higher refractive index.

๐Ÿ“‹ 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}$
Unit III

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.

GoogleIntelARM๐Ÿ‡ฎ๐Ÿ‡ณ CDAC

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$

2's complement is used universally in computers because it has a unique representation of zero (unlike 1's complement which has both +0 and -0) and allows subtraction using addition hardware.

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

GateSymbolExpression0,00,11,01,1
ANDAยทB$Y = A \cdot B$0001
ORA+B$Y = A + B$0111
NOTA'$Y = \overline{A}$Inverts: 0โ†’1, 1โ†’0
NAND(AยทB)'$Y = \overline{AB}$1110
NOR(A+B)'$Y = \overline{A+B}$1000
XORAโŠ•B$Y = A \oplus B$0110
XNOR(AโŠ•B)'$Y = \overline{A \oplus B}$1001
NAND and NOR are called universal gates because any Boolean function can be implemented using only NAND gates or only NOR gates. Example: NOT using NAND = connect both inputs together: $\overline{A \cdot A} = \overline{A}$.

Boolean Algebra

Important Laws

LawAND FormOR 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

  1. Groups must contain $2^n$ cells (1, 2, 4, 8, 16)
  2. Groups must be rectangular
  3. Groups can wrap around edges
  4. Every 1 must be covered by at least one group
  5. 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\CD00011110
001111
010000
110000
101111

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

Q1

$(255)_{10}$ in hexadecimal is:

  1. EE
  2. FF
  3. FE
  4. 1F
โœ… B. $255 = 15 \times 16 + 15 = FF_{16}$.
Q2

The 2's complement of 8-bit number 00110100 is:

  1. 11001011
  2. 11001100
  3. 11001010
  4. 00110101
โœ… B. 1's comp = 11001011, add 1 โ†’ 11001100.
Q3

Which gate is a universal gate?

  1. AND
  2. OR
  3. XOR
  4. NAND
โœ… D. NAND and NOR are universal gates.
Q4

De Morgan's theorem states $\overline{A+B}$ equals:

  1. $\overline{A} + \overline{B}$
  2. $\overline{A} \cdot \overline{B}$
  3. $A \cdot B$
  4. $A + B$
โœ… B. $\overline{A+B} = \overline{A} \cdot \overline{B}$ (De Morgan's Second Theorem).
Q5

The Excess-3 code for decimal 4 is:

  1. 0100
  2. 0111
  3. 1000
  4. 0011
โœ… B. 4 + 3 = 7 โ†’ 0111.
Q6

In a 4-variable K-map, a group of 4 cells eliminates how many variables?

  1. 1
  2. 2
  3. 3
  4. 4
โœ… B. Group of $2^n$ eliminates $n$ variables. Group of 4 = $2^2$ โ†’ eliminates 2 variables.

๐Ÿ“‹ 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.
Unit IV

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.

AppleQualcomm๐Ÿ‡ฎ๐Ÿ‡ณ CDAC PARAM

Adders & Subtractors

Half Adder

ABSumCarry
0000
0110
1010
1101

$Sum = A \oplus B$    $Carry = A \cdot B$

Full Adder

AB$C_{in}$Sum$C_{out}$
00000
00110
01010
01101
10010
10101
11001
11111
$$Sum = A \oplus B \oplus C_{in}$$ $$C_{out} = AB + C_{in}(A \oplus B)$$

A Full Adder = Two Half Adders + OR gate.

Half Subtractor

ABDifferenceBorrow
0000
0111
1010
1100

$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:

MintermA B CMUX InputValue
$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$
001000
010100
100010
110001

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)
0000XX0
0001001
001X011
01XX101
1XXX111

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{(A

MCQ Assessment โ€” Unit IV

Q1

A Full Adder has how many inputs and outputs?

  1. 2 inputs, 1 output
  2. 3 inputs, 2 outputs
  3. 2 inputs, 2 outputs
  4. 3 inputs, 3 outputs
โœ… B. 3 inputs (A, B, Cin) and 2 outputs (Sum, Cout).
Q2

A 4:1 MUX has how many select lines?

  1. 1
  2. 2
  3. 3
  4. 4
โœ… B. $2^n$ inputs needs $n$ select lines. $2^2=4$ โ†’ 2 select lines.
Q3

The borrow output of a Half Subtractor is:

  1. $A \cdot B$
  2. $\overline{A} \cdot B$
  3. $A \oplus B$
  4. $A + B$
โœ… B. $B_{out} = \overline{A} \cdot B$. Borrow is needed when A=0 and B=1.
Q4

A 3:8 decoder has how many output lines?

  1. 3
  2. 6
  3. 8
  4. 16
โœ… C. 3 input lines โ†’ $2^3 = 8$ output lines.
Q5

In a priority encoder, if both $D_2$ and $D_0$ are high, the output code represents:

  1. $D_0$
  2. $D_2$
  3. Both
  4. Invalid
โœ… B. Priority encoder outputs the code for the highest-priority active input ($D_2$ has higher priority).

๐Ÿ“‹ 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)$
Unit V

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."

IntelAMD๐Ÿ‡ฎ๐Ÿ‡ณ DRDOQualcomm

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)

SR$Q_{next}$$\overline{Q}_{next}$State
00$Q$$\overline{Q}$Hold / No change
0101Reset
1010Set
1100โŒ Invalid / Forbidden
The S=R=1 state is invalid because both Q and Q' become 0, violating the complementary requirement. When inputs return to S=R=0, the output is unpredictable (race condition).

D Latch

Eliminates the invalid state by using a single data input $D$. Internally: $S = D$, $R = \overline{D}$.

EnableD$Q_{next}$Action
0X$Q$Hold
100Reset
111Set

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$

SR$Q_{next}$
00$Q$ (Hold)
010 (Reset)
101 (Set)
11โŒ Invalid

Excitation Table (given desired transition, find required inputs):

$Q$$Q_{next}$SR
000X
0110
1001
11X0

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}$

JK$Q_{next}$Action
00$Q$Hold
010Reset
101Set
11$\overline{Q}$Toggle

Excitation Table:

$Q$$Q_{next}$JK
000X
011X
10X1
11X0

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:

  1. Master (first FF): Captures input on the positive edge (clock = 1)
  2. Slave (second FF): Transfers master's output on the negative edge (clock = 0)
  3. Since master and slave never operate simultaneously, race condition is eliminated.

Flip-Flop Conversion

General Procedure:

  1. Write the characteristic table of the desired flip-flop.
  2. Write the excitation table of the available flip-flop.
  3. For each row, determine the required inputs of the available FF.
  4. 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)
0000X
0111X
100X1
111X0

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

TypeInputOutputApplication
SISOSerialSerialTime delay
SIPOSerialParallelSerial-to-parallel conversion
PISOParallelSerialParallel-to-serial conversion
PIPOParallelParallelTemporary storage, buffer

SISO Operation Example

Loading data 1011 into a 4-bit SISO register (MSB first):

ClockInput$Q_3$$Q_2$$Q_1$$Q_0$
Initialโ€”0000
111000
200100
311010
411101

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
00000
10011
20102
30113
41004
51015
61106
71117
80000 (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

Q1

The characteristic equation of a JK flip-flop is:

  1. $Q_{next} = J + K$
  2. $Q_{next} = J\overline{Q} + \overline{K}Q$
  3. $Q_{next} = JK$
  4. $Q_{next} = J \oplus K$
โœ… B. $Q_{next} = J\overline{Q} + \overline{K}Q$.
Q2

The SR latch has an invalid state when:

  1. S=0, R=0
  2. S=0, R=1
  3. S=1, R=0
  4. S=1, R=1
โœ… D. Both S and R high causes both Q and Q' to be 0, violating complementary rule.
Q3

A T flip-flop with T=1 connected to a 10 MHz clock produces an output frequency of:

  1. 10 MHz
  2. 20 MHz
  3. 5 MHz
  4. 1 MHz
โœ… C. T=1 means toggle every clock edge โ†’ frequency division by 2 โ†’ 5 MHz.
Q4

To convert a JK flip-flop to a D flip-flop, connect:

  1. J=D, K=D
  2. J=D, K=$\overline{D}$
  3. J=$\overline{D}$, K=D
  4. J=1, K=D
โœ… B. $J=D$ and $K=\overline{D}$. When D=1: J=1,K=0 โ†’ Set. When D=0: J=0,K=1 โ†’ Reset.
Q5

A Mod-6 counter requires how many flip-flops?

  1. 2
  2. 3
  3. 4
  4. 6
โœ… B. $\lceil \log_2 6 \rceil = 3$ flip-flops. They count 0-7 but reset at 6 (110).
Q6

Which register type converts serial data to parallel?

  1. SISO
  2. SIPO
  3. PISO
  4. PIPO
โœ… B. SIPO = Serial In, Parallel Out.

๐Ÿ“‹ Unit V Summary โ€” All Characteristic Equations

Flip-FlopCharacteristic EquationSpecial Feature
SR$Q_{next} = S + \overline{R}Q$, SR=0Invalid 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.
Unit VI

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.

๐Ÿ‡ฎ๐Ÿ‡ณ Fasal๐Ÿ‡ฎ๐Ÿ‡ณ CropInArduinoRaspberry Pi๐Ÿ‡ฎ๐Ÿ‡ณ Smart Cities Mission

Analog vs Digital Signals

PropertyAnalog SignalDigital Signal
NatureContinuous (smooth wave)Discrete (0s and 1s)
ValuesInfinite values in a rangeOnly two levels (HIGH/LOW)
Noise immunityLow (susceptible to noise)High (noise can be filtered)
ProcessingOp-amps, analog circuitsMicrocontrollers, logic gates
ExampleTemperature, audio, voltageSwitch state, serial data
StorageDifficult, degrades over timeEasy, 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

ParameterValue
MicrocontrollerATmega328P
Clock Speed16 MHz
Flash Memory32 KB (0.5 KB for bootloader)
SRAM2 KB
EEPROM1 KB
Digital I/O Pins14 (6 provide PWM)
Analog Input Pins6 (A0โ€“A5)
Operating Voltage5V
Input Voltage7โ€“12V (via Vin/barrel jack)
DC Current per I/O20 mA (max 40 mA)

Pin Configuration

Pin CategoryPinsDescription
PowerVin, 5V, 3.3V, GNDPower supply and ground connections
Digital I/OD0โ€“D13Digital input/output. D0/D1 = Serial (TX/RX)
PWMD3, D5, D6, D9, D10, D11Analog-like output using pulse width modulation (marked with ~)
Analog InputA0โ€“A510-bit ADC (0โ€“1023 for 0โ€“5V)
CommunicationD10โ€“D13 (SPI), A4/A5 (I2C)SPI and I2C protocols for sensors/displays
OtherRESET, AREF, ICSPReset 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.

ParameterDHT11DHT22
Temperature Range0โ€“50ยฐC-40โ€“80ยฐC
Temp Accuracyยฑ2ยฐCยฑ0.5ยฐC
Humidity Range20โ€“80% RH0โ€“100% RH
Humidity Accuracyยฑ5%ยฑ2โ€“5%
Sampling Rate1 Hz (once/sec)0.5 Hz (once/2 sec)
Price~โ‚น50~โ‚น200
ResolutionInteger only0.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.

India's Smart Cities Mission (100 cities, โ‚น48,000 crore) deploys IoT sensors for traffic management, waste monitoring, water quality, and air pollution. Cities like Pune, Surat, and Bhopal use Arduino-compatible sensors in public infrastructure.
IoT freelancing on Fiverr and Upwork pays $20โ€“100/hr for Arduino projects. Common gigs: home automation, sensor data logging, prototype development. Indian students earn โ‚น15,000โ€“50,000/month doing IoT freelancing!

MCQ Assessment โ€” Unit VI

Q1

Arduino Uno uses which microcontroller?

  1. ATmega2560
  2. ATmega328P
  3. ESP8266
  4. STM32
โœ… B. Arduino Uno uses ATmega328P at 16 MHz.
Q2

The resolution of Arduino's built-in ADC is:

  1. 8-bit (256 levels)
  2. 10-bit (1024 levels)
  3. 12-bit (4096 levels)
  4. 16-bit
โœ… B. Arduino Uno has a 10-bit ADC โ†’ $2^{10} = 1024$ levels, mapping 0โ€“5V to 0โ€“1023.
Q3

The HC-SR04 ultrasonic sensor uses which formula for distance?

  1. $d = v \times t$
  2. $d = (t \times 0.034) / 2$
  3. $d = t / 340$
  4. $d = 2t \times v$
โœ… B. $d = \frac{time(\mu s) \times 0.034}{2}$ cm. Divide by 2 because sound travels to object and back.
Q4

DHT22 is better than DHT11 in terms of:

  1. Price
  2. Sampling speed
  3. Accuracy and range
  4. Power consumption
โœ… C. DHT22 has ยฑ0.5ยฐC accuracy vs DHT11's ยฑ2ยฐC, and wider range (-40 to 80ยฐC).
Q5

An LDR's resistance in bright light is approximately:

  1. 1 Mฮฉ
  2. 100 kฮฉ
  3. 10 kฮฉ
  4. 1 kฮฉ
โœ… D. LDR: dark โ‰ˆ 1 Mฮฉ, bright light โ‰ˆ 1 kฮฉ. Resistance decreases with light.
Q6

Which Arduino pins support PWM output?

  1. All digital pins
  2. Only analog pins
  3. D3, D5, D6, D9, D10, D11
  4. D0 and D1 only
โœ… C. PWM pins are marked with ~ symbol: 3, 5, 6, 9, 10, 11.

๐Ÿ“‹ 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.
--- Content truncated. Add to cart to read more. ---