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.
Components and supplies
7 Segment LED Display, InfoVue
Pushbutton Switch, Momentary
Stepper Motor and Driver for 28BYJ-48
Arduino Nano R3
Project description
Code
sketch.ino
c_cpp
Uses two debounced pushbuttons to change the state of the wheel.
1/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 UNIVERSIDADE FEDERAL DE PERNAMBUCO - PHYSICS DEPARTMENT - NANO-OPTICS LABORATORY 3 MOTORIZED ROTATION WHEEL 4 Allison Pessoa 5 6 Recife, Pernambuco - Brazil 7 December 2021 8 allisonpessoa@hotmail.com 9 10This 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. 11The 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. 12Details on the wiring can be found on the circuit project. 13 14 Allison Pessoa, 2021. Some rights reserved. 15 16////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 17 18#include <Stepper.h> 19 20const int stepsPerRevolution = 60; 21Stepper myStepper(stepsPerRevolution, 2,4,3,5); 22 23const byte a = 10; 24const byte b = 9; 25const byte c = 6; 26const byte d = 7; 27const byte e = 8; 28const byte f = 11; 29const byte g = 12; 30 31volatile int N = 0; 32 33const byte pushbt_plus = A0; 34const byte pushbt_minus = A1; 35 36unsigned long lastDebounceTime = 0; 37unsigned long debounceDelay = 50; 38 39void (*functions[6])() = {&displayZero, &displayOne, &displayTwo, &displayThree, &displayFour, &displayFive}; 40 41void setup() 42{ 43 pinMode(a, OUTPUT); 44 pinMode(b, OUTPUT); 45 pinMode(c, OUTPUT); 46 pinMode(d, OUTPUT); 47 pinMode(e, OUTPUT); 48 pinMode(f, OUTPUT); 49 pinMode(g, OUTPUT); 50 displayZero(); 51 52 pinMode(pushbt_plus, INPUT); 53 pinMode(pushbt_minus, INPUT); 54 55 pinMode(2, OUTPUT); 56 pinMode(3, OUTPUT); 57 pinMode(4, OUTPUT); 58 pinMode(5, OUTPUT); 59 60 myStepper.setSpeed(700); 61 62} 63 64void increase(){ 65 N += 1; 66 if (N == 6) { 67 N = 0; 68 } 69 70 stepperMoveFoward(); 71 stepperStop(); 72 73 (*functions[N])(); 74} 75 76void decrease(){ 77 N -= 1; 78 if (N == -1){ 79 N = 5; 80 } 81 82 stepperMoveBackward(); 83 stepperStop(); 84 85 (*functions[N])(); 86} 87 88void stepperMoveFoward(){ 89 myStepper.step(stepsPerRevolution*5.7); 90} 91 92void stepperMoveBackward(){ 93 myStepper.step(-stepsPerRevolution*5.7); 94} 95 96void displayZero(){ 97 digitalWrite(a, 0); 98 digitalWrite(b, 0); 99 digitalWrite(c, 0); 100 digitalWrite(d, 0); 101 digitalWrite(e, 0); 102 digitalWrite(f, 0); 103 digitalWrite(g, 1); 104} 105 106void displayOne(){ 107 digitalWrite(a, 1); 108 digitalWrite(b, 0); 109 digitalWrite(c, 0); 110 digitalWrite(d, 1); 111 digitalWrite(e, 1); 112 digitalWrite(f, 1); 113 digitalWrite(g, 1); 114} 115 116void displayTwo(){ 117 digitalWrite(a, 0); 118 digitalWrite(b, 0); 119 digitalWrite(c, 1); 120 digitalWrite(d, 0); 121 digitalWrite(e, 0); 122 digitalWrite(f, 1); 123 digitalWrite(g, 0); 124} 125 126void displayThree(){ 127 digitalWrite(a, 0); 128 digitalWrite(b, 0); 129 digitalWrite(c, 0); 130 digitalWrite(d, 0); 131 digitalWrite(e, 1); 132 digitalWrite(f, 1); 133 digitalWrite(g, 0); 134} 135 136void displayFour(){ 137 digitalWrite(a, 1); 138 digitalWrite(b, 0); 139 digitalWrite(c, 0); 140 digitalWrite(d, 1); 141 digitalWrite(e, 1); 142 digitalWrite(f, 0); 143 digitalWrite(g, 0); 144} 145 146void displayFive(){ 147 digitalWrite(a, 0); 148 digitalWrite(b, 1); 149 digitalWrite(c, 0); 150 digitalWrite(d, 0); 151 digitalWrite(e, 1); 152 digitalWrite(f, 0); 153 digitalWrite(g, 0); 154} 155 156void stepperStop(){ 157 digitalWrite(2, 0); 158 digitalWrite(3, 0); 159 digitalWrite(4, 0); 160 digitalWrite(5, 0); 161} 162 163bool readButton(byte buttonPin){ 164 bool reading = digitalRead(buttonPin); 165 bool pressed = 0; 166 167 if (reading == HIGH) { 168 if ((millis() - lastDebounceTime) > debounceDelay) { 169 pressed = 1; 170 } 171 lastDebounceTime = millis(); 172 } 173 return pressed; 174} 175 176void loop() 177{ 178 if (readButton(pushbt_plus) == 1){ 179 increase(); 180 } 181 182 if (readButton(pushbt_minus) == 1){ 183 decrease(); 184 } 185} 186
sketch.ino
c_cpp
Uses two debounced pushbuttons to change the state of the wheel.
1/*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2 3 UNIVERSIDADE FEDERAL DE PERNAMBUCO - PHYSICS DEPARTMENT - NANO-OPTICS 4 LABORATORY 5 MOTORIZED ROTATION WHEEL 6 7 Allison Pessoa 8 9 Recife, 10 Pernambuco - Brazil 11 December 12 2021 13 allisonpessoa@hotmail.com 14 15 16This script is used for controlling 17 a stepper motor which is attached to a 3D-printed wheel. The whell has 6 slots where 18 optical filters can be placed. 19The motor turns +- 60 for step, passing from one 20 slot to the adjacent. At the same time, a 7-digid segment shows the current filter 21 on. 22Details on the wiring can be found on the circuit project. 23 24 Allison 25 Pessoa, 2021. Some rights reserved. 26 27////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 28 29#include 30 <Stepper.h> 31 32const int stepsPerRevolution = 60; 33Stepper myStepper(stepsPerRevolution, 34 2,4,3,5); 35 36const byte a = 10; 37const byte b = 9; 38const byte c = 6; 39const 40 byte d = 7; 41const byte e = 8; 42const byte f = 11; 43const byte g = 12; 44 45volatile 46 int N = 0; 47 48const byte pushbt_plus = A0; 49const byte pushbt_minus = A1; 50 51unsigned 52 long lastDebounceTime = 0; 53unsigned long debounceDelay = 50; 54 55void (*functions[6])() 56 = {&displayZero, &displayOne, &displayTwo, &displayThree, &displayFour, &displayFive}; 57 58void 59 setup() 60{ 61 pinMode(a, OUTPUT); 62 pinMode(b, OUTPUT); 63 pinMode(c, OUTPUT); 64 65 pinMode(d, OUTPUT); 66 pinMode(e, OUTPUT); 67 pinMode(f, OUTPUT); 68 pinMode(g, 69 OUTPUT); 70 displayZero(); 71 72 pinMode(pushbt_plus, INPUT); 73 pinMode(pushbt_minus, 74 INPUT); 75 76 pinMode(2, OUTPUT); 77 pinMode(3, OUTPUT); 78 pinMode(4, OUTPUT); 79 80 pinMode(5, OUTPUT); 81 82 myStepper.setSpeed(700); 83 84} 85 86void 87 increase(){ 88 N += 1; 89 if (N == 6) { 90 N = 0; 91 } 92 93 stepperMoveFoward(); 94 95 stepperStop(); 96 97 (*functions[N])(); 98} 99 100void decrease(){ 101 102 N -= 1; 103 if (N == -1){ 104 N = 5; 105 } 106 107 stepperMoveBackward(); 108 109 stepperStop(); 110 111 (*functions[N])(); 112} 113 114void stepperMoveFoward(){ 115 116 myStepper.step(stepsPerRevolution*5.7); 117} 118 119void stepperMoveBackward(){ 120 121 myStepper.step(-stepsPerRevolution*5.7); 122} 123 124void displayZero(){ 125 digitalWrite(a, 126 0); 127 digitalWrite(b, 0); 128 digitalWrite(c, 0); 129 digitalWrite(d, 130 0); 131 digitalWrite(e, 0); 132 digitalWrite(f, 0); 133 digitalWrite(g, 134 1); 135} 136 137void displayOne(){ 138 digitalWrite(a, 1); 139 digitalWrite(b, 140 0); 141 digitalWrite(c, 0); 142 digitalWrite(d, 1); 143 digitalWrite(e, 144 1); 145 digitalWrite(f, 1); 146 digitalWrite(g, 1); 147} 148 149void displayTwo(){ 150 151 digitalWrite(a, 0); 152 digitalWrite(b, 0); 153 digitalWrite(c, 1); 154 155 digitalWrite(d, 0); 156 digitalWrite(e, 0); 157 digitalWrite(f, 1); 158 159 digitalWrite(g, 0); 160} 161 162void displayThree(){ 163 digitalWrite(a, 164 0); 165 digitalWrite(b, 0); 166 digitalWrite(c, 0); 167 digitalWrite(d, 168 0); 169 digitalWrite(e, 1); 170 digitalWrite(f, 1); 171 digitalWrite(g, 172 0); 173} 174 175void displayFour(){ 176 digitalWrite(a, 1); 177 digitalWrite(b, 178 0); 179 digitalWrite(c, 0); 180 digitalWrite(d, 1); 181 digitalWrite(e, 182 1); 183 digitalWrite(f, 0); 184 digitalWrite(g, 0); 185} 186 187void displayFive(){ 188 189 digitalWrite(a, 0); 190 digitalWrite(b, 1); 191 digitalWrite(c, 0); 192 193 digitalWrite(d, 0); 194 digitalWrite(e, 1); 195 digitalWrite(f, 0); 196 197 digitalWrite(g, 0); 198} 199 200void stepperStop(){ 201 digitalWrite(2, 202 0); 203 digitalWrite(3, 0); 204 digitalWrite(4, 0); 205 digitalWrite(5, 206 0); 207} 208 209bool readButton(byte buttonPin){ 210 bool reading = digitalRead(buttonPin); 211 212 bool pressed = 0; 213 214 if (reading == HIGH) { 215 if ((millis() - 216 lastDebounceTime) > debounceDelay) { 217 pressed = 1; 218 } 219 lastDebounceTime 220 = millis(); 221 } 222 return pressed; 223} 224 225void loop() 226{ 227 if (readButton(pushbt_plus) 228 == 1){ 229 increase(); 230 } 231 232 if (readButton(pushbt_minus) == 1){ 233 234 decrease(); 235 } 236} 237
Downloadable files
Circuit Wiring
Circuit Wiring
Circuit Wiring
Circuit Wiring
Documentation
Thingiverse
More details about the 3D printing and the files can be found here (https://www.thingiverse.com/thing:5257313).
https://www.thingiverse.com/thing:5257313
3D-printable - Wheel
3D-printable - Wheel
Thingiverse
More details about the 3D printing and the files can be found here (https://www.thingiverse.com/thing:5257313).
https://www.thingiverse.com/thing:5257313
3D-printable - Wheel
3D-printable - Wheel
3D-printable - Support to holder
3D-printable - Support to holder
Comments
Only logged in users can leave comments