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


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.


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.


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


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

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. Two main themes have emerged in recent years, sometimes combined:

  • electronics - 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
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.