543  Sensor Quiz and Practice Exercises

Learning Objectives

After completing this chapter, you will be able to:

  • Test your understanding of sensor fundamentals
  • Apply sensor concepts to practical scenarios
  • Identify gaps in your knowledge for further study

543.1 Prerequisites

  • Complete all previous chapters in the Sensor Fundamentals series

543.2 Knowledge Check Quiz

Test your understanding with these practice questions.

543.2.1 Question 1: Resolution vs Accuracy

A temperature sensor has 16-bit resolution (0.01C steps) and +/-3C accuracy. You need to detect temperature changes of 1C. Is this sensor suitable?

Click to reveal answer

Answer: YES, with caveats.

The 16-bit resolution allows detecting 0.01C changes, so 1C changes are easily detectable. However, the absolute temperature reading may be off by up to 3C. If you need to know the actual temperature (e.g., “is it above 25C?”), this sensor is problematic. If you only need to detect changes (e.g., “temperature rose 1C”), the sensor works fine because changes are relative.

Key insight: Resolution affects change detection; accuracy affects absolute measurement.

543.2.2 Question 2: Power Consumption

You’re designing a battery-powered soil moisture monitor with a 2000mAh battery. The sensor draws 150mA continuously with no sleep mode. How long will the battery last?

Click to reveal answer

Answer: About 13 hours.

Calculation: 2000mAh / 150mA = 13.3 hours

This is a critical design flaw! For a soil moisture monitor that should last months, you need either: 1. A sensor with sleep mode (<1uA standby) 2. A much larger battery 3. Solar power supplementation 4. A different sensing approach (capacitive sensors with low power)

Key insight: Always check if sensors have power-saving modes for battery applications.

543.2.3 Question 3: Nyquist Sampling

A vibration sensor detects frequencies up to 500 Hz. You’re sampling at 600 Hz and see a 100 Hz pattern that shouldn’t exist. What’s happening?

Click to reveal answer

Answer: Aliasing.

You’re sampling below the Nyquist rate (needs >1000 Hz to capture 500 Hz signals). A 500 Hz signal sampled at 600 Hz appears as |500-600| = 100 Hz.

Fix: Sample at least 1000 Hz (2x highest frequency), preferably 2000+ Hz for safety margin. Also add a hardware anti-aliasing filter (low-pass at 300 Hz) before the ADC.

Key insight: Nyquist theorem: sample at >2x the highest frequency component.

543.2.4 Question 4: I2C Troubleshooting

Your BMP280 pressure sensor isn’t detected on the I2C bus. The wiring looks correct. What should you check first?

Click to reveal answer

Answer: Check these in order:

  1. Pull-up resistors - I2C requires 4.7kohm pull-ups on SDA and SCL
  2. I2C address - SDO pin tied to GND = 0x76, VCC = 0x77
  3. Voltage levels - BMP280 is 3.3V; using 5V may damage it
  4. Run I2C scanner - Verify what addresses respond
  5. Check SDA/SCL pin assignments - Different ESP32 boards use different defaults
Most common cause: Missing pull-up resistors or floating SDO pin.

543.2.5 Question 5: Sensor Selection

You need to measure room temperature for a smart thermostat. Requirements: +/-0.5C accuracy, I2C interface, <$10, low power. Which sensor?

Click to reveal answer

Answer: BME280 or SHT31

Comparison: - DHT22: +/-0.5C accuracy, but NO I2C (digital single-wire only) - Fail - BME280: +/-1C accuracy (marginal), I2C, $5-8, low power - Acceptable - SHT31: +/-0.3C accuracy, I2C, $10-15, low power - Best if budget allows - DS18B20: +/-0.5C, but 1-Wire not I2C - Fail

Best choice: BME280 if +/-1C is acceptable (most thermostats have 1-2C deadband anyway), SHT31 if you need guaranteed +/-0.5C.

543.3 Practice Exercises

543.3.1 Exercise 1: Calibration

Your DHT22 consistently reads 2.3C higher than a reference thermometer. Write the calibration code.

# Your solution here
def read_calibrated_temperature():
    raw = dht.readTemperature()
    # Apply offset correction
    calibrated = raw - 2.3
    return calibrated

543.3.2 Exercise 2: Moving Average Filter

Implement a moving average filter for an ultrasonic distance sensor that occasionally produces outliers.

from collections import deque

# Your solution here
class MovingAverage:
    def __init__(self, window_size=5):
        self.window = deque(maxlen=window_size)

    def filter(self, value):
        self.window.append(value)
        return sum(self.window) / len(self.window)

Challenge: Modify to use a median filter instead for better outlier rejection.

543.3.3 Exercise 3: Battery Life Calculation

Calculate battery life for this system: - Battery: 3000mAh - MCU: 10mA active, 10uA sleep - Sensor: 1mA active (500ms), 0.1uA sleep - Reading interval: Every 10 minutes

Click to reveal solution

Calculation:

Per reading cycle (10 minutes): - MCU active: 500ms x 10mA = 0.005 mAh (during sensor read) - MCU sleep: 9.5 minutes x 10uA = 0.00158 mAh - Sensor active: 500ms x 1mA = 0.0005 mAh - Sensor sleep: 9.5 minutes x 0.1uA = 0.000016 mAh

Total per cycle: ~0.00708 mAh

Cycles per day: 144

Daily consumption: 144 x 0.00708 = 1.02 mAh

Battery life: 3000 / 1.02 = 2,941 days (8 years)

Note: Real-world factors (self-discharge, temperature, aging) reduce this significantly.

543.3.4 Exercise 4: Sensor Selection Matrix

Create a selection matrix for a weather station that needs: - Temperature (+/-0.5C) - Humidity (+/-3%) - Pressure (+/-1 hPa) - Budget: <$15 total

Requirement BME280 DHT22 + BMP280 SHT31 + BMP280
Temp accuracy +/-1C +/-0.5C +/-0.3C
Humidity accuracy +/-3% +/-2% +/-2%
Pressure accuracy +/-1 hPa +/-1 hPa +/-1 hPa
Cost $8 $5 + $5 = $10 $15 + $5 = $20
Complexity 1 chip 2 chips 2 chips

Decision: BME280 for simplicity, or DHT22 + BMP280 for better temperature accuracy within budget.

543.4 Summary

You’ve completed the Sensor Fundamentals quiz and exercises. Key concepts tested:

  1. Resolution vs accuracy distinction
  2. Power consumption calculations
  3. Nyquist sampling and aliasing
  4. I2C troubleshooting
  5. Sensor selection process
  6. Calibration techniques
  7. Filtering strategies

543.5 What’s Next

Congratulations on completing the Sensor Fundamentals series!

Continue your learning: - Sensor Interfacing - Advanced connection techniques - Actuators - Complete the sensing-actuation loop - Sensor Labs - More hands-on projects

Return to Sensor Fundamentals Index ->