allisonpessoa
Published © GPL3+

3D-printable Motorized Wheel for optical filter turning

A stepper motor controls the optical filter in the optical path and the user can remotely turn the wheel to change the filter.

IntermediateFull instructions provided272
3D-printable Motorized Wheel for optical filter turning

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
Stepper Motor and Driver for 28BYJ-48
×1
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×1

Story

Read more

Custom parts and enclosures

3D-printable - Wheel

3D-printable - Support to holder

Thingiverse

More details about the 3D printing and the files can be found here (https://www.thingiverse.com/thing:5257313).

Schematics

Circuit Wiring

Code

sketch.ino

C/C++
Uses two debounced pushbuttons to change the state of the wheel.
/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                  UNIVERSIDADE FEDERAL DE PERNAMBUCO - PHYSICS DEPARTMENT - NANO-OPTICS LABORATORY
                                              MOTORIZED ROTATION WHEEL
                                                    Allison Pessoa

                                              Recife, Pernambuco - Brazil
                                                     December 2021
                                                allisonpessoa@hotmail.com
                                                
This script is used for controlling a stepper motor which is attached to a 3D-printed wheel. The whell has 6 slots where optical filters can be placed.
The motor turns +- 60 for step, passing from one slot to the adjacent. At the same time, a 7-digid segment shows the current filter on.
Details on the wiring can be found on the circuit project.

 Allison Pessoa, 2021. Some rights reserved.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

#include <Stepper.h>
 
const int stepsPerRevolution = 60; 
Stepper myStepper(stepsPerRevolution, 2,4,3,5);
 
const byte a = 10;
const byte b = 9;
const byte c = 6;
const byte d = 7;
const byte e = 8;
const byte f = 11;
const byte g = 12;

volatile int N = 0;

const byte pushbt_plus = A0;
const byte pushbt_minus = A1;

unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;

void (*functions[6])() = {&displayZero, &displayOne, &displayTwo, &displayThree, &displayFour, &displayFive};

void setup()
{
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  displayZero();
  
  pinMode(pushbt_plus, INPUT);
  pinMode(pushbt_minus, INPUT);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  
  myStepper.setSpeed(700);
  
}

void increase(){
  N += 1;
  if (N == 6) {
    N = 0;
  }
  
  stepperMoveFoward();
  stepperStop();
  
  (*functions[N])();
}

void decrease(){
  N -= 1;
  if (N == -1){
    N = 5;
  }
  
  stepperMoveBackward();
  stepperStop();
  
  (*functions[N])();
}

void stepperMoveFoward(){
  myStepper.step(stepsPerRevolution*5.7);
}

void stepperMoveBackward(){
  myStepper.step(-stepsPerRevolution*5.7);
}

void displayZero(){
    digitalWrite(a, 0);
    digitalWrite(b, 0);
    digitalWrite(c, 0);
    digitalWrite(d, 0);
    digitalWrite(e, 0);
    digitalWrite(f, 0);
    digitalWrite(g, 1);
}

void displayOne(){
    digitalWrite(a, 1);
    digitalWrite(b, 0);
    digitalWrite(c, 0);
    digitalWrite(d, 1);
    digitalWrite(e, 1);
    digitalWrite(f, 1);
    digitalWrite(g, 1);
}

void displayTwo(){
    digitalWrite(a, 0);
    digitalWrite(b, 0);
    digitalWrite(c, 1);
    digitalWrite(d, 0);
    digitalWrite(e, 0);
    digitalWrite(f, 1);
    digitalWrite(g, 0);
}

void displayThree(){
    digitalWrite(a, 0);
    digitalWrite(b, 0);
    digitalWrite(c, 0);
    digitalWrite(d, 0);
    digitalWrite(e, 1);
    digitalWrite(f, 1);
    digitalWrite(g, 0);
}

void displayFour(){
    digitalWrite(a, 1);
    digitalWrite(b, 0);
    digitalWrite(c, 0);
    digitalWrite(d, 1);
    digitalWrite(e, 1);
    digitalWrite(f, 0);
    digitalWrite(g, 0);  
}

void displayFive(){
    digitalWrite(a, 0);
    digitalWrite(b, 1);
    digitalWrite(c, 0);
    digitalWrite(d, 0);
    digitalWrite(e, 1);
    digitalWrite(f, 0);
    digitalWrite(g, 0);  
}

void stepperStop(){
    digitalWrite(2, 0);
    digitalWrite(3, 0);
    digitalWrite(4, 0);
    digitalWrite(5, 0);
}

bool readButton(byte buttonPin){
  bool reading = digitalRead(buttonPin);
  bool pressed = 0;
  
    if (reading == HIGH) {
      if ((millis() - lastDebounceTime) > debounceDelay) {
        pressed = 1;
    }
    lastDebounceTime = millis();
  }
  return pressed;
}

void loop()
{
  if (readButton(pushbt_plus) == 1){
    increase();
  }
  
  if (readButton(pushbt_minus) == 1){
    decrease();
  }
}

Credits

allisonpessoa
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.