16  Case Studies and Worked Examples

16.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Apply the hardware prototyping framework to real-world project scenarios
  • Trace a complete development journey from concept through certification to production
  • Calculate component selection trade-offs and power budget estimates
  • Evaluate design decisions using comprehensive review scenarios

Key Concepts

  • MVP (Minimum Viable Product): Earliest version of a product with enough features to satisfy early adopters and provide feedback for future development.
  • Iteration: Design-build-test cycle producing an improved prototype version based on lessons learned from the previous version.
  • Failure Analysis: Systematic investigation of a hardware or firmware failure to identify root cause and prevent recurrence.
  • Lessons Learned: Documented insights from a project that improve processes and avoid known pitfalls in future projects.
  • Scale-Up Challenge: Engineering, supply chain, and quality issues that emerge when moving from 10 prototype units to 10,000 production units.
  • Cost Reduction: Engineering effort to reduce BOM cost per unit after the initial product launch, improving margin at volume.
  • Technical Debt: Accumulated design shortcuts in firmware or hardware that reduce quality and increase future refactoring cost.

Prototyping is building rough, working versions of your IoT device to test ideas quickly and cheaply. Think of it like building a model airplane before constructing the real thing – a prototype reveals problems when they are still easy and inexpensive to fix. Modern prototyping tools make it possible to go from idea to working device in days rather than months.

“Case studies are stories about real prototyping projects – what worked, what failed, and what the builders learned,” said Max the Microcontroller. “Reading them is like getting advice from experienced engineers who already made the mistakes so you do not have to.”

Sammy the Sensor shared a common lesson: “Almost every case study mentions the same surprise – the first prototype never works as expected. Sensors behave differently in the real world than in the lab. Batteries drain faster than the datasheet predicts. And users interact with devices in ways nobody anticipated. That is why you prototype!”

Bella the Battery highlighted the cost lesson: “One case study showed that a team spent 200 dollars on their first prototype, found three critical design flaws, and fixed them for 50 dollars in the next version. If they had gone straight to production, those same flaws would have cost 50,000 dollars to fix. Prototyping is cheap insurance!” Lila the LED concluded, “Every worked example in this chapter is a real lesson. Study them, learn from them, and apply their lessons to your own projects!”

16.2 Hardware Prototyping Framework

A complete hardware prototyping framework helps you systematically approach IoT development:

16.2.1 Platform Selection

Compare platforms based on: - Processing power and memory - Connectivity options (Wi-Fi, BLE, LoRa, cellular) - Power consumption (active, sleep modes) - GPIO availability and interfaces - Development ecosystem and community - Cost and availability

16.2.2 Component Library

Maintain a catalog of: - Sensors with electrical specifications - Actuators with drive requirements - Communication modules with protocol details - Power components with efficiency data

16.2.3 Power Budget Analysis

Calculate for each state: - Active current draw - Idle/standby current - Deep sleep current - Estimate battery life based on duty cycles

Consider a soil moisture sensor node that wakes every 15 minutes, reads sensors for 5 seconds at 80 mA, then sleeps at 10 µA. The battery life calculation requires averaging over the duty cycle:

\[ I_{\text{avg}} = \frac{I_{\text{active}} \times t_{\text{active}} + I_{\text{sleep}} \times t_{\text{sleep}}}{t_{\text{total}}} \]

Substituting values for a 900-second cycle:

\[ I_{\text{avg}} = \frac{80\text{ mA} \times 5\text{ s} + 0.01\text{ mA} \times 895\text{ s}}{900\text{ s}} = \frac{400 + 8.95}{900} = 0.454\text{ mA} \]

With a 3000 mAh battery, the theoretical lifespan is \(3000 \div 0.454 = 6,607\) hours \(\approx\) 275 days. Accounting for battery self-discharge (2-3% per month) and capacity degradation at temperature extremes, practical deployments achieve 200-240 days between battery replacements.

Interactive Calculator: Battery Life from Duty Cycle

Experiment with different sensor configurations to see how duty cycle affects battery life:

Key Insights:

  • Reducing active current from 80 mA to 40 mA nearly doubles battery life
  • Sleep current under 10 µA becomes negligible compared to active phase
  • Longer cycle periods dramatically improve battery life (30 min vs 5 min = 6x longer)

16.2.4 Pin Management

Track and validate: - GPIO allocation and conflicts - Voltage level compatibility - Current sourcing/sinking requirements - Shared bus assignments (I2C, SPI)


16.3 Interactive Simulator: ESP32 IoT Dashboard

ESP32 Multi-Sensor IoT Dashboard

What This Simulates: Complete ESP32 IoT system integrating sensors, Wi-Fi, MQTT, and local display

System Architecture:

System architecture diagram showing ESP32 microcontroller connected to DHT22 temperature/humidity sensor, OLED display, and Wi-Fi connection to MQTT broker for cloud data publishing

How to Use:

  1. Click Start Simulation
  2. Watch sensors initialize and connect to Wi-Fi
  3. See MQTT connection established
  4. Observe sensor readings published every 5 seconds

Key Learning Points:

  1. Multi-Sensor Integration - Reading multiple I/O types simultaneously
  2. Wi-Fi Management - Connection handling with reconnection logic
  3. MQTT Publishing - Reliable data transmission to cloud
  4. JSON Formatting - Standard IoT data serialization
  5. Error Handling - Graceful failure recovery

16.4 Case Study: Smart Thermostat Development

This case study follows a complete development journey from concept to production.

16.4.1 Project Requirements

  • Wall-mounted smart thermostat
  • Temperature and humidity sensing
  • Occupancy detection (PIR)
  • Wi-Fi connectivity to cloud
  • Touchscreen display
  • 2-year target lifespan (with AC power)
  • FCC/CE certification required
  • Target retail price: $99

16.4.2 Phase 1: Proof of Concept (2 months)

Goals: Validate core functionality

Hardware:

  • ESP32 DevKit
  • DHT22 sensor (temperature/humidity)
  • PIR motion sensor
  • 2.4” TFT display

Key Learnings:

  • DHT22 too slow (2-second read time)
  • Display refresh causing Wi-Fi dropouts
  • Power consumption higher than expected

Iteration 1 Result: Core concept proven, identified technical risks

16.4.3 Phase 2: Alpha Prototype (3 months)

Improvements:

  • Replaced DHT22 with SHT31 (faster, more accurate)
  • Added display buffer to prevent Wi-Fi conflicts
  • First custom PCB design (2-layer)

PCB Issues Discovered:

  • Antenna keep-out zone violated (reduced Wi-Fi range)
  • Power supply noise coupling to ADC
  • Missing I2C pull-ups

Iteration 2 Result: Functional prototype, 3 PCB respins needed

16.4.4 Phase 3: Beta Prototype (4 months)

Refinements:

  • 4-layer PCB with proper ground plane
  • Switched to ESP32-S3 for improved performance
  • Added on-device ML for occupancy prediction
  • Production-intent enclosure design

Testing:

  • 30-day continuous operation test
  • Temperature chamber testing (-20C to +60C)
  • EMC pre-compliance testing

Iteration 3 Result: Production-intent design validated

16.4.5 Phase 4: Pre-Production (5 months)

Activities:

  • DFM (Design for Manufacturing) review
  • Test fixture development
  • Certification preparation (FCC, CE)
  • Small batch production (50 units)

Certifications:

  • FCC Part 15 testing: 2 iterations
  • CE marking: EMC + safety testing
  • Total certification cost: $18,000

16.4.6 Phase 5: Production (2 months)

Final Specifications:

  • ESP32-S3 (dual-core, Wi-Fi, 8MB flash)
  • SHT31 (temp/humidity), PIR (occupancy), BH1750 (light)
  • 3.5” resistive touchscreen
  • Wi-Fi 802.11n + Bluetooth LE
  • 24VAC transformer + Li-ion backup
  • 4-layer PCB, SMT assembly, injection-molded enclosure

Final BOM Cost: $142 at 1000 units Manufacturing Yield: 98.2%

16.4.7 Timeline Summary

Phase Duration PCB Revisions
POC 2 months 0 (breadboard)
Alpha 3 months 3
Beta 4 months 2
Pre-production 5 months 1
Certification 3 months 0
Production 2 months 0
Total 18 months 6 PCB versions

16.4.8 Key Takeaways

  1. Plan for 3+ PCB iterations - First designs rarely work perfectly
  2. Certification takes time and money - Budget 3 months and $15-20K
  3. Component selection matters - Wrong sensor choice cost 2 months
  4. DFM review is essential - Production issues are expensive
  5. Test in real conditions - Lab success does not equal field success

16.5 Comprehensive Review Quizzes

16.5.1 Quiz 1: Platform Selection

### Quiz 2: Component Knowledge

### Quiz 3: Debugging

### Quiz 4: PCB Manufacturing

### Quiz 5: Power Design (Multi-Select)

16.6

16.7 Knowledge Check: Development Timeline


Scenario: You’re designing a battery-powered soil monitoring node for vineyards that measures soil moisture, temperature, and electrical conductivity (EC) every 30 minutes. The node must operate for 12 months on a 3000 mAh battery and transmit data via LoRaWAN to a gateway 2 km away through hilly terrain. Select appropriate components and calculate expected battery life.

Step 1: Microcontroller Selection

Requirements: Low power, LoRa support, analog inputs for sensors, I2C/SPI for digital sensors.

Candidates: | MCU | Active Current | Sleep Current | LoRa Support | ADC Channels | Cost | Decision | |—–|—————|—————|————–|————–|——|———-| | Arduino Uno (ATmega328) | 45 mA | 0.1 µA | External module needed | 6 (10-bit) | $25 | ❌ No deep sleep, large footprint | | ESP32 | 80 mA | 10 µA | External module needed | 18 (12-bit) | $5 | ❌ Overkill (Wi-Fi unused), higher sleep current | | STM32L0 | 12 mA | 0.3 µA | External module needed | 16 (12-bit) | $8 | ✅ Selected: Ultra-low power, sufficient peripherals | | RAK3172 (STM32WL SoC) | 15 mA | 1.5 µA | Built-in | 7 (12-bit) | $12 | ✅ Best choice: Integrated LoRa, eliminates external module |

Decision: RAK3172 eliminates the need for an external LoRa module (saves $8, reduces PCB footprint, improves reliability). The slightly higher sleep current (1.5 vs 0.3 µA) is negligible compared to sensor and transmission energy.

Step 2: Soil Moisture Sensor Selection

Requirements: Corrosion-resistant (buried in soil for 12 months), low power, accurate in clay/loam soils.

Candidates: | Sensor Type | Principle | Current | Lifetime | Cost | Decision | |————-|———–|———|———-|——|———-| | Resistive (FC-28) | Metal probes measure resistance | 35 mA | 3-6 months (corrosion) | $2 | ❌ Corrodes quickly in soil | | Capacitive (DFRobot SEN0193) | Capacitance change with moisture | 5 mA | 12-24 months | $8 | ✅ Selected: Corrosion-resistant coating | | TDR (Decagon GS1) | Time domain reflectometry | 15 mA | 5+ years | $120 | ❌ Professional-grade, budget overkill |

Decision: Capacitive sensor ($8) balances cost, accuracy, and 12-month lifetime. Resistive sensors corrode within months. TDR is overkill for vineyard monitoring.

Step 3: Temperature and EC Sensors

Component Model Current Interface Cost Notes
Temperature DS18B20 1 mA 1-Wire $2 Waterproof, -55 to 125°C range
Soil EC Atlas Scientific EC-EZO 38 mA (reading) I2C $60 Buried-probe design, auto-calibration

Step 4: LoRa Module and Antenna

RAK3172 has built-in LoRa, but needs external antenna: - Antenna: 915 MHz dipole, 3 dBi gain, $4 - LoRa settings: SF9 (spreading factor 9), 125 kHz BW, +14 dBm TX power (enough for 2 km hilly terrain)

Step 5: Power Budget Calculation

Every 30 minutes (1800 seconds):

Operation Duration Current Energy (mAh)
Wake MCU 0.1 s 15 mA 0.00042
Read capacitive soil sensor 1.0 s 5 mA 0.00139
Read DS18B20 temperature 0.75 s 1 mA 0.00021
Read EC sensor 1.5 s 38 mA 0.01583
Process data 0.2 s 15 mA 0.00083
LoRa transmit (SF9, +14 dBm) 0.6 s 120 mA 0.02000
Active phase total 4.15 s 0.0387 mAh
Deep sleep 1795.85 s 1.5 µA 0.00075
Total per cycle 1800 s 0.0394 mAh

Daily energy: 48 cycles/day × 0.0394 mAh = 1.89 mAh/day

Battery life: 3000 mAh / 1.89 mAh/day = 1587 days = 4.3 years

The energy calculation converts time and current to charge capacity. For each operation, energy in mAh is computed as:

\[ E = I \times t_{\text{hours}} = I \times \frac{t_{\text{seconds}}}{3600} \]

For the LoRa transmission drawing 120 mA for 0.6 seconds:

\[ E_{\text{LoRa}} = 120\text{ mA} \times \frac{0.6\text{ s}}{3600\text{ s/h}} = 0.02\text{ mAh} \]

The average daily current becomes critical for battery sizing. With 48 cycles per day and 0.0394 mAh per cycle, the equivalent continuous current is:

\[ I_{\text{equivalent}} = \frac{1.89\text{ mAh/day}}{24\text{ h}} = 0.079\text{ mA} = 79\text{ µA} \]

This is remarkably low – the deep sleep current (1.5 µA) contributes only 2% of the total. The active phase, though brief (4.15 seconds of 1800), dominates the energy budget at 98%.

Result: The design exceeds the 12-month target by 4.3x. We can either: 1. Use a smaller 800 mAh battery (saves cost and PCB space) 2. Transmit more frequently (every 10 minutes instead of 30) 3. Add more sensors (wind speed, solar radiation)

Interactive Calculator: Component Energy Breakdown

Explore how different component currents and durations affect total energy consumption:

Optimization Tips:

  • LoRa transmission typically consumes 40-60% of total energy. Reduce SF (spreading factor) if range permits.
  • EC sensor draws high current. Consider duty-cycling power with a load switch.
  • Reading interval has huge impact: 10 min vs 30 min = 3x more energy consumption.
  • Deep sleep current under 10 µA becomes negligible at typical duty cycles.

Step 6: Cost Breakdown

Component Unit Cost Quantity Total
RAK3172 SoC $12 1 $12
Capacitive soil sensor $8 1 $8
DS18B20 temperature $2 1 $2
Atlas EC sensor $60 1 $60
LoRa antenna $4 1 $4
LiPo battery 800 mAh $6 1 $6
PCB + passives $5 1 $5
Enclosure (IP67) $8 1 $8
Total per node $105

For a 50-acre vineyard with 20 nodes: $105 × 20 = $2,100 hardware cost.

Comparison to off-the-shelf solution: Commercial soil sensor nodes (e.g., Sensoterra) cost $300-400 each = $6,000-8,000 for 20 nodes. Custom design saves $3,900-5,900 at 20-node scale.

Factor Continue Using Dev Boards Design Custom PCB
Quantity 1-10 prototypes 50+ units for deployment
Size constraint Enclosure fits dev board + breadboard Needs compact form factor
Power budget USB or wall-powered Battery-powered (dev board overhead 20-50 mA)
Cost per unit Dev board ($5-30) acceptable Need <$10 BOM cost
Reliability Short-term lab testing Long-term deployment (loose connections unacceptable)
Certification Not required FCC/CE/UL compliance needed (dev boards aren’t certified assemblies)
Features needed Using 80% of dev board features Using <30% (wasted components and cost)
Timeline Need working prototype this week 6-12 weeks for design, fabrication, testing
Team expertise Software-focused team Electrical engineering resources available

Typical progression:

  1. Proof of concept (Week 1-4): Breadboard + Arduino/ESP32 dev board
  2. Functional prototype (Week 5-12): Perfboard or dev board in enclosure for field testing
  3. Alpha PCB (Month 4-6): First custom PCB design, expect 2-3 respins
  4. Beta PCB (Month 7-10): Production-intent design with DFM review
  5. Production (Month 11+): Manufacturing at scale

Red flags that you need a custom PCB:

  • Dev board won’t fit in desired enclosure
  • Battery life is 10x shorter than required (due to dev board overhead)
  • Loose breadboard wires cause intermittent failures
  • Total BOM cost is >$50 when production target is <$20
  • External investors or customers demand “production-ready” hardware

Don’t rush to custom PCB too early: Companies often waste $10,000-20,000 on 3-4 PCB respins because they started custom design before requirements were stable. Fully validate functionality on dev boards first.

Common Mistake: Ignoring Environmental Factors Until Deployment

The Problem: A team designs and tests a soil moisture sensor indoors on a benchtop for 6 months. The prototype works perfectly. When deployed outdoors in a field, 80% of sensors fail within 2 weeks.

What went wrong:

  1. Moisture ingress: Indoor testing never exposed the sensor to rain. Water leaked into the enclosure through cable glands, corroding the PCB. The team used IP65 enclosures (splash-proof) instead of IP67 (submersion-proof). Lesson: Outdoor sensors need IP67+ enclosures with proper cable gland sealing.

  2. Temperature extremes: Lab testing at 20-25°C never revealed that the LiPo battery stops charging below 0°C. During winter nights (-5°C), batteries wouldn’t recharge, and sensors died. Lesson: Test across the full temperature range (-20°C to +60°C for outdoor sensors, not just room temp).

  3. Condensation: Morning dew caused condensation inside the enclosure, shorting the PCB. The team didn’t include desiccant packets or breather vents. Lesson: Sealed enclosures need desiccant and/or breather vents with hydrophobic membranes.

  4. UV degradation: After 6 months outdoors, the plastic enclosure became brittle and cracked, exposing electronics. The team used standard ABS plastic instead of UV-stabilized polycarbonate. Lesson: Outdoor enclosures need UV-stabilized materials.

  5. Wildlife interference: Rodents chewed through the sensor cables (attracted by soy-based cable insulation). Lesson: Use rodent-resistant cables or conduit for buried/outdoor installations.

The fix (environmental testing checklist):

Environmental Factor Test Method Acceptance Criteria
Water ingress Spray bottle + submerge for 1 hr No water inside enclosure
Condensation Freezer (-20°C) to hot room (+40°C) cycle No condensation on PCB
Temperature -20°C to +60°C for 24 hours Operates at all temps
UV exposure UV lamp for 500 hours No enclosure cracking
Vibration Shake test (vehicle/industrial) No loose components
Corrosion Salt spray (coastal/marine) No visible corrosion

When to test: During functional prototype phase (Phase 2), not after production starts. Environmental failures caught late cost 100x more to fix (redesign + new enclosure tooling + replace deployed units).

Common Pitfalls

Example code often uses fixed delays calibrated for one microcontroller clock speed that produce wrong timings on a different clock. Copying without checking can cause sensors to receive malformed I2C timing. Parameterise timing values from the clock speed constant and verify with a logic analyser on the actual target hardware.

Calling blocking sensor read functions within an MQTT callback can stall the network stack long enough for a watchdog reset or missed keep-alive. Trigger sensor reads from a timer, cache the latest value, and return cached data from any function called within a network callback.

Assuming a serial read() always returns a complete packet causes firmware to process partial payloads as valid data when bytes arrive in multiple TCP segments. Implement a length-prefixed or delimiter-terminated framing protocol and accumulate bytes into a ring buffer until a complete frame is received.

16.8 Summary

Hardware Prototyping Stages:

  • Proof of Concept (PoC): Core feasibility demonstration
  • Functional Prototype: Complete feature implementation
  • Engineering Prototype: Production-intent design
  • Pre-Production Prototype: Manufacturing validation

Platform Selection:

  • Microcontrollers (MCUs): Low power, real-time, limited resources
  • Microprocessors (MPUs): High performance, rich OS, abundant resources
  • Hybrid approaches: Combined MCU+MPU or System-on-Chip (SoC)

Best Practices:

  • Start simple, build incrementally
  • Design for testability with debug headers
  • Plan for 3+ PCB iterations
  • Budget time and money for certification
  • Test in real-world conditions

16.10 Concept Relationships

Hardware Prototyping Case Studies
├── Demonstrates: [Best Practices](prototyping-hw-best-practices.html) - Real-world application of guidelines
├── Validates: [PCB Design](prototyping-hw-pcb-design.html) - Multi-iteration design process
├── Uses: [Hardware Platforms](prototyping-hw-platforms.html) - ESP32, Arduino in production context
├── Applies: [Components](prototyping-hw-components.html) - Component selection worked examples
└── Feeds into: [Testing and Validation](../testing-validation/testing-validation.html) - Field testing methodologies

Case Study Lessons:

  1. Smart thermostat illustrates 18-month journey from concept to production
  2. Component selection shows decision matrices and power budgeting
  3. Debugging failures reveals environmental testing importance
  4. Cost analysis quantifies best practices ROI

16.11 What’s Next

If you want to… Read this
Learn the underlying programming paradigms Programming Paradigms and Tools
Apply examples to a full microcontroller project Microcontroller Programming Essentials
Explore best practices for production code Programming Best Practices