A slightly oddball technique I've used in the past is a reverse mode transistor, specifically a 2N2222, although I think a BC547 will work as well.
Basically you wire it up backwards: collector to ground, emitter to 5V (through a suitable resistor). Your input just goes to the base.
You need to check whatever NPN transistor you use for the Vebo rating. Not all can handle 5V in reverse, but the 2222 and 547 can handle up to 6V, so they are OK.
Your output is from the emitter, and should be a clean 0V - 5V square wave at low frequency (I've used this trick up to 100kHz), duly inverted as required.
Because reverse mode has terrible gain, you may need to buffer the output through another transistor to power your LED or whatever. If you have a cheap multimeter with transistor test socket, you can check the gain - just reverse the C and E connections. It'll probably read about 5-10, but it will still work.