Project tutorial
Optical Illusion Box

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.

  • 3,736 views
  • 0 comments
  • 23 respects

Components and supplies

Apps and online services

About this project

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/

Stepper Motor: https://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors/overview

Motor Driver: http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

Code

optical_illusion_box.inoC/C++
/*

    02_Optical_Illusion_Box
    http://pattvira.com/optical_illusion_box

*/

#include <AccelStepper.h>              // AccelStepper Library can be downloaded here: http://www.airspayce.com/mikem/arduino/AccelStepper/index.html
                                       // To import a library: Go to Sketch > Import Library > Add Library > [your downloaded file]

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;
int steadySpeed = 400;

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

G4oQTBDJTMs9jSuU0Cnk.png
G4oqtbdjtms9jsuu0cnk

Comments

Similar projects you might like

Giftduino - The Perfect Arduino Gift Box

Project tutorial by circuito.io team

  • 13,085 views
  • 3 comments
  • 30 respects

Simple Arduino Optical Chopper

Project tutorial by Brendan Sweeny

  • 1,986 views
  • 0 comments
  • 4 respects

Arduino Arcade LEGO Games Box

Project tutorial by LenkaDesign

  • 4,978 views
  • 6 comments
  • 28 respects

Mobile Vote Box

Project tutorial by benstr 🚀

  • 2,158 views
  • 8 comments
  • 9 respects

Arduino Mystery Box - Beginners

Project tutorial by Dragos

  • 1,089 views
  • 1 comment
  • 5 respects
Add projectSign up / Login