PHY 175 · Modern Physics and Electronics

Sequential Logic Circuits
& Arduino Programming

Unit IV
Course Code   PHY175
Credits   3 – 0 – 0 – 3
Weightage   ATT 5 · CA 25 · MTT 20 · ETT 50

Course Outcome CO5 & CO6

CO5: Analyze the characteristics and operation of sequential logic circuits including flip-flops, registers, and counters.
CO6: Demonstrate Arduino programming, sensor interfacing (DHT11/DHT22), and IoT monitoring applications.

Table of Contents

IIntroduction to Sequential Logic3
IILatches — SR, D, JK4
IIIFlip-Flops — SR, D, JK, T6
IVTriggering — Level & Edge8
VFlip-Flop Conversions9
VIShift Registers — SISO, SIPO, PISO, PIPO10
VIIShift Register Applications12
VIIICounters — Asynchronous & Synchronous13
IXMod-N Counters & UP/DOWN Counters15
XRing & Johnson Counters17
XIArduino Programming Basics18
XIIArduino Digital & Analog I/O20
XIIIDHT11 / DHT22 Sensor Interfacing22
XIVArduino-Based IoT Monitoring Systems24
XVSmart Home Automation with Arduino26
XVIProteus Simulation & Circuit Design27
Summary & Formula Sheet28
Exam Tips & Practice Questions29
Solutions31
References & CO Mapping33
How to use these notes: Each section contains theory, key formulas, circuit diagrams, Arduino code examples, and exam-focused tips. The summary sheet at the end is designed for quick revision before exams.

I. Introduction to Sequential Logic

1.1 Combinational vs Sequential Logic

FeatureCombinational LogicSequential Logic
Output depends onPresent inputs onlyPresent inputs + past state (memory)
MemoryNoYes
ClockNot requiredUsually required
FeedbackNoYes
ExamplesAdders, MUX, decodersFlip-flops, registers, counters
SpeedFasterSlower (due to clock)

1.2 What is a Sequential Circuit?

A sequential circuit is a digital circuit whose output depends not only on the current inputs but also on the previous state of the circuit. This memory capability is provided by flip-flops.

1.3 Block Diagram

┌──────────────────────────────────────┐ │ │ │ Inputs ──→ ┌──────────────┐ │ │ │ Combinational│──→ Outputs │ │ Logic │ │ │ └──────┬───────┘ │ │ │ │ │ ▼ │ │ ┌──────────────┐ │ │ │ Memory │ │ │ │ (Flip-Flops)│ │ │ └──────┬───────┘ │ │ │ │ │ └─────────────────┘ │ (feedback) └──────────────────────────────────────┘ ↑ Clock

1.4 Types of Sequential Circuits

TypeDescriptionExamples
SynchronousState changes synchronized with a clockCounters, registers
AsynchronousState changes occur without a common clockRipple counters, latches

1.5 Clock Signal

A clock is a periodic square wave that synchronizes state changes in sequential circuits. It has two important parameters:

Clock: ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ │ │ │ │ │ │ ────────┘ └──┘ └──┘ └──┘ └──── Rising edge ↑ (0→1) Falling edge ↓ (1→0)

II. Latches — SR, D, JK

2.1 What is a Latch?

A latch is a bistable memory device that changes state based on input levels (not clock edges). It is the simplest form of sequential circuit.

2.2 SR Latch (NOR-based)

Built from two cross-coupled NOR gates. Has two inputs (S = Set, R = Reset) and two outputs (Q, Q̄).

┌───────┐ S ──│ NOR │──┬── Q │ │ │ └───┬───┘ │ │ │ │ ┌───┘ │ │ ┌───┴──┴──┐ R ──│ NOR │──┬── Q̄ └─────────┘ │ ↑ │ └────────┘
SRQ (next)State
00Q (hold)Memory
010Reset
101Set
11InvalidNot allowed
Invalid State

When S = R = 1, both outputs try to be 0, violating the Q and Q̄ complementarity. This is called the race condition or invalid state.

2.3 Gated SR Latch

Adds an Enable (E) input to control when the latch can change state. Uses NAND gates.

2.4 D Latch (Data Latch)

Eliminates the invalid state of the SR latch by using a single data input D and an Enable input. When E = 1, Q follows D; when E = 0, Q holds its value.

┌───────┐ D ──│ │──┬── Q │ D │ │ E ──│ Latch │ │ └───────┘ │ ▼ Q̄ (optional)
EDQ (next)State
0XQ (hold)Memory
100Reset
111Set

2.5 JK Latch

A JK latch resolves the invalid state of the SR latch: when J = K = 1, the output toggles.

JKQ (next)State
00Q (hold)Memory
010Reset
101Set
11Q̄ (toggle)Toggle

II-b. Latch Comparison & Examples

2.6 Comparison of Latches

Feature SR Latch D Latch JK Latch
InputsS, RD, EJ, K
Invalid stateYes (S=R=1)NoNo
ToggleNoNoYes (J=K=1)
TransparencyLevel-sensitiveLevel-sensitiveLevel-sensitive
ApplicationsSwitch debouncingData storageCounters

2.7 Race-Around Condition

In a JK latch with J = K = 1, the output toggles repeatedly while the enable is high. This is called the race-around condition. It is solved by using edge-triggered flip-flops instead of latches.

\[ \text{Race-around occurs when } J = K = 1 \text{ and } t_{enable} > t_{propagation} \]

2.8 Latch vs Flip-Flop

FeatureLatchFlip-Flop
TriggerLevel-sensitiveEdge-sensitive
Race-aroundPossibleNot possible
Clock inputEnable (E)Clock (CLK)
SpeedFasterSlightly slower
UsageSimple storageRegisters, counters
Worked Example · SR Latch State

Problem: An SR latch has S = 0, R = 0. If the previous state was Q = 1, what is the next state?

Solution:

With S = R = 0, the latch holds its previous state (memory mode).

Therefore, Q (next) = 1.

Worked Example · JK Latch Toggle

Problem: A JK latch has J = 1, K = 1, and current state Q = 0. What is the next state?

Solution:

When J = K = 1, the latch toggles. So Q (next) = Q̄ = 1.

III. Flip-Flops — SR, D, JK, T

3.1 What is a Flip-Flop?

A flip-flop is an edge-triggered bistable memory device that changes state only at a clock edge (rising or falling). It is the fundamental building block of sequential circuits.

3.2 SR Flip-Flop

┌────────┐ S ──│ │── Q │ SR │ CLK ─│ FF │ │ │── Q̄ R ──│ │ └────────┘
SRCLKQ (next)State
00Q (hold)Memory
010Reset
101Set
11InvalidNot allowed

3.3 D Flip-Flop

Also called a delay flip-flop or data flip-flop. Output Q follows input D at the active clock edge.

┌────────┐ D ──│ │── Q │ D │ CLK ─│ FF │ │ │── Q̄ └────────┘
DCLKQ (next)
00
11
X0 or ↓Q (hold)
\[ Q_{next} = D \]

3.4 JK Flip-Flop

The JK flip-flop eliminates the invalid state of the SR flip-flop. When J = K = 1, the output toggles.

JKCLKQ (next)State
00Q (hold)Memory
010Reset
101Set
11Q̄ (toggle)Toggle
\[ Q_{next} = J\overline{Q} + \overline{K}Q \]

3.5 T Flip-Flop (Toggle)

The T flip-flop is a single-input version of the JK flip-flop with J = K = T. When T = 1, output toggles; when T = 0, output holds.

TCLKQ (next)State
0Q (hold)Memory
1Q̄ (toggle)Toggle
\[ Q_{next} = T \oplus Q \]

III-b. Flip-Flop Comparison & Examples

3.6 Comparison of Flip-Flops

Flip-Flop Inputs Characteristic Equation Key Feature
SRS, R\( Q_{next} = S + \overline{R}Q \)Invalid state when S=R=1
DD\( Q_{next} = D \)Data transfer
JKJ, K\( Q_{next} = J\overline{Q} + \overline{K}Q \)No invalid state; toggles
TT\( Q_{next} = T \oplus Q \)Toggle

3.7 Characteristic Tables vs Excitation Tables

TablePurpose
Characteristic TableGiven current state and inputs, find next state
Excitation TableGiven current state and next state, find required inputs

JK Excitation Table

Q (present)Q (next)JK
000X
011X
10X1
11X0

D Excitation Table

Q (present)Q (next)D
000
011
100
111
Worked Example · D Flip-Flop

Problem: A D flip-flop has D = 1 applied at the rising edge of the clock. If the current state is Q = 0, what is the next state?

Solution:

\[ Q_{next} = D = 1 \]

The output becomes 1.

Worked Example · T Flip-Flop

Problem: A T flip-flop has T = 1 and current state Q = 1. Find the next state.

Solution:

\[ Q_{next} = T \oplus Q = 1 \oplus 1 = 0 \]

The output toggles to 0.

Worked Example · JK Flip-Flop

Problem: A JK flip-flop has J = 0, K = 1. If current state Q = 1, find the next state.

Solution:

When J = 0 and K = 1, the flip-flop resets.

Therefore, Q (next) = 0.

IV. Triggering — Level & Edge

4.1 Level Triggering

In level triggering, the flip-flop responds to the input as long as the clock is at a particular level (high or low). This is characteristic of latches.

Clock: ┌────────┐ ┌────────┐ │ │ │ │ ────────┘ └────────┘ └──── Active Active Active Active High Low High Low Output responds throughout the active level → transparent

4.2 Edge Triggering

In edge triggering, the flip-flop responds only at the moment the clock transitions. This eliminates the race-around condition.

Positive Edge Triggering (Rising Edge)

Output changes when the clock transitions from 0 → 1.

Negative Edge Triggering (Falling Edge)

Output changes when the clock transitions from 1 → 0.

Clock: ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ │ │ │ │ │ │ ────────┘ └──┘ └──┘ └──┘ └──── ↑ ↓ ↑ ↓ Rising Falling Rising Falling Positive edge: changes at ↑ Negative edge: changes at ↓

4.3 Master-Slave Configuration

Two flip-flops connected in cascade — the master is triggered on one edge and the slave on the opposite edge. This eliminates race-around and provides reliable edge-triggered behavior.

┌─────────┐ ┌─────────┐ │ Master │────→│ Slave │────→ Q │ FF │ │ FF │ └────┬────┘ └────┬────┘ │ │ CLK (rising) CLK (falling) ↑ ↑ triggered triggered

4.4 Triggering Comparison

FeatureLevel TriggeringEdge Triggering
ResponseEntire active levelOnly at edge
Race-aroundPossibleNot possible
TransparencyYesNo
Used inLatchesFlip-flops
ReliabilityLowerHigher

V. Flip-Flop Conversions

5.1 Why Convert Flip-Flops?

Different flip-flop types are available in IC form. Being able to convert one type to another allows a designer to use the available IC efficiently. Conversion involves designing combinational logic that feeds the available flip-flop's inputs to mimic the desired flip-flop's behavior.

5.2 SR to JK Flip-Flop

We need to find S and R in terms of J, K, and Q:

JKQQ (next)SR
00000X
0011X0
01000X
011001
100110
1011X0
110110
111001
\[ S = J\overline{Q} \qquad R = KQ \]

5.3 SR to D Flip-Flop

DQQ (next)SR
0000X
01001
10110
111X0
\[ S = D \qquad R = \overline{D} \]

5.4 JK to D Flip-Flop

\[ J = D \qquad K = \overline{D} \]

5.5 JK to T Flip-Flop

\[ J = T \qquad K = T \]

5.6 D to JK Flip-Flop

\[ D = J\overline{Q} + \overline{K}Q \]
Worked Example · SR to JK Conversion

Problem: Design a JK flip-flop using an SR flip-flop.

Solution:

From the excitation table, \( S = J\overline{Q} \) and \( R = KQ \).

Circuit: Connect \( S \) to \( J \cdot \overline{Q} \) and \( R \) to \( K \cdot Q \) using AND gates. Feed Q back to the AND gates.

VI. Shift Registers — SISO, SIPO, PISO, PIPO

6.1 What is a Shift Register?

A shift register is a cascade of flip-flops that shifts binary data one position per clock pulse. It is used for temporary data storage and serial/parallel data conversion.

6.2 SISO (Serial-In Serial-Out)

Data enters one bit at a time and exits one bit at a time. After 4 clock pulses, the input data appears at the output.

Serial In ──→ FF₀ ──→ FF₁ ──→ FF₂ ──→ FF₃ ──→ Serial Out ↑ ↑ ↑ ↑ CLK CLK CLK CLK (all flip-flops share the same clock)

6.3 SIPO (Serial-In Parallel-Out)

Data enters serially but is available in parallel at the outputs of all flip-flops.

Serial In ──→ FF₀ ──→ FF₁ ──→ FF₂ ──→ FF₃ ↓ ↓ ↓ ↓ Q₀ Q₁ Q₂ Q₃ (parallel outputs)

6.4 PISO (Parallel-In Serial-Out)

Data is loaded in parallel and shifted out serially. Requires additional logic for parallel loading.

Parallel In: D₀ D₁ D₂ D₃ ↓ ↓ ↓ ↓ ┌─[FF₀]─[FF₁]─[FF₂]─[FF₃]─┐ │ ↓ ↓ ↓ ↓ │ └── MUX-based parallel load ─┘ ↓ Serial Out

6.5 PIPO (Parallel-In Parallel-Out)

Data is loaded in parallel and read out in parallel. Used as a temporary storage register.

Parallel In: D₀ D₁ D₂ D₃ ↓ ↓ ↓ ↓ ┌─[FF₀]─[FF₁]─[FF₂]─[FF₃]─┐ │ ↓ ↓ ↓ ↓ │ └── Q₀ Q₁ Q₂ Q₃ ──┘ (parallel outputs)

VI-b. Shift Register Comparison & Examples

6.6 Comparison of Shift Registers

Type Data In Data Out Application Pins
SISOSerialSerialDelay line, buffering2 + clock
SIPOSerialParallelSerial-to-parallel conversionn + 2
PISOParallelSerialParallel-to-serial conversionn + 2
PIPOParallelParallelData storage2n + 1

6.7 Shift Register Operations

OperationDescription
Shift LeftEach bit moves one position to the left; LSB gets 0
Shift RightEach bit moves one position to the right; MSB gets 0
Rotate LeftMSB wraps around to LSB
Rotate RightLSB wraps around to MSB
Arithmetic ShiftPreserves sign bit (MSB)
Logical ShiftFills vacated position with 0
Worked Example · SISO Shift Register

Problem: A 4-bit SISO shift register initially contains 0000. The input sequence is 1, 0, 1, 1 (MSB first). Show the register contents after each clock pulse.

Solution:

ClockInputFF₀FF₁FF₂FF₃
0 (initial)0000
111000
200100
311010
411101

After 4 clocks, output = 1 (the first input bit).

Worked Example · SIPO Conversion

Problem: Serial input 1011 is shifted into a 4-bit SIPO register. What are the parallel outputs after 4 clock pulses?

Solution:

After 4 clocks, the register contains the input bits in order: FF₀=1, FF₁=0, FF₂=1, FF₃=1.

Parallel outputs: Q₀=1, Q₁=0, Q₂=1, Q₃=1 → 1011

6.8 Universal Shift Register (IC 74LS194)

A 4-bit bidirectional universal shift register that supports:

VII. Shift Register Applications

7.1 Serial-to-Parallel Conversion

A serial data stream is converted into parallel data. Used in communication receivers, where serial data arrives on a single line.

7.2 Parallel-to-Serial Conversion

Parallel data is converted into a serial stream for transmission. Used in communication transmitters, saving transmission lines.

7.3 Delay Line

A SISO shift register delays the input by \( n \) clock cycles, where \( n \) is the number of flip-flops.

\[ \text{Delay} = n \times T_{clock} \]

7.4 Sequence Generator

A shift register with feedback can generate a repeating sequence of bits (e.g., pseudo-random binary sequences used in cryptography and testing).

7.5 Ring Counter

A ring counter is a shift register with the output of the last flip-flop fed back to the input of the first. It circulates a single 1 through the register.

┌────[FF₀]──[FF₁]──[FF₂]──[FF₃]────┐ │ ↓ ↓ ↓ ↓ │ └────┘ │ │ │ │ Q₀ Q₁ Q₂ Q₃ (feedback from Q₃ to input of FF₀) Initial: 1000 → 0100 → 0010 → 0001 → 1000...

7.6 Johnson Counter (Twisted Ring)

Similar to a ring counter, but the complemented output of the last flip-flop is fed back. A 4-bit Johnson counter has 8 states (2n).

┌────[FF₀]──[FF₁]──[FF₂]──[FF₃]────┐ │ ↓ ↓ ↓ ↓ │ │ │ │ │ │ │ └────┼──────┼──────┼──────┘ │ │ │ │ ↑ │ └──────┴──────┴──────┘ (from Q̄₃) Sequence (4-bit): 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001, 0000...

7.7 Applications Summary

ApplicationRegister TypeFunction
Serial communicationSIPO / PISOData conversion
Data storagePIPOTemporary buffer
Delay lineSISOTime delay
Sequence generationRing / JohnsonPattern generation
Pseudo-random numbersLFSRTesting, crypto

VIII. Counters — Asynchronous & Synchronous

8.1 What is a Counter?

A counter is a sequential circuit that counts clock pulses. It is built from flip-flops and produces a binary count sequence.

8.2 Asynchronous (Ripple) Counter

In an asynchronous counter, the clock is applied only to the first flip-flop. Each subsequent flip-flop is clocked by the output (Q) of the previous one. This creates a ripple effect.

CLK ──→ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │ FF₀ │ │ FF₁ │ │ FF₂ │ │ FF₃ │ │ T │ │ T │ │ T │ │ T │ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ Q₀──→CLK Q₁──→CLK Q₂──→CLK Q₃ │ │ │ │ ▼ ▼ ▼ ▼ LSB MSB Output: Q₃ Q₂ Q₁ Q₀ (binary count)

4-bit Asynchronous UP Counter

ClockQ₃Q₂Q₁Q₀Decimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
..................
15111115
1600000 (rolls over)

8.3 Modulus of a Counter

The modulus (mod) of a counter is the number of unique states it goes through before repeating.

\[ \text{Modulus} = 2^n \quad \text{for an } n\text{-bit counter} \]

8.4 Synchronous Counter

In a synchronous counter, all flip-flops are clocked simultaneously by the same clock. Additional combinational logic determines the next state. This eliminates the ripple delay and allows higher-speed operation.

┌─────────────────────────────┐ CLK ──┼─────┬─────┬─────┬─────────┐ │ ↓ ↓ ↓ ↓ │ │ ┌─────┐┌─────┐┌─────┐┌─────┐ │ │ │ FF₀ ││ FF₁ ││ FF₂ ││ FF₃ │ │ │ └──┬──┘└──┬──┘└──┬──┘└──┬──┘ │ │ │ │ │ │ │ │ └─────┴─────┴─────┴────────┘ │ Combinational Logic │ (determines next state) ┘

IX. Mod-N Counters & UP/DOWN Counters

9.1 Mod-N Counter Design

A Mod-N counter counts from 0 to N−1 and then resets. It is designed by decoding the state N and using it to reset the flip-flops.

Steps to Design a Mod-N Counter

  1. Find the number of flip-flops: \( n = \lceil \log_2 N \rceil \)
  2. Determine the reset state (binary equivalent of N).
  3. Connect the flip-flop outputs corresponding to 1s in N to a NAND gate.
  4. The NAND gate output clears all flip-flops (active-low reset).

9.2 Example: Mod-6 Counter

Design a Mod-6 counter (counts 0–5, then resets). Requires \( n = \lceil \log_2 6 \rceil = 3 \) flip-flops.

Count sequence: 000 → 001 → 010 → 011 → 100 → 101 → (110 = 6 → reset) When Q₂ Q₁ Q₀ = 110, reset all flip-flops.
\[ \text{Reset condition} = Q_2 \cdot Q_1 \cdot \overline{Q_0} \]

9.3 Mod-N Counter Table

ModulusFlip-FlopsCount RangeReset State
Mod-210–12
Mod-420–34
Mod-630–56
Mod-830–78 (natural)
Mod-1040–910
Mod-1240–1112
Mod-1640–1516 (natural)

9.4 UP/DOWN Counter

An UP/DOWN counter can count either upward (0, 1, 2, …) or downward (…, 2, 1, 0) based on a control input.

UP Counter (Count Up)

Each flip-flop toggles when all previous flip-flops are 1.

DOWN Counter (Count Down)

Each flip-flop toggles when all previous flip-flops are 0.

UP/DOWN Control ──→ Mode Select │ ▼ ┌──────────────┴──────────────┐ │ │ UP Mode DOWN Mode (Q₀ toggles each clock) (Q₀ toggles each clock) Q₁ toggles when Q₀=1 Q₁ toggles when Q₀=0 Q₂ toggles when Q₁Q₀=11 Q₂ toggles when Q₁Q₀=00

9.5 4-bit UP/DOWN Counter Truth Table (Partial)

UP/DOWNQ₃ Q₂ Q₁ Q₀Next State
1 (UP)00000001
1 (UP)00100011
1 (UP)11110000 (roll)
0 (DOWN)00001111 (roll)
0 (DOWN)00110010
0 (DOWN)00010000
Worked Example · Mod-10 Counter

Problem: Design a Mod-10 (decade) counter using JK flip-flops.

Solution:

Mod-10 requires 4 flip-flops (since \( 2^4 = 16 > 10 \)).

Count sequence: 0000 → 0001 → ... → 1001 (9) → 0000.

When the state reaches 1010 (10), reset all flip-flops.

Reset condition: \( Q_3 \cdot \overline{Q_2} \cdot Q_1 \cdot \overline{Q_0} \)

Worked Example · Counter Frequency Division

Problem: A 4-bit ripple counter has a 1 MHz clock. What is the frequency at the output of the last flip-flop?

Solution:

Each flip-flop divides frequency by 2.

\[ f_{out} = \frac{f_{in}}{2^n} = \frac{1 \text{ MHz}}{2^4} = \frac{1000 \text{ kHz}}{16} = 62.5 \text{ kHz} \]

X. Ring & Johnson Counters

10.1 Ring Counter

A ring counter is a shift register with the output of the last flip-flop fed back to the input of the first. A single 1 circulates through the register.

┌────[FF₀]──[FF₁]──[FF₂]──[FF₃]────┐ │ ↓ ↓ ↓ ↓ │ └────┘ │ │ │ │ Q₀ Q₁ Q₂ Q₃ (Q₃ fed back to FF₀) Initial: 1000 Clock 1: 0100 Clock 2: 0010 Clock 3: 0001 Clock 4: 1000 (repeats)

Ring Counter Properties

10.2 Johnson Counter (Twisted Ring)

A Johnson counter feeds back the complemented output of the last flip-flop. It has \( 2n \) states (twice as many as a ring counter).

┌────[FF₀]──[FF₁]──[FF₂]──[FF₃]────┐ │ ↓ ↓ ↓ ↓ │ │ │ │ │ │ │ └────┼──────┼──────┼──────┘ │ │ │ │ ↑ (from Q̄₃) └──────┴──────┴──────┘ Initial: 0000 Clock 1: 1000 Clock 2: 1100 Clock 3: 1110 Clock 4: 1111 Clock 5: 0111 Clock 6: 0011 Clock 7: 0001 Clock 8: 0000 (repeats)

10.3 Ring vs Johnson Counter

Feature Ring Counter Johnson Counter
FeedbackQ of last FFQ̄ of last FF
Number of statesn2n
EncodingOne-hotProgressive
Number of 1sExactly oneMultiple (varies)
Self-startingNoNo (usually)
ApplicationsSequencer, timingFrequency division, timing

10.4 Applications of Counters

ApplicationCounter TypeDescription
Frequency divisionAny ripple counterDivide input frequency
Digital clocksMod-60, Mod-24Time-keeping
Event countingMod-NCount objects/events
Timing sequencesRing / JohnsonControl signals
Program counter (CPU)SynchronousInstruction addressing
Analog-to-digital convertersSynchronousCounter-ramp ADC
Frequency countersSynchronousMeasure frequency

XI. Arduino Programming Basics

11.1 What is Arduino?

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It consists of a microcontroller board (e.g., Arduino Uno with ATmega328P) and an Integrated Development Environment (IDE) for writing code.

11.2 Arduino Uno Specifications

FeatureSpecification
MicrocontrollerATmega328P
Operating Voltage5 V
Digital I/O Pins14 (6 with PWM)
Analog Input Pins6 (10-bit ADC)
Flash Memory32 KB
SRAM2 KB
EEPROM1 KB
Clock Speed16 MHz

11.3 Arduino IDE Structure

Every Arduino sketch has two required functions:

void setup() {
  // Runs once at startup
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // Runs repeatedly
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

11.4 Data Types in Arduino

TypeSizeRange
boolean1 byte0 or 1
byte1 byte0–255
int2 bytes−32,768 to 32,767
long4 bytes−2,147,483,648 to 2,147,483,647
float4 bytes3.4 × 10⁻³⁸ to 3.4 × 10³⁸
char1 byte−128 to 127

11.5 Common Arduino Functions

FunctionPurposeExample
pinMode()Set pin directionpinMode(13, OUTPUT);
digitalWrite()Set digital outputdigitalWrite(13, HIGH);
digitalRead()Read digital inputint val = digitalRead(2);
analogRead()Read analog input (0–1023)int val = analogRead(A0);
analogWrite()PWM output (0–255)analogWrite(9, 128);
delay()Wait in millisecondsdelay(1000);
Serial.begin()Initialize serial portSerial.begin(9600);
Serial.println()Print to serial monitorSerial.println("Hello");
millis()Milliseconds since bootunsigned long t = millis();

XII. Arduino Digital & Analog I/O

12.1 Digital I/O

Digital pins can be configured as either INPUT or OUTPUT. They read or write binary values (HIGH = 5 V, LOW = 0 V).

// Blink LED on pin 13
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);  // LED ON
  delay(500);
  digitalWrite(13, LOW);   // LED OFF
  delay(500);
}

12.2 Reading a Push Button

const int BUTTON_PIN = 2;
const int LED_PIN = 13;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int state = digitalRead(BUTTON_PIN);
  if (state == LOW) {        // button pressed
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
}

12.3 Analog Input (ADC)

Arduino Uno has a 10-bit ADC, giving values 0–1023. The reference voltage is typically 5 V.

\[ V_{measured} = \frac{\text{ADC value}}{1023} \times V_{ref} \]
// Read analog voltage from A0
void setup() {
  Serial.begin(9600);
}

void loop() {
  int adcValue = analogRead(A0);
  float voltage = (adcValue / 1023.0) * 5.0;
  Serial.print("ADC: ");
  Serial.print(adcValue);
  Serial.print("  Voltage: ");
  Serial.println(voltage);
  delay(500);
}

12.4 Analog Output (PWM)

Some digital pins support PWM (Pulse Width Modulation), which simulates analog output by rapidly switching the pin on and off.

\[ V_{avg} = \frac{\text{PWM value}}{255} \times 5\,\text{V} \]
// Fade LED on pin 9
void setup() {
  pinMode(9, OUTPUT);
}

void loop() {
  for (int i = 0; i <= 255; i++) {
    analogWrite(9, i);
    delay(10);
  }
  for (int i = 255; i >= 0; i--) {
    analogWrite(9, i);
    delay(10);
  }
}

XIII. DHT11 / DHT22 Sensor Interfacing

13.1 What is DHT11 / DHT22?

The DHT11 and DHT22 are low-cost digital temperature and humidity sensors. They output calibrated digital signals over a single-wire protocol.

13.2 Comparison of DHT11 and DHT22

Feature DHT11 DHT22 (AM2302)
Temperature Range0 – 50 °C−40 – 80 °C
Temperature Accuracy±2 °C±0.5 °C
Humidity Range20 – 90 % RH0 – 100 % RH
Humidity Accuracy±5 % RH±2 % RH
Sampling Rate1 Hz (1 sec)0.5 Hz (2 sec)
Operating Voltage3.3 – 5 V3.3 – 6 V
CostLowModerate

13.3 Pin Configuration

PinNameFunction
1VCCPower supply (3.3–5 V)
2DATADigital data output
3NCNot connected
4GNDGround

13.4 Circuit Connection

Arduino Uno DHT11/DHT22 ─────────── ──────────── 5V ────────────────── VCC (Pin 1) D2 ──┬─────────────── DATA (Pin 2) │ 10kΩ (pull-up) │ 5V ──┘ GND ───────────────── GND (Pin 4)

13.5 Arduino Code for DHT11

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11   // or DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.print(" °C  |  Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
  delay(2000);
}

13.6 Applications

XIV. Arduino-Based IoT Monitoring Systems

14.1 What is IoT?

The Internet of Things (IoT) refers to the network of physical devices embedded with sensors, software, and connectivity that enables them to collect and exchange data over the internet.

14.2 IoT Architecture

┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ Sensors │───→│ Arduino / │───→│ Cloud / │ │ (DHT, LDR) │ │ ESP8266 │ │ Server │ └──────────────┘ └──────────────┘ └──────┬───────┘ │ ▼ ┌──────────────┐ │ User App / │ │ Dashboard │ └──────────────┘

14.3 IoT Monitoring System Components

ComponentFunction
SensorsCollect data (temperature, humidity, light, motion)
MicrocontrollerProcess data (Arduino, ESP32, NodeMCU)
CommunicationWi-Fi, Bluetooth, GSM, LoRa
Cloud PlatformStore and analyze data (ThingSpeak, Blynk, AWS)
User InterfaceMobile app, web dashboard

14.4 Example: IoT Temperature Monitoring

#include <DHT.h>
#include <ESP8266WiFi.h>

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected!");
}

void loop() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();

  // Send to ThingSpeak or other cloud platform
  Serial.print("Temp: ");
  Serial.print(t);
  Serial.print(" °C, Hum: ");
  Serial.println(h);

  delay(30000);  // Send every 30 seconds
}

14.5 Popular IoT Platforms

PlatformFeatures
ThingSpeakFree MATLAB-based IoT analytics
BlynkMobile app for IoT control
FirebaseReal-time database
AWS IoTScalable enterprise IoT
Adafruit IOSimple cloud dashboard

14.6 Applications of IoT Monitoring

XV. Smart Home Automation with Arduino

15.1 What is Smart Home Automation?

Smart home automation uses sensors, microcontrollers, and communication networks to automatically control home appliances such as lights, fans, air conditioners, and security systems.

15.2 Components of a Smart Home System

ComponentFunction
Arduino / ESP32Central controller
PIR motion sensorDetect presence
LDR (light sensor)Measure ambient light
DHT11Temperature & humidity
Relay moduleControl AC appliances
Wi-Fi moduleRemote access
Mobile app / WebUser interface

15.3 Example: Automatic Light Control

const int LDR_PIN = A0;
const int LED_PIN = 9;
const int THRESHOLD = 500;  // Adjust as needed

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(LDR_PIN);
  Serial.print("Light: ");
  Serial.println(lightLevel);

  if (lightLevel < THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);  // Dark → turn on
  } else {
    digitalWrite(LED_PIN, LOW);   // Bright → turn off
  }
  delay(200);
}

15.4 Example: Temperature-Based Fan Control

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11
#define FAN_PIN 9

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
  pinMode(FAN_PIN, OUTPUT);
}

void loop() {
  float temp = dht.readTemperature();

  if (temp > 30.0) {
    digitalWrite(FAN_PIN, HIGH);  // Fan ON
    Serial.println("Fan ON (temp > 30°C)");
  } else {
    digitalWrite(FAN_PIN, LOW);   // Fan OFF
    Serial.println("Fan OFF");
  }
  delay(2000);
}

15.5 Advantages of Smart Home Automation

XVI. Proteus Simulation & Circuit Design

16.1 What is Proteus?

Proteus is a circuit simulation and PCB design software. It allows students and engineers to design circuits, simulate behavior, and test code (including Arduino sketches) before building physical prototypes.

16.2 Key Features

FeatureDescription
ISIS (Schematic Capture)Draw circuit diagrams with components
ARES (PCB Layout)Design printed circuit boards
Mixed-Mode SimulationAnalog + digital simulation
Microcontroller SimulationSimulate Arduino, PIC, AVR code
Virtual InstrumentsOscilloscope, logic analyzer, etc.

16.3 Simulating Arduino in Proteus

  1. Install Proteus and the Arduino library for Proteus.
  2. Place the Arduino Uno board in the schematic.
  3. Connect external components (LEDs, sensors, etc.).
  4. Write the Arduino sketch in the Arduino IDE.
  5. Compile the sketch to generate a .hex file.
  6. Load the .hex file into the Arduino board in Proteus.
  7. Run the simulation and observe the behavior.

16.4 Example: Blink LED in Proteus

┌─────────────────┐ │ Arduino Uno │ │ │ │ D13 ─────┼────[ 220Ω ]────[ LED ]──── GND │ │ └─────────────────┘ Simulation: LED blinks at 1 Hz.

16.5 Proteus Component Library

CategoryComponents
MicrocontrollersArduino Uno, PIC, AVR, 8051
PassiveResistors, Capacitors, Inductors
SemiconductorsDiodes, BJTs, MOSFETs
Digital ICsLogic gates, Flip-flops, Counters, MUX
DisplayLCD, 7-segment, LED matrix
SensorsTemperature, LDR, PIR, Ultrasonic
InstrumentsOscilloscope, Voltmeter, Ammeter

16.6 Advantages of Proteus Simulation

Summary & Formula Sheet

Flip-Flops

Flip-FlopCharacteristic EquationExcited Inputs
SR\( Q_{next} = S + \overline{R}Q \)S, R
D\( Q_{next} = D \)D
JK\( Q_{next} = J\overline{Q} + \overline{K}Q \)J, K
T\( Q_{next} = T \oplus Q \)T

Flip-Flop Conversions

ConversionRequired Logic
SR → JK\( S = J\overline{Q} \), \( R = KQ \)
SR → D\( S = D \), \( R = \overline{D} \)
JK → D\( J = D \), \( K = \overline{D} \)
JK → T\( J = T \), \( K = T \)
D → JK\( D = J\overline{Q} + \overline{K}Q \)

Shift Registers

TypeInputOutputApplication
SISOSerialSerialDelay line
SIPOSerialParallelSerial-to-parallel
PISOParallelSerialParallel-to-serial
PIPOParallelParallelData storage

Counters

Counter TypeClockModulusNotes
Ripple (async)Only first FF\( 2^n \)Slow, ripple delay
SynchronousAll FFs\( 2^n \)Fast, no ripple
Mod-NEitherNReset at N
RingAll FFsnOne-hot
JohnsonAll FFs2nTwisted ring

Arduino Key Functions

FunctionPurpose
pinMode(pin, mode)Set pin as INPUT/OUTPUT
digitalWrite(pin, value)Write HIGH/LOW
digitalRead(pin)Read digital input
analogRead(pin)Read analog (0–1023)
analogWrite(pin, value)PWM output (0–255)
delay(ms)Wait milliseconds
Serial.begin(baud)Initialize serial
Serial.println(data)Print to serial monitor

Sensor Formulas

\[ V_{measured} = \frac{\text{ADC value}}{1023} \times 5\,\text{V} \] \[ V_{PWM} = \frac{\text{PWM value}}{255} \times 5\,\text{V} \]

Exam Tips & Practice Questions

Top 12 Exam Tips
  1. Memorize characteristic equations of all flip-flops — they're the foundation.
  2. Remember: latch = level-triggered; flip-flop = edge-triggered.
  3. The invalid state in SR flip-flop occurs when S = R = 1.
  4. JK flip-flop resolves the invalid state by toggling when J = K = 1.
  5. Race-around condition occurs in level-triggered JK latches when J=K=1.
  6. Master-slave configuration eliminates race-around.
  7. For SISO shift register: after n clocks, input appears at output.
  8. Modulus of an n-bit counter = 2ⁿ (unless Mod-N).
  9. Ring counter has n states; Johnson counter has 2n states.
  10. Arduino ADC: 10-bit → 0–1023 for 0–5 V.
  11. PWM: 8-bit → 0–255 for 0–5 V average.
  12. DHT11 has ±2°C / ±5% accuracy; DHT22 has ±0.5°C / ±2% accuracy.

Practice Questions

Q1 · SR Latch Easy

An SR latch has S = 1, R = 0. What is the next state if the current state is Q = 0? What if Q = 1?

Q2 · Flip-Flop Comparison Easy

Compare latches and flip-flops. Why is edge triggering preferred over level triggering?

Q3 · JK Flip-Flop Medium

A JK flip-flop has J = 1, K = 0, and current state Q = 0. Find the next state. Then, if J = 1, K = 1, find the next state.

Q4 · Flip-Flop Conversion Medium

Design a JK flip-flop using an SR flip-flop. Write the required logic expressions.

Q5 · Shift Register Medium

A 4-bit SIPO shift register initially contains 0000. The input sequence is 1, 0, 0, 1 (LSB first). Show the register contents after each clock.

Q6 · Counter Design Hard

Design a Mod-6 counter using JK flip-flops. Show the state table and reset logic.

Q7 · Ring vs Johnson Medium

Compare ring counter and Johnson counter. How many states does each have for 4 flip-flops?

Q8 · Arduino ADC Easy

An Arduino reads analog value 512 on pin A0. What is the measured voltage?

Q9 · Arduino Programming Medium

Write an Arduino sketch to read temperature from a DHT11 sensor and turn on an LED if the temperature exceeds 30°C.

Q10 · IoT System Hard

Describe the architecture of an IoT-based temperature monitoring system using Arduino, DHT11, and a cloud platform.

Solutions to Practice Questions

Solution Q1 · SR Latch

When S = 1, R = 0, the latch is in the Set state.

Regardless of the current state (0 or 1), the next state will be Q = 1.

Solution Q2 · Flip-Flop Comparison

Latch: Level-triggered, transparent when enable is active, can have race-around.

Flip-Flop: Edge-triggered, samples input only at clock edge, no race-around.

Edge triggering is preferred because it provides predictable, synchronized operation and avoids the race-around condition that causes unreliable behavior in latches.

Solution Q3 · JK Flip-Flop

Case 1: J = 1, K = 0, Q = 0

\[ Q_{next} = J\overline{Q} + \overline{K}Q = 1 \cdot 1 + 1 \cdot 0 = 1 \]

Next state: Q = 1 (Set).

Case 2: J = 1, K = 1, Q = 0

\[ Q_{next} = 1 \cdot 1 + 0 \cdot 0 = 1 \]

Next state: Q = 1 (Toggle).

Solution Q4 · JK from SR

From the excitation table:

\[ S = J\overline{Q} \qquad R = KQ \]

Connect AND gates between J and Q̄ (for S), and between K and Q (for R).

Solution Q5 · SIPO Shift Register

Input sequence (LSB first): 1, 0, 0, 1

ClockInputFF₀FF₁FF₂FF₃
00000
111000
200100
300010
411001

After 4 clocks: parallel outputs Q₀Q₁Q₂Q₃ = 1001.

Solution Q6 · Mod-6 Counter

Flip-flops needed: \( n = \lceil \log_2 6 \rceil = 3 \).

State sequence: 000 → 001 → 010 → 011 → 100 → 101 → (110 resets)

Reset logic: When Q₂ Q₁ Q₀ = 110, reset all flip-flops.

Reset condition: \( \text{Reset} = Q_2 \cdot Q_1 \cdot \overline{Q_0} \)

This signal is applied to the active-low clear input of the JK flip-flops.

Solution Q7 · Ring vs Johnson
FeatureRing CounterJohnson Counter
States for 4 FFs48
FeedbackQ of last FFQ̄ of last FF
Number of 1sExactly 1Multiple
EncodingOne-hotProgressive
Solution Q8 · Arduino ADC
\[ V_{measured} = \frac{512}{1023} \times 5 = 2.502 \text{ V} \]

Approximately 2.5 V.

Solution Q9 · Arduino DHT11 + LED
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11
#define LED_PIN 9

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  float t = dht.readTemperature();
  if (isnan(t)) {
    Serial.println("Sensor error!");
    return;
  }
  if (t > 30.0) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  delay(2000);
}
Solution Q10 · IoT Architecture

Components: Arduino + DHT11 + ESP8266 (or NodeMCU) + Cloud

  1. Sensor Layer: DHT11 collects temperature and humidity.
  2. Processing Layer: Arduino reads sensor data, processes it.
  3. Communication Layer: ESP8266 Wi-Fi module sends data to the cloud.
  4. Cloud Layer: ThingSpeak/Blynk stores and visualizes data.
  5. User Layer: Mobile app/web dashboard displays real-time and historical data.

References & CO Mapping

Textbooks

RefTitleAuthorPublisher
T-1Principles of ElectronicsV. K. Mehta and Rohit MehtaS. Chand & Company
R-1Electronic Devices and Circuit TheoryRobert L. Boylestad and Louis NashelskyPearson Education India
R-2Digital FundamentalsThomas L. FloydPearson Education India

Relevant Websites

RefWeb AddressFeature
RW-6electronicsforu.com/technology-trends/learn-electronics/flip-flop-rs-jk-t-dFlip-flop
RW-7testbook.com/electrical-engineering/asynchronous-countersAsynchronous counter (UP/DOWN/Mod-N)

Audio-Visual Aids

RefTopic
AV-7Operation of basic shift registers (SISO, SIPO, PISO, PIPO)
AV-8DHT11/DHT22

Software

RefToolPurpose
SW-1ProteusCircuit simulation
SW-2Arduino IDEArduino programming
SW-3Arduino sensors librariesDHT, LCD, etc.

Key Takeaways

  1. Sequential circuits have memory; outputs depend on present inputs and past state.
  2. Latches are level-triggered; flip-flops are edge-triggered.
  3. SR flip-flop has an invalid state when S = R = 1.
  4. JK flip-flop eliminates the invalid state and toggles when J = K = 1.
  5. D flip-flop: \( Q_{next} = D \); T flip-flop: \( Q_{next} = T \oplus Q \).
  6. Shift registers shift data one bit per clock; types: SISO, SIPO, PISO, PIPO.
  7. Asynchronous counters ripple; synchronous counters are clocked simultaneously.
  8. Modulus of an n-bit counter is 2ⁿ; Mod-N counters reset at N.
  9. Ring counter has n states; Johnson counter has 2n states.
  10. Arduino: setup() runs once, loop() runs repeatedly.
  11. DHT11/DHT22 measure temperature and humidity; use a 10kΩ pull-up resistor.
  12. Proteus allows virtual simulation of Arduino-based circuits before hardware build.

CO Mapping

CODescriptionSections Covered
CO5Analyze the characteristics and operation of sequential logic circuitsI, II, III, IV, V, VI, VII, VIII, IX, X
CO6Demonstrate Arduino programming and sensor interfacingXI, XII, XIII, XIV, XV, XVI

End of Unit IV

Sequential Logic · Flip-Flops · Shift Registers · Counters · Arduino Programming · Sensors · IoT

PHY 175 · Modern Physics and Electronics

Complete · Exam-Ready · Full Marks Guaranteed