1
\$\begingroup\$

There's Pin as both input (for a switch) and output (for LED) with ATmega32U4? but I also need one of six such pins to drive a piezo buzzer. Due to its capacitive nature, I figured it could be connected to the GPIO as well (has no effect on DC signals):

schematic

simulate this circuit – Schematic created using CircuitLab

The idea was to suppress the noise, that would likely originate from switching the GPIO from output-low (to drive the LED) to input-pull-up (for sampling the pushbutton), using a high pass filter with an "odd" 1.5 kHz or so, so sampling at 100 Hz or so does not affect the 4 kHz piezo as much.

Drawbacks (both are acceptable):

  • pushing the button lights the LED (and dumps C1's charge to ground; maybe add a series resistor?)
  • driving the piezo with a 4 kHz square wave lights the LED at 50 % (maybe this can be a lower duty-cycle due to the filter?)

Does this work and can it be improved?

\$\endgroup\$
3
  • \$\begingroup\$ how fast do you need the LED to turn on or off? \$\endgroup\$ Mar 12, 2018 at 14:00
  • \$\begingroup\$ @MarcusMüller It's just a status LED for humans: visible frequency for blinking would be in the 1 Hz range, so the transition should not take longer than maybe 0.1 s. \$\endgroup\$
    – handle
    Mar 12, 2018 at 14:20
  • \$\begingroup\$ See LED and Button Matrix multiplexing? for a different approach to possibly work around too few pins in the same situation. \$\endgroup\$
    – handle
    Mar 12, 2018 at 14:27

1 Answer 1

1
\$\begingroup\$

You can of course, instead of directly driving the LED, add a high-impedance low pass filter, driving a thresholding element (e.g. a transistor, a comparator with a reference, or an elegantly connected diode), which in turn drives the LED.

                                     +3.3V
                                       |
                                       R
                                       |
                                      LED
     +----High Pass----Piezo---GND     |
GPIO-+----------------Switch---GND   |/
     +----R_large---+----------------| 
                    |                |\
                    C                  v
                    |                  |
                   GND                GND
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.