I’m working on a project to convert any sensor input into a digital high/low output. To debug the code, a variety of basic waveforms (square, triangle, sawtooth, sign, and noise) need to be fed in.
Other than for making square waves, surprisingly I’ve never needed an electronic waveform generator before now. Rather than order one for $40, I concluded it would be a much better use of my time to stop everything and cobble together my own. Because my original goal is to handle noisy inputs, I decided to use a real world sensor as input, instead of a simulated signal.
This is my long-winded way of saying that you can build your own waveform generator from the old record player in your basement and a simple light-sensor circuit on a breadboard. But, instead of playing a record, the turntable spins a disc with a pattern printed on paper by an ordinary computer printer.
Repurposed turntable spinning waveform disc
The paper disc lacks grooves, so the waveform disc is read with a light sensor rather than a needle.
Waveform disc being read by light sensor
Because this is my wife’s turntable, I am apparently not allowed to “break it”. Therefore, a 3D printed cartridge is temporarily placed at the end of the player arm, above the existing needle cartridge. A white LED provides a consistent bright light source that reflects off the printed waveform disc into the light sensor. When a dark portion of the disc rotates underneath the light sensor, less light is reflected, and thus the voltage is lower on the output.
Light sensor atop record player needle
The light-sensor cartridge is made from black opaque plastic to prevent non-reflected ambient light from reaching the light sensor. The face of the light-sensor cartridge has a hole for the LED, but only a slit for the light sensor. The slit narrows view of the disc, so that only the brightness of a small portion of the circular segment will be read. Without the slit, the sharp transition between black and white tended to be seen as an aggregated blurry gray.
Light sensor cartridge
At some point I’ll put more effort into writing up a proper light sensor circuit. For the moment, here is a quick explanation.
Light sensor circuit on solderless breadboard
A 9-volt battery supplies power to IC1, which is a 5V regulator (such as an MCP1702). Power is stored in C1 (1 µF at 9V) and C2 (1 µF at 5V) to keep it smooth.
LED1 is connected to +5VDC and ground. There is a resistor (not shown) soldered to the LED to keep it at 20 mA or less.
The light sensor is a 3 mm Everlight ALS-PT204-6C/L177. It was chosen because it responds to standard visible light, rather than infrared. I want it to see what I see.
The light sensor connects to +5VDC and to the middle pin of trimpot R3 (100 kΩ). My trimpot was dialed to about 20 kΩ, but you’ll need to adjust it based on the light conditions and distance to the target. The goal is to create as large of a signal as possible, with a compromise between flattening the top of the wave and the bottom of the wave.
I wrote a quick program to generate waveform patterns in a disc shape. The main loop goes around the circumference of the circle calling a function that converts the given degree into a monochrome brightness from 0-255. For example, a half-white half-black disc would return 0 (black) for 0-179 degrees and 255 (white) for 180-359 degrees. The main loop then draws a line from the center of the circle to the perimeter using the given brightness.
Screenshot of waveform disc generating application
To generate the variety of discs, only the function needs to be changed. Here are the six disc patterns created so far. Can you guess the waveform each disc translates into?
Wave generator patterns
① A square wave (played at 45 RPM)
② A square wave, also played at 45 RPM, but with more segments to increase the output frequency.
Square wave higher frequency
③ A noisy wave. Although the disc appears to be a really high-frequency square wave, it actually has random brightnesses, not just 0 (black) and 255 (white). The waveform voltage does not peak or drop as far as the other discs because the light sensor sees multiple lines at the same time, resulting in a gray blend.
④ Now we’re getting fancy, with a sawtooth waveform. It isn’t perfect because the paper disc is creased up slightly around the mid-gray region.
Approximate sawtooth wave
⑤ The triangle wave looks more like an ocean wave. Either the sensor or the printer does not have a linear response. (More likely, this is the effect of voltage divider.)
Approximate triangle wave
⑥ A simulated sin wave. Not great, but not bad.
Approximate sin wave
Let’s see this contraption in action!
This was a fun experiment, even if slightly impractical. I’m considering trying some colored discs, or even ’recording' my voice.