Sensors & Measurement · Study deck

Sensor Circuits: Switching and Interface Safety

A GPIO pin is a software-controlled signal pin.

Physics Phoebe is your guide for this deck.

sensorcircuits
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: My GPIO pins are like a small child -- they can push a light doorbell button (small current), but they can't push open a heavy door (big current).
  • Explain: Step 3: Design the return-to-station transistor driver: When rain is detected, the MCU activates an illustrative 20 mA relay coil to signal the controller.
  • Explain: This provides good voltage range (3.15V to 0.58V across rain conditions) while keeping current well under the 0.5 mA budget.
  • Explain: Step 2: Design the RC noise filter: The motor EMI noise at 20 kHz must be filtered.
iotclass.org

Major section

Learning Points

Current Amplification: Small base current (~1mA) controls large collector current (~20mA).

  • Switching Action: Transistor acts as electronic switch (ON/OFF).
  • Current Gain (beta):: A small base current controls a larger collector current.
  • For example, a transistor with beta near 100 can let 0.1 mA at the base control about 10 mA through the load.

Why it matters

Efficiency: Saturation can reduce transistor power loss.

iotclass.org

Major section

Learning Points (continued)

Efficiency: Saturation can reduce transistor power loss.

  • Current Amplification: A GPIO limited to about 12 mA can switch a 500 mA load through a suitably rated driver; size base drive from the transistor's saturation data, not active-region gain alone.
  • Separate Load Supply: The load can have its own supply if the grounds and ratings are handled correctly.
  • Protection: A suitably rated driver and flyback path protect the controller.
iotclass.org

Major section

For Kids: Meet the Sensor Squad!

Temperature Terry was teaching a class about sensor circuits, and the whole squad was paying attention!

  • When I'm an LDR (light sensor), my resistance changes with light, so the voltage in the middle changes too!".
  • The resistor is like the narrow path, and the capacitor is like the sponge.
  • Lila here needs exactly the right amount of current -- too much and she burns out!

Key terms

When rain
When rain is detected, the MCU activates an illustrative 20 mA relay coil to signal the controller.
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

Rain sensor: Resistive rain sensor board (exposed PCB traces), resistance varies with wetness.

  • My GPIO pins are like a small child -- they can push a light doorbell button (small current), but they can't push open a heavy door (big current).
  • The current-limiting resistor is like a speed bump on a road.
  • MCU: ESP32, 3.3V GPIO, 12-bit ADC; usable input range depends on attenuation and calibration.
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

"And that's it!" Sammy concluded. "Four simple building blocks, and you can connect almost any sensor to any microcontroller.

  • Illustrative scenario: A robotic mower needs to detect rain onset within 5 seconds and signal its controller to return to a charging station.
  • Step 1: Design the voltage divider: The rain sensor is a variable resistor.
  • The rain signal changes slowly (seconds), so a low cutoff frequency is acceptable.
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

This provides good voltage range (3.15V to 0.58V across rain conditions) while keeping current well under the 0.5 mA budget.

  • Step 2: Design the RC noise filter: The motor EMI noise at 20 kHz must be filtered.
  • With the 47 kOhm/10 kOhm divider connected directly, its 8.25 kOhm Thevenin resistance adds to the filter resistance: the effective time constant is about 18.25 ms and the cutoff about 8.72 Hz.
  • Step 3: Design the return-to-station transistor driver: When rain is detected, the MCU activates an illustrative 20 mA relay coil to signal the controller.
iotclass.org

Deck summary

Key takeaways

Current Amplification: Small base current (~1mA) controls large collector current (~20mA).

  • Efficiency: Saturation can reduce transistor power loss.
  • Temperature Terry was teaching a class about sensor circuits, and the whole squad was paying attention!
  • Rain sensor: Resistive rain sensor board (exposed PCB traces), resistance varies with wetness.
  • "And that's it!" Sammy concluded. "Four simple building blocks, and you can connect almost any sensor to any microcontroller.
iotclass.org

Retrieval practice

Recall check 1 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q1You want to switch a 200mA motor from a 3.3V GPIO assumed to supply at most 12mA, using a 2N2222 transistor. Which conclusion about a beta=100 estimate is justified?

A260 Ω gives 10 mA base drive and proves motor saturation.
B1.3 kΩ gives about 2 mA base drive, but beta 100 does not prove saturation.
C10 kΩ limits base current while guaranteeing full motor current.
D100 Ω maximizes base current without exceeding the GPIO limit.
Show answer

Answer: B see answers page

iotclass.org

Retrieval practice

Recall check 2 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q2You need to drive a blue LED (forward voltage 3.2V, rated current 20mA) from a 5V supply. What resistor value should you use?

AA 250 Ω resistor from the full 5 V supply divided by 20 mA.
BA 90 Ω resistor from the 1.8 V drop divided by 20 mA.
CA 160 Ω resistor from the LED 3.2 V drop divided by 20 mA.
DNo series resistor because the LED supposedly limits its own current.
Show answer

Answer: B R = (Vsupply - Vf) / If = (5V - 3.2V) / 0.02A = 90 ohms. Use the nearest standard value like 100 ohms.

iotclass.org

Retrieval practice

Recall check 3 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q3An LDR (200 ohm in bright light, 10 kohm in dark) is placed as R1 (top) in a voltage divider with a 10 kohm fixed resistor R2 (bottom) and 3.3V supply. What happens to the output voltage at the midpoint as it gets darker?

AOutput voltage increases from 3.24V toward 3.3V
BThe output stays at 1.65 V because the light sensor's midpoint bias fixes its reading.
COutput voltage oscillates between 0V and 3.3V
DOutput voltage decreases from 3.24V toward 1.65V
Show answer

Answer: D Vout = 3.3V x R2/(R1+R2). Bright: 3.3 x 10k/10.2k = 3.24V. Dark: 3.3 x 10k/20k = 1.65V. Higher R1 means more voltage drops across the LDR, leaving less at the output.

iotclass.org

Retrieval practice

Recall check 4 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q4What turns a changing sensor resistance into a measurable node voltage?

AWheatstone Bridge
BAmplifier (Op-Amp)
CLow-Pass Filter
DVoltage Divider
Show answer

Answer: D It turns one changing resistance into a measurable node voltage.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. B · 200mA/100 = 2mA is an active-region estimate; (3.3V-0.7V)/2mA = 1.3kohm. The P2N2222A data sheet tests saturation at a forced ratio of 10, requiring about 20mA for 200mA, beyond the assumed 12mA GPIO budget. Use a suitable MOSFET or driver for this motor.
  2. B · R = (Vsupply - Vf) / If = (5V - 3.2V) / 0.02A = 90 ohms. Use the nearest standard value like 100 ohms.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. D · Vout = 3.3V x R2/(R1+R2). Bright: 3.3 x 10k/10.2k = 3.24V. Dark: 3.3 x 10k/20k = 1.65V. Higher R1 means more voltage drops across the LDR, leaving less at the output.
  2. D · It turns one changing resistance into a measurable node voltage.
iotclass.org