Skip to content

Quiz: Buttons, Photoresistors, and Analog Sensor Input

Test your understanding of buttons, photoresistors, and analog sensor input with these review questions.


1. What is a voltage divider?

  1. A component whose resistance changes with light level
  2. A cutoff point separating one category of reading from another
  3. Two resistors wired in series across a power source, with the midpoint tapped as an output voltage that varies with one resistor's changing value
  4. A variable resistor with a rotating knob that a person can adjust by hand
Show Answer

The correct answer is C. A voltage divider is two resistors wired in series across a power source, with the midpoint between them tapped as the output; because the resistors share the total voltage in proportion to their resistances, a changing resistor (like a photoresistor) produces a changing midpoint voltage. Option A describes a photoresistor itself, option B describes a threshold value, and option D describes a potentiometer.

Concept Tested: Voltage Divider


2. Which statement correctly describes a passive buzzer?

  1. It has a built-in oscillator that produces one fixed tone the moment it receives power
  2. It can only be driven with a simple digital HIGH/LOW signal
  3. It requires an analog-to-digital converter to produce sound
  4. It has no built-in oscillator and vibrates at whatever frequency the driving signal changes, so code controls its pitch
Show Answer

The correct answer is D. A passive buzzer has no built-in oscillator circuit; it simply vibrates at whatever frequency the driving signal changes, giving code full control over pitch through tone generation. Option A describes an active buzzer instead, which produces one fixed tone with no pitch control. Option B describes how an active buzzer is typically driven, and option C incorrectly involves an ADC, which is used for reading inputs, not driving sound outputs.

Concept Tested: Passive Buzzer


3. Why does the chapter recommend calibrating a photoresistor's threshold on-site rather than copying a threshold value from a datasheet or another student's project?

  1. Because a datasheet threshold value is always mathematically incorrect
  2. Because different lighting conditions in different rooms produce very different "bright" and "dark" readings from the same photoresistor circuit
  3. Because calibration is required by the Pico's ADC hardware before any reading can be taken
  4. Because a potentiometer must be used instead of a fixed threshold in every circuit
Show Answer

The correct answer is B. The chapter warns that overhead fluorescent lights, a sunny window, and a closet all produce wildly different "bright" and "dark" readings from the exact same photoresistor circuit, so calibration means testing under the real conditions the project will operate in. Option A overstates the issue as an inherent datasheet error, option C misattributes calibration to a hardware requirement, and option D wrongly makes a potentiometer mandatory.

Concept Tested: Calibration


4. How does a reed switch typically get used in a security system, according to the chapter?

  1. A magnet is mounted on the door frame and a reed switch on the door itself, so moving the magnet away lets a program detect the door has opened
  2. It measures the ambient temperature near a door to detect if it has been left open
  3. It generates a tone whenever a person walks near the door
  4. It measures the humidity level to detect if a door or window is open to the outside
Show Answer

The correct answer is A. A reed switch's two thin metal contacts snap together only when a magnet is held near it, so mounting a magnet on the door frame and the reed switch on the door lets a program detect "door open" the instant the magnet moves away. Option B confuses it with a temperature sensor, option C confuses it with a buzzer, and option D confuses it with a humidity sensor — none of which the reed switch measures.

Concept Tested: Reed Switch


5. How does a moving average filter differ from debounce code in the problem each one solves?

  1. A moving average filter is used exclusively with digital sensors, while debounce is used exclusively with analog sensors
  2. Debounce and moving average filtering are two names for exactly the same technique
  3. Debounce ignores readings for a short time right after a detected change, while a moving average continuously blends several readings together over time
  4. A moving average filter eliminates the need for a threshold value, while debounce requires one
Show Answer

The correct answer is C. Debounce ignores readings for a short, deliberate pause right after a detected change, filtering out a mechanical switch's brief bounce, while a moving average filter continuously blends several recent readings together to smooth out ongoing noise in a continuously varying analog signal. Option A reverses the typical use case. Option B incorrectly treats them as identical, and option D invents an unsupported relationship to threshold values.

Concept Tested: Moving Average Filter


6. A moving average filter with WINDOW_SIZE = 3 has just processed the readings 10, 20, and 30, in that order, filling its buffer. A new reading of 60 arrives. What does the filter report after this new reading is processed?

  1. 30
  2. 40
  3. 60
  4. 36.67
Show Answer

The correct answer is D. When 60 arrives, the buffer [10, 20, 30] appends it to become [10, 20, 30, 60]; since this exceeds WINDOW_SIZE of 3, the oldest reading (10) is dropped, leaving [20, 30, 60]. The average is (20 + 30 + 60) / 3 = 110 / 3 ≈ 36.67. Option A is just the most recent pre-update value, option B miscalculates the average, and option C is simply the newest raw reading with no averaging applied.

Concept Tested: Moving Average Filter


7. A student wants a passive piezo buzzer to sound the musical note A4 (440 Hz) using MicroPython's PWM class. Which line of code correctly sets the buzzer's pitch to that note?

  1. buzzer.freq(440)
  2. buzzer.duty_u16(440)
  3. buzzer = Pin(18, Pin.OUT); buzzer.value(440)
  4. buzzer.sampling_rate(440)
Show Answer

The correct answer is A. Tone generation on a passive buzzer works by setting the PWM signal's frequency directly, and buzzer.freq(440) sets that frequency in hertz, which becomes the pitch heard since the buzzer has no built-in oscillator of its own. Option B confuses frequency with duty cycle, which controls volume/clarity, not pitch. Option C treats the buzzer as a simple digital output, which would only work for an active buzzer, and option D uses a nonexistent method.

Concept Tested: Tone Generation


8. A student wants to build a small weather station that reports both the room's air temperature and its relative humidity from a single sensor module. Which component from this chapter best fits this need?

  1. A photoresistor wired into a voltage divider
  2. A reed switch paired with a magnet
  3. A DHT11 sensor
  4. A passive buzzer driven with tone generation
Show Answer

The correct answer is C. The DHT11 sensor is a low-cost combined temperature-and-humidity sensor module that communicates over a single digital data pin and returns both a temperature value and a relative humidity percentage from one read, exactly matching the scenario. Option A measures light, not temperature or humidity. Option B detects magnet proximity, and option D is an output component for sound, not a sensor at all.

Concept Tested: DHT11 Sensor


9. A student increases a moving average filter's window size from 5 to 30 readings while keeping the sampling rate constant. Based on the chapter's discussion of the filter's tradeoffs, what is the most likely result?

  1. The filtered signal will react instantly to genuine changes with no added smoothing benefit
  2. The filtered signal will smooth out more noise, but it will also lag further behind genuine changes in the underlying sensor reading
  3. The sampling rate will automatically increase to compensate for the larger window
  4. The filter will stop working once the window size exceeds 10 readings
Show Answer

The correct answer is B. The chapter explains that a larger window smooths more aggressively but reacts more slowly to a genuine change in the sensor's environment, meaning more noise reduction comes at the cost of increased lag. Option A describes the opposite tradeoff. Option C incorrectly links window size to sampling rate, which are independent settings, and option D invents an artificial limit not mentioned anywhere in the chapter.

Concept Tested: Moving Average Filter


10. A student wires a button to trigger an interrupt handler instead of using a polling loop, expecting this to automatically solve the bouncing-contact problem. After testing, a single press still triggers the handler multiple times. What does the chapter say about this situation?

  1. Interrupt handlers are immune to mechanical bounce, so the wiring must be faulty
  2. Interrupt handlers can only be used with analog sensors, not digital buttons
  3. The button must be replaced with a tilt switch, which does not bounce
  4. Debounce logic still matters with interrupts, since a bouncing switch triggers the handler multiple times just as fast as it would trigger a polling loop
Show Answer

The correct answer is D. The chapter explicitly notes that debounce logic still matters with interrupts, because a bouncing switch will trigger the handler multiple times just as fast as it would trigger a polling loop, which is why most interrupt-based button code adds its own short timing check inside the handler. Option A incorrectly claims interrupts are immune to bounce. Option B is false since interrupt handlers work with digital buttons, and option C misdiagnoses the fix as a different sensor type.

Concept Tested: Interrupt Handler