Project tutorial

# Optical Illusion Box

I tell them I built a “phyllotaxis phenakistoscope” and they give me that puzzle look. So I say I built a super cool optical illusion box.

• 5,593 views
• 24 respects

## Components and supplies

 NEMA 17 Stepper Motor
×1
 L298N Dual H-Bridge Motor Driver
×1
 Arduino UNO
×1
 LED Strip
×1
 SparkFun N Channel MOSFET
×1
 Rotary potentiometer (generic)
×1
 Slide Switch
×1
×1
 Resistor 10k ohm
×1

## Apps and online services

 Arduino IDE

### Overview

Yes, I built a phyllotaxis phenakistoscope. What is a phenakistoscope?

A phenakistoscope is an optical illusion device that creates an illusion of motion by looking at a series of images at an offset interval. The image is blurred when observed with the naked eyes, but can be seen clearly with a help of a strobe light. The image became clear when the light frequency is synced up to the rotational speed of the motor. A quick example calculation of how this works.

Say a disc is divided into 12 even slices of pies. And say the motor runs at a speed of 1 revolution per second (or 60 revolution per minute). We want to see all 12 images each revolution, so we need to flash the light 12 times. So the math comes down to strobing the light every ~83.33 milliseconds (1000ms / 12). It is as simple as that, and the magic comes alive!

What is a phyllotaxis?

This is a phyllotaxis. But definitely check out Dan Shiffman’s video to learn more. It’s awesome. You might see where I got the idea. And while you are at it, check out his other videos as well. They are equally awesome.

### Assembly

I made a 9x9 wooden box, with slits on all four sides to place the led strip. You can set up the light in any configuration really as long as it is bright enough to illuminate the image. My set up is not ideal - the light could be brighter, but it works great for now. Make sure that the 12V power supply has a higher max current than the current draw of the stepper motor and the led strip combined.

I use the potentiometer to vary the strobe light frequency, and I set the motor to run at a constant speed. However, you can totally switch that up and use the potentiometer to change the motor speed while keeping the strobe frequency constant. Or better yet, connect two potentiometers instead of one to control both.

Phenakistoscope Inspirations: https://blog.arduino.cc/2014/01/07/a-diy-electronic-remake-of-a-phenakistoscope/

## Code

##### optical_illusion_box.inoC/C++
```/*

02_Optical_Illusion_Box
http://pattvira.com/optical_illusion_box

*/

AccelStepper stepper(4, 2, 3, 4, 5);   // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

int ledPin = 11;      // LED connected to pin 11
int switchPin = 8;    // ON/OFF switch connected to pin 8
int potPin = A0;      // Potentiometer connected to pin A0

// Variables for ON/OFF switch
int switchState = 0;
int lastSwitchState = 0;
boolean light = false;

// Variables for offseting strobe light
unsigned long interval = 1000;              // Variable for an offset interval
boolean ledState = HIGH;                    // Variable for LED state
unsigned long previousMillis = 0;

float strobe = 100;                         // Variable for strobe light on
int velocity = 200;                         // Variable for stepper motor speed (number if steps per second)
// My motor rotates 1.8 degrees each turn -> 200 steps per revolution
int maximumSpeed = 512;

void setup() {

stepper.setMaxSpeed(maximumSpeed);        // Define the maximum motor speed
stepper.setSpeed(steadySpeed);	    // Initialize the motor speed
pinMode(ledPin, OUTPUT);                  // Set an LED pin as an output pin
pinMode(switchPin, INPUT);                // Set a on/off switch pin as an input pin

}

void loop() {

switchState = digitalRead(switchPin);               // Identify if the switch is on or off
strobe = map(analogRead(potPin), 0, 1023, 0, 100);  // Strobe frequency
if (switchState != lastSwitchState) {
if (switchState == HIGH) {
light = true;
} else {
light = false;
}
}
lastSwitchState = switchState;

if (light) {                                        // If switch is on,
if (strobe == 0) {
strobe = 1;
} else {
strobeLight(ledPin, 1, strobe - 1);             // Light strobes
}
stepper.setSpeed(steadySpeed);                    // Motor is set to a constant speed

} else {                                            // If switch is off,
digitalWrite(ledPin, LOW);                        // Light turns off
stepper.setSpeed(0);                              // Motor stops
}

stepper.runSpeed();                                 // Motor only runs when this command is called

}

// Function for turning on and off the LED strip without using delay
void strobeLight(int pin, int lightOn, int lightOff) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;                      // Save the last time you blinked the LED

if (ledState == LOW) {                               // If the LED is off turn it on and vice-versa
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);                      // Set the LED with the ledState of the variable

if (ledState)                                        // Set the offset interval
{
interval = lightOn;
}
else
{
interval = lightOff;
}
}
}
```

## Schematics

• 2 projects
• 11 followers

December 7, 2016

#### Members who respect this project

and 16 others

See similar projects
you might like

#### Automatically Open/Close a Box With a Linear Actuator Box

Project tutorial by Team RobotGeek Projects Team

• 7,304 views
• 10 respects

#### Simple Arduino Optical Chopper

Project tutorial by Brendan Sweeny

• 5,165 views
• 1 comment
• 7 respects

Project tutorial by circuito.io team

• 23,398 views
• 37 respects

#### Mobile Vote Box

Project tutorial by benstr 🚀

• 4,158 views
• 15 respects

#### Monster in a Box

Project tutorial by craig jameson

• 31,525 views
• 137 respects

• 2,051 views
• 1 comment
• 0 respects