Components and supplies
1
Vibration Shock Switch Module
1
Microphone Amplifier Breakout
1
Arduino UNO
3
Stepper Motor
1
Jumper wires (generic)
Tools and machines
1
Laser cutter (generic)
1
Hot glue gun (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Code
arduino
1#include <Stepper.h> 2#define STEPS_PER_MOTOR_REVOLUTION 32 3#define 4 STEPS_PER_OUTPUT_REVOLUTION 32 * 64/2 5Stepper small_stepper1(STEPS_PER_MOTOR_REVOLUTION, 6 10, 12 , 11, 13); 7Stepper small_stepper2(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 8 9); 9Stepper small_stepper3(STEPS_PER_MOTOR_REVOLUTION, 1, 4, 3, 5); 10 11int 12 sensorPin = A2; 13int pushButton = 2; 14int vib_pin = 2; 15int Steps2Take; 16int 17 cont; 18long st; 19int StepRod1; 20int StepRod2; 21int StepRod3; 22 23boolean 24 choque = false; 25 26void setup() { 27 Serial.begin(9600); 28 pinMode(sensorPin, 29 INPUT); 30 pinMode(vib_pin, INPUT); 31 pinMode(StepRod3, OUTPUT); 32 cont 33 = 0; 34 35 attachInterrupt(digitalPinToInterrupt(2), choca, FALLING); 36} 37 38void 39 loop() { 40 41 if (digitalRead(sensorPin) == HIGH) { 42 delay(10); 43 if 44 (cont == 0) 45 st = millis(); 46 cont = cont + 1; 47 while (digitalRead(sensorPin) 48 != LOW) { 49 if (millis() - st > 2000) { 50 Serial.print(cont); 51 52 Serial.println(" aplausos"); 53 54 doOrders(cont); 55 cont 56 = 0; 57 } 58 } 59 } 60 if (millis() - st > 2000 && cont != 0) { 61 62 Serial.print(cont); 63 Serial.println(" aplausos"); 64 doOrders(cont); 65 66 cont = 0; 67 } 68} 69 70 71void doOrders(int apl) { 72 73 74 if (cont 75 == 1) { 76 StepRod1 = HIGH; 77 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION 78 * 2 ; // Rotate CW 1 turn 79 small_stepper1.setSpeed(1000); 80 small_stepper2.setSpeed(1000); 81 82 83 Serial.println("Adelante"); 84 85 StepRod2 = HIGH; 86 87 for (int 88 i = 0; i < Steps2Take; i++) { 89 small_stepper1.step(-1); 90 small_stepper2.step(1); 91 92 93 if (choque) { 94 brazo(); 95 choque = false; 96 return; 97 98 } 99 } 100 101 StepRod3 = LOW; 102 } 103 104 105 if (cont == 2) { 106 107 StepRod2 = HIGH; 108 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // 109 Rotate CW 1 turn 110 small_stepper2.setSpeed(1000); 111 112 Serial.println("Giro 113 1"); 114 for (int i = 0; i < Steps2Take; i++) { 115 small_stepper2.step(1); 116 117 118 if (choque) { 119 brazo(); 120 choque = false; 121 return; 122 123 } 124 } 125 126 StepRod1 = LOW; 127 StepRod3 = LOW; 128 129 } 130 131 132 133 if (cont == 3) { 134 StepRod1 = HIGH; 135 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION 136 * 2 ; // Rotate CW 1 turn 137 small_stepper1.setSpeed(1000); 138 139 Serial.println("Giro 140 2"); 141 142 for (int i = 0; i < Steps2Take; i++) { 143 small_stepper1.step(-1); 144 145 146 if (choque) { 147 brazo(); 148 choque = false; 149 return; 150 151 } 152 } 153 154 StepRod2 = LOW; 155 StepRod3 = LOW; 156 } 157 158} 159 160void 161 choca() { 162 choque = true; 163} 164 165 166void brazo() { 167 168 //digitalWrite(StepRod3, 169 HIGH); 170 //delay(500); 171 172 Serial.println("Brazo"); 173 174 Steps2Take 175 = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 176 small_stepper3.setSpeed(1000); 177 178 small_stepper3.step(Steps2Take); 179 180} 181 182/* 183 if (moviPin = HIGH) { 184 185 StepRod1 = HIGH; 186 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // 187 Rotate CW 1 turn 188 small_stepper1.setSpeed(1000); 189 small_stepper1.step(Steps2Take); 190 191 192 StepRod2 = LOW; 193 StepRod3 = LOW; 194 }*/ 195
Code
arduino
1#include <Stepper.h> 2#define STEPS_PER_MOTOR_REVOLUTION 32 3#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64/2 4Stepper small_stepper1(STEPS_PER_MOTOR_REVOLUTION, 10, 12 , 11, 13); 5Stepper small_stepper2(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9); 6Stepper small_stepper3(STEPS_PER_MOTOR_REVOLUTION, 1, 4, 3, 5); 7 8int sensorPin = A2; 9int pushButton = 2; 10int vib_pin = 2; 11int Steps2Take; 12int cont; 13long st; 14int StepRod1; 15int StepRod2; 16int StepRod3; 17 18boolean choque = false; 19 20void setup() { 21 Serial.begin(9600); 22 pinMode(sensorPin, INPUT); 23 pinMode(vib_pin, INPUT); 24 pinMode(StepRod3, OUTPUT); 25 cont = 0; 26 27 attachInterrupt(digitalPinToInterrupt(2), choca, FALLING); 28} 29 30void loop() { 31 32 if (digitalRead(sensorPin) == HIGH) { 33 delay(10); 34 if (cont == 0) 35 st = millis(); 36 cont = cont + 1; 37 while (digitalRead(sensorPin) != LOW) { 38 if (millis() - st > 2000) { 39 Serial.print(cont); 40 Serial.println(" aplausos"); 41 42 doOrders(cont); 43 cont = 0; 44 } 45 } 46 } 47 if (millis() - st > 2000 && cont != 0) { 48 Serial.print(cont); 49 Serial.println(" aplausos"); 50 doOrders(cont); 51 cont = 0; 52 } 53} 54 55 56void doOrders(int apl) { 57 58 59 if (cont == 1) { 60 StepRod1 = HIGH; 61 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 62 small_stepper1.setSpeed(1000); 63 small_stepper2.setSpeed(1000); 64 65 Serial.println("Adelante"); 66 67 StepRod2 = HIGH; 68 69 for (int i = 0; i < Steps2Take; i++) { 70 small_stepper1.step(-1); 71 small_stepper2.step(1); 72 73 if (choque) { 74 brazo(); 75 choque = false; 76 return; 77 } 78 } 79 80 StepRod3 = LOW; 81 } 82 83 84 if (cont == 2) { 85 StepRod2 = HIGH; 86 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 87 small_stepper2.setSpeed(1000); 88 89 Serial.println("Giro 1"); 90 for (int i = 0; i < Steps2Take; i++) { 91 small_stepper2.step(1); 92 93 if (choque) { 94 brazo(); 95 choque = false; 96 return; 97 } 98 } 99 100 StepRod1 = LOW; 101 StepRod3 = LOW; 102 103 } 104 105 106 if (cont == 3) { 107 StepRod1 = HIGH; 108 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 109 small_stepper1.setSpeed(1000); 110 111 Serial.println("Giro 2"); 112 113 for (int i = 0; i < Steps2Take; i++) { 114 small_stepper1.step(-1); 115 116 if (choque) { 117 brazo(); 118 choque = false; 119 return; 120 } 121 } 122 123 StepRod2 = LOW; 124 StepRod3 = LOW; 125 } 126 127} 128 129void choca() { 130 choque = true; 131} 132 133 134void brazo() { 135 136 //digitalWrite(StepRod3, HIGH); 137 //delay(500); 138 139 Serial.println("Brazo"); 140 141 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 142 small_stepper3.setSpeed(1000); 143 small_stepper3.step(Steps2Take); 144 145} 146 147/* 148 if (moviPin = HIGH) { 149 StepRod1 = HIGH; 150 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION * 2 ; // Rotate CW 1 turn 151 small_stepper1.setSpeed(1000); 152 small_stepper1.step(Steps2Take); 153 154 StepRod2 = LOW; 155 StepRod3 = LOW; 156 }*/ 157
Downloadable files
Schematics
Schematics

Comments
Only logged in users can leave comments