Fork me on GitHub

Project Notes

#053 LM324 Function Generator

Use an Arduino to monitor the behaviour of a low-frequency LM324 OpAmp waveform generator (square,triangle,sine,cosine) and plot the results with Processing.

The Build

Notes

The circuit uses the 4 OpAmps in an LM324 to drive four waveforms: square,triangle,sine,cosine.

The frequency is designed to be very low, in order to drive output effects visible to the human eye.

Stage 1: Square Wave Generator

Stage 1 uses an RC network (R4,C1) to generate a low frequency square wave. It can oscillate from about 0.24Hz to about 4Hz by adjusting R4.

f = 1/(2πRC)
f = 1/(2π * 20kΩ * 33μF)
f = 0.24Hz

The non-inverting voltage reference is pegged to Vcc/2 using the R1/R2 voltage divider. A similar reference voltage is repeated for each OpAmp unit. Note that the reference voltage is not shared to avoid cross-over problems.

Stage 2: Triangle Wave Integrator

The square wave from stage 1 is fed to the second stage configured as an integrating amplifier. This results in a triangle wave.

opamp_integrator

Stage 3: Sine Wave Integrator

The triangle wave from stage 1 is fed to the third stage to perform a second integration. This results in a sine wave.

Stage 4: Cosine Wave Integrator

To transform the output from stage 3 (sine) to cosine, we use the final OpAmp unit as an inverting amplifier with gain = 1.

opamp_integrator

Measured Behaviour

LEAP#090 PlotNValues (a simple Processing sketch) reads the data from the serial port and plots the output values over time, with some coloration effects thrown in for good measure. In other words, we’re using Arduino and Processing as a basic oscilloscope … and it kind of works, mainly because the frequency is so low.

The behaviour is demonstrated in the following trace with R4 variable resistor at about 10kΩ.

  • Stage 4 (upper trace) is the cosine output
  • Stage 3 (upper middle trace) is the sine wave output
  • Stage 2 (lower middle trace) is the triangle wave output
  • Stage 1 (lower trace) is the square wave output

processing trace

Construction

The Arduino only acts as a measurement device in this circuit. For simplicity, the circuit is powered from the Arduino 5V pin. That works fine, although it is equally possible to use a separate power supply (but ensuring there is a common ground connection).

The Breadboard

The Schematic

The Build

Credits and References

About LEAP#53 OpAmpOscillators
Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects, usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting (IMHO!).

The projects are usually inspired by things found wild on the net, or ideas from the sources such as:

Feel free to borrow liberally, and if you spot any issues do let me know. See the individual projects for credits where due. There are even now a few projects contributed by others - send your own over in a pull request if you would also like to add to this collection.