-
1Step 1
Step 1: Base Layer
The first thing we need is a platform for the chains, stepper motors, and bearings.
1) Using a 2'x4' handy panel and a plunge router; I carved out 5 ovals for the tracks. Start with half circles, then connect them.
2) The depth is slightly deeper than a #25 bike chain.
3) Each track is 2" from the side, and 1.5 inches apart.4) Drill holes through the board for sprocket access.
5) Drill holes deep enough for 2 inline skate bearings. This will give the sprocket something to push the chain into.
6) Using #25 bike chain, cut to length and connect.
Final base layer)
-
2Step 2
Step 2: Switch Layer
This layer will sit directly on top of the base layer. The 10 switches for the starting and finishing line will attach to this board.
1) Using a 2'x4' handy panel, carve out a groove deep enough and wide enough for a SPDT lever switch to sit in.
2) Carve out the same size ovals as the base layer. This time the cut goes all the way through the board.
3) Drill Holes in the middle of the groove of the switch layer, through the base layer for wiring the switches.
-
3Step 3
Race layer:
Using the same router methods, carve out another oval track with no holes or grooves. This will be the top layer of the track.
-
4Step 4
Platform:
1) Using 2"x4"'s build a platform for your derby. I built mine 16.5 inches, but your's may be taller or shorter based on how high or low you want it. The width is 48" like the base layer.
2) Using 2"x6"'s build a case for your electronics and stepper motors.
3) Attach the case and platform with door hinges for easy access.
-
5Step 5
Making them move)
1) Connect your stepper motors to stepper motor controllers, then to the Arduino boards (I used uno's). Each motor used a separate board. You will also need a power supply for the stepper motors, and power supply for the Arduino boards.
I connected:
DIR- Arduino Pin 10
DIR+ Arduino Pin 11
PUL- Arduino Pin 12
PUL+ Arduino Pin 13Upload a simple code to test all five horses are hooked up correctly.
#include <Stepper.h> Stepper horse(800, 13, 12, 11, 10); void setup() { horse.setSpeed(70); } void loop() { horse.step(400); delay(200); }
-
6Step 6
Adding the switches)
1) Attach the switch layer and wire the 5 switches to a mega board. I used a mega for each of the 5 switches, but you could do it with a single one if you wanted to.
2) Run a wire from the switch mega to each horse uno. You will also need to connect all of the grounds.
3) Change the program in the uno's so that if they receive a HIGH signal from the mega board, they will delay.
#include <Stepper.h> Stepper horse(800, 13, 12, 11, 10); void setup() { horse.setSpeed(70); pinMode(6, INPUT); pinMode(7, INPUT); } void loop() { horse.step(400); delay(200); while (digitalRead(6) == HIGH) { delay(1); } while (digitalRead(7) == HIGH) { delay(1); } }
4) Program the finish and start sensor to delay the horse until all 5 have finished.
boolean h1finish = false; boolean h2finish = false; boolean h3finish = false; boolean h4finish = false; boolean h5finish = false; void setup() { pinMode(53, INPUT); pinMode(52, OUTPUT); pinMode(51, INPUT); pinMode(50, OUTPUT); pinMode(49, INPUT); pinMode(48, OUTPUT); pinMode(47, INPUT); pinMode(46, OUTPUT); pinMode(45, INPUT); pinMode(44, OUTPUT); } void loop() { if (digitalRead(53) == HIGH) { digitalWrite(52, HIGH); h5finish = true; } if (digitalRead(51) == HIGH) { digitalWrite(50, HIGH); h1finish = true; } if (digitalRead(49) == HIGH) { digitalWrite(48, HIGH); h4finish = true; } if (digitalRead(47) == HIGH) { digitalWrite(46, HIGH); h2finish = true; } if (digitalRead(45) == HIGH) { digitalWrite(44, HIGH); h3finish = true; } if (h1finish == true && h2finish == true && h3finish == true && h4finish == true && h5finish == true) { delay(5000); digitalWrite(52, LOW); digitalWrite(50, LOW); digitalWrite(48, LOW); digitalWrite(46, LOW); digitalWrite(44, LOW); delay(5000); h1finish = false; h2finish = false; h3finish = false; h4finish = false; h5finish = false; } }
-
7Step 7
Time the horses)
Depending on your length of track, stepper motors, and other various things your horses will run at different speeds. I first get the time of horse #5 (longest track) going at it's fastest speed and work up from there. Come up with races for all 5 horses that are the same time.
-
8Step 8
Understanding the odds)
-
9Step 9
Programming the finish switch Mega board)
The finish switch Mega board will be the brains of the operation. It will come up with a 5 digit number to Serial communicate to the other boards. The 5 digit number will contain 3 pieces of information. The first two digits (12xxx) will be the odds for the next race. The third and fourth digits will be the race to run (xx34x) and the fifth digit will be the winner of the previous race (xxxx1).
boolean h1finish = false; boolean h2finish = false; boolean h3finish = false; boolean h4finish = false; boolean h5finish = false; int first = 0; int second = 0; int third = 0; int fourth = 0; int fifth = 0; int lastrace = 0; int nextracenum = 0; long nextraceodds = 0; long lastraceodds = 0; long nro = 0; int h12odds = 0; int h13odds = 0; int h14odds = 0; int h15odds = 0; int h23odds = 0; int h24odds = 0; int h25odds = 0; int h34odds = 0; int h35odds = 0; int h45odds = 0; int oddssum = 0; int oddssum1 = 0; int oddssum2 = 0; int oddssum3 = 0; int oddssum4 = 0; int oddssum5 = 0; int oddssum6 = 0; int oddssum7 = 0; int oddssum8 = 0; int oddssum9 = 0; int oddssum10 = 0; int oddstotal = 0; int winner = 0; int racenum = 0; void setup() { pinMode(45, INPUT); pinMode(47, INPUT); pinMode(49, INPUT); pinMode(51, INPUT); pinMode(53, INPUT); pinMode(52, OUTPUT); pinMode(50, OUTPUT); pinMode(48, OUTPUT); pinMode(46, OUTPUT); pinMode(44, OUTPUT); digitalWrite(52, LOW); digitalWrite(50, LOW); digitalWrite(48, LOW); digitalWrite(46, LOW); digitalWrite(44, LOW); Serial.begin(9600); randomSeed(analogRead(0)); } void loop() { if (digitalRead(53) == HIGH && h5finish == false) { h5finish = true; digitalWrite(52, HIGH); if (first == 0) { first = 5; } else if (second == 0) { second = 5; } else if (third == 0) { third = 5; } else if (fourth == 0) { fourth = 5; } else if (fifth == 0) { fifth = 5; } } if (digitalRead(51) == HIGH && h4finish == false) { digitalWrite(50, HIGH); h4finish = true; if (first == 0) { first = 4; } else if (second == 0) { second = 4; } else if (third == 0) { third = 4; } else if (fourth == 0) { fourth = 4; } else if (fifth == 0) { fifth = 4; } } if (digitalRead(49) == HIGH && h3finish == false) { digitalWrite(48, HIGH); h3finish = true; if (first == 0) { first = 3; } else if (second == 0) { second = 3; } else if (third == 0) { third = 3; } else if (fourth == 0) { fourth = 3; } else if (fifth == 0) { fifth = 3; } } if (digitalRead(47) == HIGH && h2finish == false) { digitalWrite(46, HIGH); h2finish = true; if (first == 0) { first = 2; } else if (second == 0) { second = 2; } else if (third == 0) { third = 2; } else if (fourth == 0) { fourth = 2; } else if (fifth == 0) { fifth = 2; } } if (digitalRead(45) == HIGH && h1finish == false) { digitalWrite(44, HIGH); h1finish = true; if (first == 0) { first = 1; } else if (second == 0) { second = 1; } else if (third == 0) { third = 1; } else if (fourth == 0) { fourth = 1; } else if (fifth == 0) { fifth = 1; } } if (h1finish == true && h2finish == true && h3finish == true && h4finish == true && h5finish == true) { if (first == 1 && second == 2) { lastrace = 0; } else if (first == 2 && second == 1) { lastrace = 0; } else if (first == 1 && second == 3) { lastrace = 1; } else if (first == 3 && second == 1) { lastrace = 1; } else if (first == 1 && second == 4) { lastrace = 2; } else if (first == 4 && second == 1) { lastrace = 2; } else if (first == 1 && second == 5) { lastrace = 3; } else if (first == 5 && second == 1) { lastrace = 3; } else if (first == 2 && second == 3) { lastrace = 4; } else if (first == 3 && second == 2) { lastrace = 4; } else if (first == 2 && second == 4) { lastrace = 5; } else if (first == 4 && second == 2) { lastrace = 5; } else if (first == 2 && second == 5) { lastrace = 6; } else if (first == 5 && second == 2) { lastrace = 6; } else if (first == 3 && second == 4) { lastrace = 7; } else if (first == 4 && second == 3) { lastrace = 7; } else if (first == 3 && second == 5) { lastrace = 8; } else if (first == 5 && second == 3) { lastrace = 8; } else if (first == 4 && second == 5) { lastrace = 9; } else if (first == 5 && second == 4) { lastrace = 9; } nextraceodds = random(10,35); while (nextraceodds == lastraceodds) { nextraceodds = random(10,35); } lastraceodds = nextraceodds; nro = nextraceodds * 1000; // 25 * 1000 = 25000 nro = nro + lastrace; // 25003 switch(nextraceodds) { case 10: h12odds = 14; h13odds = 9; h14odds = 39; h15odds = 5; h23odds = 11; h24odds = 47; h25odds = 6; h34odds = 23; h35odds = 3; h45odds = 12; break; case 11: h12odds = 9; h13odds = 21; h14odds = 11; h15odds = 36; h23odds = 6; h24odds = 3; h25odds = 10; h34odds = 7; h35odds = 23; h45odds = 12; break; case 12: h12odds = 19; h13odds = 3; h14odds = 6; h15odds = 25; h23odds = 9; h24odds = 18; h25odds = 76; h34odds = 4; h35odds = 17; h45odds = 34; break; case 13: h12odds = 10; h13odds = 7; h14odds = 6; h15odds = 4; h23odds = 23; h24odds = 20; h25odds = 13; h34odds = 14; h35odds = 9; h45odds = 8; break; case 14: h12odds = 2; h13odds = 34; h14odds = 8; h15odds = 5; h23odds = 49; h24odds = 12; h25odds = 7; h34odds = 200; h35odds = 119; h45odds = 29; break; case 15: h12odds = 95; h13odds = 4; h14odds = 9; h15odds = 37; h23odds = 21; h24odds = 49; h25odds = 200; h34odds = 2; h35odds = 8; h45odds = 19; break; case 16: h12odds = 59; h13odds = 5; h14odds = 23; h15odds = 18; h23odds = 9; h24odds = 42; h25odds = 33; h34odds = 4; h35odds = 3; h45odds = 14; break; case 17: h12odds = 32; h13odds = 44; h14odds = 109; h15odds = 25; h23odds = 5; h24odds = 12; h25odds = 3; h34odds = 17; h35odds = 4; h45odds = 10; break; case 18: h12odds = 4; h13odds = 8; h14odds = 13; h15odds = 5; h23odds = 10; h24odds = 16; h25odds = 6; h34odds = 33; h35odds = 12; h45odds = 20; break; case 19: h12odds = 2; h13odds = 7; h14odds = 5; h15odds = 8; h23odds = 15; h24odds = 11; h25odds = 17; h34odds = 38; h35odds = 61; h45odds = 43; break; case 20: h12odds = 38; h13odds = 2; h14odds = 7; h15odds = 24; h23odds = 16; h24odds = 60; h25odds = 200; h34odds = 3; h35odds = 10; h45odds = 37; break; case 21: h12odds = 8; h13odds = 161; h14odds = 12; h15odds = 24; h23odds = 26; h24odds = 2; h25odds = 4; h34odds = 40; h35odds = 80; h45odds = 6; break; case 22: h12odds = 6; h13odds = 12; h14odds = 3; h15odds = 36; h23odds = 16; h24odds = 4; h25odds = 49; h34odds = 8; h35odds = 11; h45odds = 24; break; case 23: h12odds = 8; h13odds = 29; h14odds = 200; h15odds = 9; h23odds = 6; h24odds = 42; h25odds = 2; h34odds = 159; h35odds = 7; h45odds = 47; break; case 24: h12odds = 2; h13odds = 47; h14odds = 108; h15odds = 18; h23odds = 17; h24odds = 6; h25odds = 3; h34odds = 20; h35odds = 16; h45odds = 19; break; case 25: h12odds = 8; h13odds = 43; h14odds = 108; h15odds = 18; h23odds = 17; h24odds = 6; h25odds = 3; h34odds = 20; h35odds = 16; h45odds = 19; break; case 26: h12odds = 2; h13odds = 8; h14odds = 4; h15odds = 15; h23odds = 14; h24odds = 7; h25odds = 26; h34odds = 29; h35odds = 107; h45odds = 88; break; case 27: h12odds = 5; h13odds = 7; h14odds = 28; h15odds = 14; h23odds = 3; h24odds = 12; h25odds = 6; h34odds = 16; h35odds = 8; h45odds = 33; break; case 28: h12odds = 3; h13odds = 19; h14odds = 2; h15odds = 21; h23odds = 38; h24odds = 4; h25odds = 48; h34odds = 9; h35odds = 99; h45odds = 24; break; case 29: h12odds = 27; h13odds = 9; h14odds = 136; h15odds = 13; h23odds = 4; h24odds = 61; h25odds = 6; h34odds = 20; h35odds = 2; h45odds = 3; break; case 30: h12odds = 2; h13odds = 7; h14odds = 63; h15odds = 12; h23odds = 3; h24odds = 26; h25odds = 5; h34odds = 21; h35odds = 4; h45odds = 36; break; case 31: h12odds = 11; h13odds = 14; h14odds = 6; h15odds = 43; h23odds = 7; h24odds = 3; h25odds = 21; h34odds = 4; h35odds = 28; h45odds = 12; break; case 32: h12odds = 8; h13odds = 86; h14odds = 18; h15odds = 17; h23odds = 19; h24odds = 3; h25odds = 4; h34odds = 30; h35odds = 40; h45odds = 6; break; case 33: h12odds = 14; h13odds = 29; h14odds = 6; h15odds = 109; h23odds = 9; h24odds = 2; h25odds = 34; h34odds = 4; h35odds = 70; h45odds = 15; break; case 34: h12odds = 5; h13odds = 9; h14odds = 17; h15odds = 16; h23odds = 4; h24odds = 8; h25odds = 7; h34odds = 14; h35odds = 13; h45odds = 25; break; } oddssum = h12odds + h13odds + h14odds + h15odds + h23odds + h24odds + h25odds + h34odds + h35odds + h45odds; oddssum1 = int(oddssum / h12odds); oddssum2 = int(oddssum / h13odds + oddssum1); oddssum3 = int(oddssum / h14odds + oddssum2); oddssum4 = int(oddssum / h15odds + oddssum3); oddssum5 = int(oddssum / h23odds + oddssum4); oddssum6 = int(oddssum / h24odds + oddssum5); oddssum7 = int(oddssum / h25odds + oddssum6); oddssum8 = int(oddssum / h34odds + oddssum7); oddssum9 = int(oddssum / h35odds + oddssum8); oddssum10 = int(oddssum / h45odds + oddssum9); winner = random(1,oddssum10+1); if (winner > 0 && winner <= oddssum1 ) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 20; case 2: nextracenum = 21; case 3: nextracenum = 40; case 4: nextracenum = 41; case 5: nextracenum = 60; case 6: nextracenum = 61; break; } } else if (winner > oddssum1 && winner <= oddssum2) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 22; break; case 2: nextracenum = 23; break; case 3: nextracenum = 42; break; case 4: nextracenum = 43; break; case 5: nextracenum = 62; break; case 6: nextracenum = 63; break; } } else if (winner > oddssum2 && winner <= oddssum3) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 24; break; case 2: nextracenum = 25; break; case 3: nextracenum = 44; break; case 4: nextracenum = 45; break; case 5: nextracenum = 64; break; case 6: nextracenum = 65; break; } } else if (winner > oddssum3 && winner <= oddssum4) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 26; break; case 2: nextracenum = 27; break; case 3: nextracenum = 46; break; case 4: nextracenum = 47; break; case 5: nextracenum = 66; break; case 6: nextracenum = 67; break; } } else if (winner > oddssum4 && winner <= oddssum5) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 28; break; case 2: nextracenum = 29; break; case 3: nextracenum = 48; break; case 4: nextracenum = 49; break; case 5: nextracenum = 68; break; case 6: nextracenum = 69; break; } } else if (winner > oddssum5 && winner <= oddssum6) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 30; break; case 2: nextracenum = 31; break; case 3: nextracenum = 50; break; case 4: nextracenum = 51; break; case 5: nextracenum = 70; break; case 6: nextracenum = 71; break; } } else if (winner > oddssum6 && winner <= oddssum7) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 32; break; case 2: nextracenum = 33; break; case 3: nextracenum = 52; break; case 4: nextracenum = 53; break; case 5: nextracenum = 72; break; case 6: nextracenum = 73; break; } } else if (winner > oddssum7 && winner <= oddssum8) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 34; break; case 2: nextracenum = 35; break; case 3: nextracenum = 54; break; case 4: nextracenum = 55; break; case 5: nextracenum = 74; break; case 6: nextracenum = 75; break; } } else if (winner > oddssum8 && winner <= oddssum9) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 36; break; case 2: nextracenum = 37; break; case 3: nextracenum = 56; break; case 4: nextracenum = 57; break; case 5: nextracenum = 76; break; case 6: nextracenum = 77; break; } } else if (winner > oddssum9 && winner <= oddssum10) { racenum = random(1,7); switch(racenum) { case 1: nextracenum = 38; break; case 2: nextracenum = 39; break; case 3: nextracenum = 58; break; case 4: nextracenum = 59; break; case 5: nextracenum = 78; break; case 6: nextracenum = 79; break; } } nro = nro + (nextracenum * 10); // 65 = 650 + 25005 = 25655 Serial.write(nro); Serial.print(nro); delay(3000); digitalWrite(52, LOW); digitalWrite(50, LOW); digitalWrite(48, LOW); digitalWrite(46, LOW); digitalWrite(44, LOW); delay(7500); lastrace = 0; first = 0; second = 0; third = 0; fourth = 0; fifth = 0; h1finish = false; h2finish = false; h3finish = false; h4finish = false; h5finish = false; } }
-
10Step 10
Program the start switch Mega)
The start switch board will be connected to the 5 switches at the start line and the countdown clock. Once all five horses have reached the start line and the countdown clock has reached 0, the horses will be released to race.
boolean h1staged = false; boolean h2staged = false; boolean h3staged = false; boolean h4staged = false; boolean h5staged = false; void setup() { pinMode(45, INPUT); // horse pinMode(47, INPUT); // horse pinMode(49, INPUT); // horse pinMode(51, INPUT); pinMode(53, INPUT); pinMode(52, OUTPUT); pinMode(50, OUTPUT); pinMode(48, OUTPUT); pinMode(46, OUTPUT); pinMode(44, OUTPUT); pinMode(2, INPUT); digitalWrite(52, LOW); digitalWrite(50, LOW); digitalWrite(48, LOW); digitalWrite(46, LOW); digitalWrite(44, LOW); delay(15000); } void loop() { if (digitalRead(53) == HIGH && h5staged == false) { digitalWrite(52, HIGH); h5staged = true; } if (digitalRead(49) == HIGH && h4staged == false) { digitalWrite(48, HIGH); h4staged = true; } if (digitalRead(45) == HIGH && h3staged == false) { digitalWrite(44, HIGH); h3staged = true; } if (digitalRead(47) == HIGH && h2staged == false) { digitalWrite(46, HIGH); h2staged = true; } if (digitalRead(51) == HIGH && h1staged == false) { digitalWrite(50, HIGH); h1staged = true; } if (h1staged == true && h2staged == true && h3staged == true && h4staged == true && h5staged == true) { while (digitalRead(2) == HIGH) { delay(1); } digitalWrite(52, LOW); digitalWrite(50, LOW); digitalWrite(48, LOW); digitalWrite(46, LOW); digitalWrite(44, LOW); h1staged = false; h2staged = false; h3staged = false; h4staged = false; h5staged = false; delay(6000); } }
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.