Build it step by step
0 of 7 doneWire the knobs
Both outer legs to 5V and GND, middles to A0 and A1.
Wire the OLED
SDA to A4, SCL to A5, 5V and GND.
Upload the sketch
A looping figure appears and slowly turns.
Set both knobs the same
An oval or a line appears.
Set 3 and 2
A pretzel-like knot appears.
Set 1 and 2
A figure of eight appears.
Try every pair
Sketch the ones you like.
How do you build a lissajous figure drawer?
Two knobs set the speeds of two sine waves, one across the screen and one up it, and the dot traces beautiful looping Lissajous figures that change as you turn them. It is the pattern an oscilloscope draws in XY mode, and a lovely way to see ratios. You need Arduino Nano, SSD1306 OLED Display, Potentiometer 10 kΩ × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.
- Level
- Beginner
- Time
- About 80 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Pot 1 outer legs | Nano 5V and GND | Sets the across speed |
| Pot 1 middle leg | Nano A0 | Chooses 1 to 6 |
| Pot 2 outer legs | Nano 5V and GND | Sets the up and down speed |
| Pot 2 middle leg | Nano A1 | Chooses 1 to 6 |
| OLED SDA and SCL | Nano A4 and A5 | I2C data and clock |
| OLED VCC and GND | Nano 5V and GND | Power for a 0.96 inch module |
Code
A Lissajous figure is what you get when one point moves left and right following one sine wave while it moves up and down following another. Here the first knob sets how many wave cycles the point makes across the screen and the second how many it makes up and down, each from 1 to 6, and the sketch draws the whole loop as 90 short straight lines. When the two numbers are the same the loop is a tilted oval or a line, and when they are different you get lovely knots, so 3:2 makes a pretzel shape and 1:2 makes a figure of eight. The numbers are shown in the corner as a ratio. A small phase value is added to the first wave on every frame, so the figure slowly turns and shows the shapes you would see if the two waves drifted slightly apart. The screen is told to talk faster with Wire.setClock(400000) so the drawing is smooth. This is exactly what an oscilloscope draws in its XY mode when you feed it two sine waves, so if you meet one at school you will know what you are looking at. Install "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. Try changing the 60 and 30 to other sizes, or add a third wave to the up and down direction for a more complex figure.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: Adafruit SSD1306 and Adafruit GFX.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const uint8_t POINTS = 90; // line segments in one figure
const float TWO_PI_F = 6.2831853;
float phase = 0;
void setup() {
Serial.begin(9600);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Wire.setClock(400000); // faster drawing
}
void loop() {
uint8_t a = map(analogRead(A0), 0, 1023, 1, 6); // sine cycles across
uint8_t b = map(analogRead(A1), 0, 1023, 1, 6); // sine cycles up and down
oled.clearDisplay();
int px = 0, py = 0;
for (uint8_t i = 0; i <= POINTS; i++) {
float t = TWO_PI_F * i / POINTS;
int x = 64 + (int)(60 * sin(a * t + phase));
int y = 32 + (int)(30 * sin(b * t));
if (i > 0) oled.drawLine(px, py, x, y, SSD1306_WHITE);
px = x;
py = y;
}
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.print(a);
oled.print(F(":"));
oled.print(b);
oled.display();
phase += 0.06; // slowly rotates the figure
if (phase > TWO_PI_F) phase -= TWO_PI_F;
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Both knobs equal | An oval or a line that turns |
| Knobs 1 and 2 | A figure of eight |
| Knobs 3 and 2 | A pretzel-like knot |
| Knobs 6 and 5 | A busy lace pattern |
| Corner text | Shows the ratio, such as 3:2 |
If it does not work
Blank screen
Check the OLED wires and try address 0x3D.
Figure jumps between shapes
Knobs jitter at a boundary, so nudge them to the middle of a step.
Slow drawing
Keep Wire.setClock(400000) and lower POINTS.
Figure is not closed
Both knobs must give whole numbers, which map() does.
Upload fails
Choose the Old Bootloader option for the Nano.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the lissajous figure drawer?
Arduino Nano, SSD1306 OLED Display, Potentiometer 10 kΩ × 2, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the lissajous figure drawer take to build?
About 80 minutes for a beginner maker, in 7 steps.
How do I know the lissajous figure drawer works?
Both knobs equal: An oval or a line that turns. Knobs 1 and 2: A figure of eight. Knobs 3 and 2: A pretzel-like knot.
Blank screen: what should I check?
Check the OLED wires and try address 0x3D.
Figure jumps between shapes: what should I check?
Knobs jitter at a boundary, so nudge them to the middle of a step.
Slow drawing: what should I check?
Keep Wire.setClock(400000) and lower POINTS.
Figure is not closed: what should I check?
Both knobs must give whole numbers, which map() does.
