Components and supplies
Toggle Switch, SPDT
Resistor 4.75k ohm
1N4007 – High Voltage, High Current Rated Diode
SG90 Micro-servo motor
Arduino Nano R3
Plastic Enclosure, Project Box
Tools and machines
Drill / Driver, Cordless
Apps and platforms
Arduino IDE
Project description
Code
Useless Box Arduino Nano
arduino
Works with UNO too, no changes. Just select the appropriate board from the Arduino editor at upload. Is the old code you can find easily, but with some minor improvements that worked for me. Thanks a lot to the one who wrote it, this guy really knows FUN.
1#include <Servo.h> 2 3Servo handServo; 4Servo boxServo; 5 6int switchStatus=0, action=1, vot, randNumber=0; 7const int ledPin = 13; 8const int frontSwitchPin = 2; 9const int handServoPin = 5; 10const int boxServoPin = 6; 11 12 13void setup() 14{ 15 Serial.begin(9600); 16 17 pinMode(ledPin, OUTPUT); 18 19 handServo.attach(handServoPin); 20 boxServo.attach(boxServoPin); 21 handServo.write(180); 22 boxServo.write(70); 23 24 //randomSeed(analogRead(0)); 25} 26 27 28void loop() 29{ 30 switchStatus = digitalRead(frontSwitchPin); 31 //action = random(1,16); 32 33 if (switchStatus == LOW){ 34 35 if (action == 1) 36 { 37 Serial.println("Action 1"); 38 for (int i = 70; i <= 110; i++) 39 { 40 boxServo.write(i); 41 delay(20); 42 } 43 for (int i = 180; i >= 35; i--) 44 { 45 handServo.write(i); 46 delay(20); 47 } 48 delay(1000); 49 handServo.write(26); 50 delay(200); 51 for (int i = 26; i <=180; i++) 52 { 53 handServo.write(i); 54 delay(20); 55 } 56 for (int i = 110; i >= 70; i--) 57 { 58 boxServo.write(i); 59 delay(20); 60 } 61 action++; 62 } 63 64 65 else if (action == 2) 66 { 67 Serial.println("Action 2"); 68 for (int i = 70; i <= 110; i++){ 69 boxServo.write(i); 70 delay(6); 71 } 72 delay(550); 73 handServo.write(26); 74 delay(1000); 75 handServo.write(180); 76 delay(550); 77 boxServo.write(70); 78 delay(1500); 79 for (int i = 70; i <= 110; i++){ 80 boxServo.write(i); 81 delay(6); 82 } 83 delay(3000); 84 boxServo.write(70); 85 action++; 86 } 87 88 else if (action == 3) 89 { 90 Serial.println("Action 3"); 91 for (int i = 70; i <= 110; i++){ 92 boxServo.write(i); 93 delay(6); 94 } 95 delay(1000); 96 boxServo.write(70); 97 delay(2000); 98 for (int i = 70; i <= 110; i++){ 99 boxServo.write(i); 100 delay(6); 101 } 102 handServo.write(26); 103 delay(650); 104 handServo.write(180); 105 delay(500); 106 boxServo.write(70); 107 action++; 108 } 109 110 else if (action == 4) 111 { 112 Serial.println("Action 4"); 113 for (int i = 70; i <= 110; i++) 114 { 115 boxServo.write(i); 116 delay(20); 117 } 118 for (int i = 180; i >= 35; i--) 119 { 120 handServo.write(i); 121 delay(20); 122 } 123 delay(2000); 124 handServo.write(26); 125 delay(200); 126 handServo.write(180); 127 delay(400); 128 boxServo.write(70); 129 action++; 130 } 131 132 else if (action == 5) 133 { 134 Serial.println("Action 5"); 135 for (int i = 70; i <= 110; i++){ 136 boxServo.write(i); 137 delay(6); 138 } 139 delay(2000); 140 handServo.write(65); 141 delay(550); 142 handServo.write(40); 143 delay(200); 144 handServo.write(65); 145 delay(200); 146 handServo.write(40); 147 delay(200); 148 handServo.write(65); 149 delay(200); 150 handServo.write(40); 151 delay(200); 152 handServo.write(65); 153 delay(200); 154 handServo.write(40); 155 delay(200); 156 handServo.write(65); 157 delay(200); 158 handServo.write(40); 159 delay(200); 160 handServo.write(65); 161 delay(2000); 162 handServo.write(26); 163 delay(400); 164 handServo.write(180); 165 delay(400); 166 boxServo.write(70); 167 action++; 168 } 169 170 else if (action == 6) 171 { 172 Serial.println("Action 6"); 173 for (int i = 70; i <110; i++) 174 { 175 boxServo.write(i); 176 delay(20); 177 } 178 delay(1000); 179 for (int i = 0; i < 12; i++) 180 { 181 for (int j = 70; j <= 110; j++){ 182 boxServo.write(j); 183 delay(6); 184 } 185 delay(200); 186 } 187 for (int i = 180; i >= 35; i--) 188 { 189 handServo.write(i); 190 delay(30); 191 } 192 handServo.write(26); 193 delay(400); 194 handServo.write(180); 195 delay(400); 196 boxServo.write(70); 197 delay(1500); 198 for (int i = 70; i <= 110; i++){ 199 boxServo.write(i); 200 delay(6); 201 } 202 delay(3000); 203 boxServo.write(70); 204 action++; 205 } 206 207 else if (action == 7) 208 { 209 Serial.println("Action 7"); 210 for (int i = 70; i <= 110; i++){ 211 boxServo.write(i); 212 delay(6); 213 } 214 delay(400); 215 handServo.write(26); 216 delay(1000); 217 for (int i = 0; i < 6; i++) 218 { 219 for (int j = 70; j <= 110; j++){ 220 boxServo.write(j); 221 delay(6); 222 } 223 delay(200); 224 } 225 delay(500); 226 handServo.write(180); 227 delay(400); 228 boxServo.write(70); 229 action++; 230 } 231 232 else if (action == 8) 233 { 234 Serial.println("Action 8"); 235 for (int i = 70; i <= 110; i++){ 236 boxServo.write(i); 237 delay(6); 238 } 239 handServo.write(26); 240 delay(2000); 241 for (int i = 0; i < 7; i++) 242 { 243 handServo.write(75); 244 delay(100); 245 handServo.write(40); 246 delay(100); 247 } 248 delay(500); 249 handServo.write(180); 250 delay(1000); 251 boxServo.write(70); 252 action++; 253 } 254 255 else if (action == 9) 256 { 257 Serial.println("Action 9"); 258 for (int i = 70; i <= 105; i++){ 259 boxServo.write(i); 260 delay(6); 261 } 262 delay(2000); 263 boxServo.write(110); 264 for (int i = 180; i >=35; i--) 265 { 266 handServo.write(i); 267 delay(40); 268 } 269 delay(500); 270 handServo.write(26); 271 delay(200); 272 for (int i = 26; i <=180; i++) 273 { 274 handServo.write(i); 275 delay(40); 276 } 277 boxServo.write(70); 278 delay(2000); 279 boxServo.write(100); 280 delay(3000); 281 boxServo.write(70); 282 action++; 283 } 284 285 286 else if (action == 10) 287 { 288 Serial.println("Action 10"); 289 for (int i = 70; i <= 105; i++) 290 { 291 boxServo.write(i); 292 delay(100); 293 } 294 delay(1000); 295 for (int i = 0; i < 10; i++) 296 { 297 for (int j = 70; j <= 100; j++){ 298 boxServo.write(j); 299 delay(6); 300 } 301 delay(100); 302 } 303 boxServo.write(110); 304 delay(100); 305 handServo.write(26); 306 delay(650); 307 handServo.write(180); 308 delay(400); 309 boxServo.write(70); 310 action++; 311 } 312 313 else if (action == 11) 314 { 315 Serial.println("Action 11"); 316 for (int i = 70; i <= 110; i++){ 317 boxServo.write(i); 318 delay(6); 319 } 320 handServo.write(26); 321 delay(2000); 322 for (int i = 0; i < 3; i++) 323 { 324 handServo.write(65); 325 delay(200); 326 handServo.write(40); 327 delay(200); 328 } 329 delay(1500); 330 handServo.write(180); 331 delay(400); 332 boxServo.write(70); 333 delay(1500); 334 for (int i = 70; i <= 110; i++){ 335 boxServo.write(i); 336 delay(6); 337 } 338 handServo.write(26); 339 delay(3000); 340 handServo.write(180); 341 delay(400); 342 boxServo.write(70); 343 action++; 344 } 345 346 else if (action == 12) 347 { 348 Serial.println("Action 12"); 349 for (int i = 70; i <= 110; i++) 350 { 351 boxServo.write(i); 352 delay(50); 353 } 354 delay(1000); 355 for (int i = 180; i >= 26; i--) 356 { 357 handServo.write(i); 358 delay(50); 359 } 360 delay(2000); 361 handServo.write(26); 362 delay(200); 363 handServo.write(180); 364 delay(400); 365 boxServo.write(70); 366 action++; 367 } 368 369 else if (action == 13) 370 { 371 Serial.println("Action 13"); 372 for (int i = 70; i <= 110; i++){ 373 boxServo.write(i); 374 delay(6); 375 } 376 delay(2000); 377 for (int i = 180; i >= 60; i--) 378 { 379 handServo.write(i); 380 delay(40); 381 } 382 for (int i = 0; i < 3; i++) 383 { 384 handServo.write(60); 385 delay(200); 386 handServo.write(40); 387 delay(800); 388 } 389 handServo.write(26); 390 delay(2000); 391 handServo.write(180); 392 delay(500); 393 boxServo.write(70); 394 action++; 395 } 396 397 else if (action == 14) 398 { 399 Serial.println("Action 14"); 400 for (int i = 70; i <= 105; i++){ 401 boxServo.write(i); 402 delay(6); 403 } 404 delay(4000); 405 boxServo.write(110); 406 handServo.write(26); 407 delay(650); 408 handServo.write(180); 409 delay(500); 410 boxServo.write(100); 411 delay(4000); 412 boxServo.write(70); 413 action++; 414 } 415 416 else if (action == 15) 417 { 418 Serial.println("Action 15"); 419 for (int i = 70; i <= 105; i++){ 420 boxServo.write(i); 421 delay(6); 422 } 423 delay(1000); 424 for (int i = 0; i < 3; i++) 425 { 426 for (int j = 70; j <= 105; j++){ 427 boxServo.write(j); 428 delay(50); 429 } 430 for (int j = 105; j >= 70; j--) 431 { 432 boxServo.write(j); 433 delay(50); 434 } 435 } 436 for (int j = 70; j <= 110; j++){ 437 boxServo.write(j); 438 delay(50); 439 } 440 for (int i = 180; i >= 35; i--) 441 { 442 handServo.write(i); 443 delay(40); 444 } 445 delay(1000); 446 handServo.write(26); 447 delay(400); 448 handServo.write(180); 449 delay(400); 450 boxServo.write(70); 451 action = 1; 452 } 453 454 } 455 456} 457
Useless Box Arduino Nano
arduino
Works with UNO too, no changes. Just select the appropriate board from the Arduino editor at upload. Is the old code you can find easily, but with some minor improvements that worked for me. Thanks a lot to the one who wrote it, this guy really knows FUN.
1#include <Servo.h> 2 3Servo handServo; 4Servo boxServo; 5 6int switchStatus=0, action=1, vot, randNumber=0; 7const int ledPin = 13; 8const int frontSwitchPin = 2; 9const int handServoPin = 5; 10const int boxServoPin = 6; 11 12 13void setup() 14{ 15 Serial.begin(9600); 16 17 pinMode(ledPin, OUTPUT); 18 19 handServo.attach(handServoPin); 20 boxServo.attach(boxServoPin); 21 handServo.write(180); 22 boxServo.write(70); 23 24 //randomSeed(analogRead(0)); 25} 26 27 28void loop() 29{ 30 switchStatus = digitalRead(frontSwitchPin); 31 //action = random(1,16); 32 33 if (switchStatus == LOW){ 34 35 if (action == 1) 36 { 37 Serial.println("Action 1"); 38 for (int i = 70; i <= 110; i++) 39 { 40 boxServo.write(i); 41 delay(20); 42 } 43 for (int i = 180; i >= 35; i--) 44 { 45 handServo.write(i); 46 delay(20); 47 } 48 delay(1000); 49 handServo.write(26); 50 delay(200); 51 for (int i = 26; i <=180; i++) 52 { 53 handServo.write(i); 54 delay(20); 55 } 56 for (int i = 110; i >= 70; i--) 57 { 58 boxServo.write(i); 59 delay(20); 60 } 61 action++; 62 } 63 64 65 else if (action == 2) 66 { 67 Serial.println("Action 2"); 68 for (int i = 70; i <= 110; i++){ 69 boxServo.write(i); 70 delay(6); 71 } 72 delay(550); 73 handServo.write(26); 74 delay(1000); 75 handServo.write(180); 76 delay(550); 77 boxServo.write(70); 78 delay(1500); 79 for (int i = 70; i <= 110; i++){ 80 boxServo.write(i); 81 delay(6); 82 } 83 delay(3000); 84 boxServo.write(70); 85 action++; 86 } 87 88 else if (action == 3) 89 { 90 Serial.println("Action 3"); 91 for (int i = 70; i <= 110; i++){ 92 boxServo.write(i); 93 delay(6); 94 } 95 delay(1000); 96 boxServo.write(70); 97 delay(2000); 98 for (int i = 70; i <= 110; i++){ 99 boxServo.write(i); 100 delay(6); 101 } 102 handServo.write(26); 103 delay(650); 104 handServo.write(180); 105 delay(500); 106 boxServo.write(70); 107 action++; 108 } 109 110 else if (action == 4) 111 { 112 Serial.println("Action 4"); 113 for (int i = 70; i <= 110; i++) 114 { 115 boxServo.write(i); 116 delay(20); 117 } 118 for (int i = 180; i >= 35; i--) 119 { 120 handServo.write(i); 121 delay(20); 122 } 123 delay(2000); 124 handServo.write(26); 125 delay(200); 126 handServo.write(180); 127 delay(400); 128 boxServo.write(70); 129 action++; 130 } 131 132 else if (action == 5) 133 { 134 Serial.println("Action 5"); 135 for (int i = 70; i <= 110; i++){ 136 boxServo.write(i); 137 delay(6); 138 } 139 delay(2000); 140 handServo.write(65); 141 delay(550); 142 handServo.write(40); 143 delay(200); 144 handServo.write(65); 145 delay(200); 146 handServo.write(40); 147 delay(200); 148 handServo.write(65); 149 delay(200); 150 handServo.write(40); 151 delay(200); 152 handServo.write(65); 153 delay(200); 154 handServo.write(40); 155 delay(200); 156 handServo.write(65); 157 delay(200); 158 handServo.write(40); 159 delay(200); 160 handServo.write(65); 161 delay(2000); 162 handServo.write(26); 163 delay(400); 164 handServo.write(180); 165 delay(400); 166 boxServo.write(70); 167 action++; 168 } 169 170 else if (action == 6) 171 { 172 Serial.println("Action 6"); 173 for (int i = 70; i <110; i++) 174 { 175 boxServo.write(i); 176 delay(20); 177 } 178 delay(1000); 179 for (int i = 0; i < 12; i++) 180 { 181 for (int j = 70; j <= 110; j++){ 182 boxServo.write(j); 183 delay(6); 184 } 185 delay(200); 186 } 187 for (int i = 180; i >= 35; i--) 188 { 189 handServo.write(i); 190 delay(30); 191 } 192 handServo.write(26); 193 delay(400); 194 handServo.write(180); 195 delay(400); 196 boxServo.write(70); 197 delay(1500); 198 for (int i = 70; i <= 110; i++){ 199 boxServo.write(i); 200 delay(6); 201 } 202 delay(3000); 203 boxServo.write(70); 204 action++; 205 } 206 207 else if (action == 7) 208 { 209 Serial.println("Action 7"); 210 for (int i = 70; i <= 110; i++){ 211 boxServo.write(i); 212 delay(6); 213 } 214 delay(400); 215 handServo.write(26); 216 delay(1000); 217 for (int i = 0; i < 6; i++) 218 { 219 for (int j = 70; j <= 110; j++){ 220 boxServo.write(j); 221 delay(6); 222 } 223 delay(200); 224 } 225 delay(500); 226 handServo.write(180); 227 delay(400); 228 boxServo.write(70); 229 action++; 230 } 231 232 else if (action == 8) 233 { 234 Serial.println("Action 8"); 235 for (int i = 70; i <= 110; i++){ 236 boxServo.write(i); 237 delay(6); 238 } 239 handServo.write(26); 240 delay(2000); 241 for (int i = 0; i < 7; i++) 242 { 243 handServo.write(75); 244 delay(100); 245 handServo.write(40); 246 delay(100); 247 } 248 delay(500); 249 handServo.write(180); 250 delay(1000); 251 boxServo.write(70); 252 action++; 253 } 254 255 else if (action == 9) 256 { 257 Serial.println("Action 9"); 258 for (int i = 70; i <= 105; i++){ 259 boxServo.write(i); 260 delay(6); 261 } 262 delay(2000); 263 boxServo.write(110); 264 for (int i = 180; i >=35; i--) 265 { 266 handServo.write(i); 267 delay(40); 268 } 269 delay(500); 270 handServo.write(26); 271 delay(200); 272 for (int i = 26; i <=180; i++) 273 { 274 handServo.write(i); 275 delay(40); 276 } 277 boxServo.write(70); 278 delay(2000); 279 boxServo.write(100); 280 delay(3000); 281 boxServo.write(70); 282 action++; 283 } 284 285 286 else if (action == 10) 287 { 288 Serial.println("Action 10"); 289 for (int i = 70; i <= 105; i++) 290 { 291 boxServo.write(i); 292 delay(100); 293 } 294 delay(1000); 295 for (int i = 0; i < 10; i++) 296 { 297 for (int j = 70; j <= 100; j++){ 298 boxServo.write(j); 299 delay(6); 300 } 301 delay(100); 302 } 303 boxServo.write(110); 304 delay(100); 305 handServo.write(26); 306 delay(650); 307 handServo.write(180); 308 delay(400); 309 boxServo.write(70); 310 action++; 311 } 312 313 else if (action == 11) 314 { 315 Serial.println("Action 11"); 316 for (int i = 70; i <= 110; i++){ 317 boxServo.write(i); 318 delay(6); 319 } 320 handServo.write(26); 321 delay(2000); 322 for (int i = 0; i < 3; i++) 323 { 324 handServo.write(65); 325 delay(200); 326 handServo.write(40); 327 delay(200); 328 } 329 delay(1500); 330 handServo.write(180); 331 delay(400); 332 boxServo.write(70); 333 delay(1500); 334 for (int i = 70; i <= 110; i++){ 335 boxServo.write(i); 336 delay(6); 337 } 338 handServo.write(26); 339 delay(3000); 340 handServo.write(180); 341 delay(400); 342 boxServo.write(70); 343 action++; 344 } 345 346 else if (action == 12) 347 { 348 Serial.println("Action 12"); 349 for (int i = 70; i <= 110; i++) 350 { 351 boxServo.write(i); 352 delay(50); 353 } 354 delay(1000); 355 for (int i = 180; i >= 26; i--) 356 { 357 handServo.write(i); 358 delay(50); 359 } 360 delay(2000); 361 handServo.write(26); 362 delay(200); 363 handServo.write(180); 364 delay(400); 365 boxServo.write(70); 366 action++; 367 } 368 369 else if (action == 13) 370 { 371 Serial.println("Action 13"); 372 for (int i = 70; i <= 110; i++){ 373 boxServo.write(i); 374 delay(6); 375 } 376 delay(2000); 377 for (int i = 180; i >= 60; i--) 378 { 379 handServo.write(i); 380 delay(40); 381 } 382 for (int i = 0; i < 3; i++) 383 { 384 handServo.write(60); 385 delay(200); 386 handServo.write(40); 387 delay(800); 388 } 389 handServo.write(26); 390 delay(2000); 391 handServo.write(180); 392 delay(500); 393 boxServo.write(70); 394 action++; 395 } 396 397 else if (action == 14) 398 { 399 Serial.println("Action 14"); 400 for (int i = 70; i <= 105; i++){ 401 boxServo.write(i); 402 delay(6); 403 } 404 delay(4000); 405 boxServo.write(110); 406 handServo.write(26); 407 delay(650); 408 handServo.write(180); 409 delay(500); 410 boxServo.write(100); 411 delay(4000); 412 boxServo.write(70); 413 action++; 414 } 415 416 else if (action == 15) 417 { 418 Serial.println("Action 15"); 419 for (int i = 70; i <= 105; i++){ 420 boxServo.write(i); 421 delay(6); 422 } 423 delay(1000); 424 for (int i = 0; i < 3; i++) 425 { 426 for (int j = 70; j <= 105; j++){ 427 boxServo.write(j); 428 delay(50); 429 } 430 for (int j = 105; j >= 70; j--) 431 { 432 boxServo.write(j); 433 delay(50); 434 } 435 } 436 for (int j = 70; j <= 110; j++){ 437 boxServo.write(j); 438 delay(50); 439 } 440 for (int i = 180; i >= 35; i--) 441 { 442 handServo.write(i); 443 delay(40); 444 } 445 delay(1000); 446 handServo.write(26); 447 delay(400); 448 handServo.write(180); 449 delay(400); 450 boxServo.write(70); 451 action = 1; 452 } 453 454 } 455 456} 457
Downloadable files
Electric diagram
The electric diagram is a bit adapted to my preferences. I opted out for USB power (phone charger or power bank) instead of batteries, thru a diode to 5V pin. This prevents the servomotors to be powered when the board is plugged in to computer USB for programming, because the current draw would be too high.
Electric diagram
Arm design
The arm which flips down the switch
Arm design
Lid lever design
The lever which opens the lid
Lid lever design
Electric diagram
The electric diagram is a bit adapted to my preferences. I opted out for USB power (phone charger or power bank) instead of batteries, thru a diode to 5V pin. This prevents the servomotors to be powered when the board is plugged in to computer USB for programming, because the current draw would be too high.
Electric diagram
Arm design
The arm which flips down the switch
Arm design
Comments
Only logged in users can leave comments