Introduction: B-Daman Speedometer
"Dad, is there something we can build to measure the speed of a B-Daman marble?"
Now THAT's the kind of question a geek dad loves.
This project is built with Arduino, a cheap programmable computer on a circuit board. It allows you to combine readings from things like photoresistors and switches available in most basic electronics kits (we used SnapCircuits), and display those readings on the computer screen or, in this case, a cheap LCD readout which can be scavenged from an old printer or fax machine or bought for not much money if you don't have one lying around.
The unit consists of a scrap board upon which we built a small firing range for the B-Daman. A marble travelling along its course breaks a light beam at the top of the run, signaling the Arduino to start a stopwatch. It then travels a measured distance of 250 mms and hits a slam bar made of a popsicle stick, braced by LEGO, triggering a press-switch. The Arduino calculates the time between the light beam being broken and the switch being pressed and converts this millimeter per millisecond reading to kilometers per hour. The calculation can be displayed in the serial port of the Arduino's parent computer or on an LCD readout for stand-alone, 9-volt-battery-powered play.
Step 1: Step 1: Parts You'll Need
My son Dylan and I built this project from:
50cm board for runway (we made ours of scrapwood)
Wooden block for backstop
Arduino (we used an Uno, but others will work)
Breadboard & Jumper wires
Laserpointer or Flashlight
Press Switch (ideally a Normally Open type that returns to Open after press)
2 x ~10K Resistors
1 8x2 LCD Display (Optional)
1 10k ohm variable potentiometer (Required only if you use the LCD Display)
Step 2: Step 2: Build Your Runway
Head to the scrap wood pile and find yourself a nice flat board. Nail, glue, or screw a backstop block to one end. Make sure it's firmly in place as your marble will be slamming into a bar and compressing against this backstop to trigger the press-switch. You don't want it to move.
Our board was around 50 cm long, of which 25 cm was the measurement run between photosensor and backstop. You can vary the size of the runway to suit your needs or to save cutting a board -- as long as you know the distance between the photosensor and the switch and change the "RunwayLength" variable in the code, you can make this any length.
We then built a superstructure out of LEGO to hold the Photosensor and light source in place, house the slam-bar and switch, and to hold up the display at the end of the runway.
We did this with an elongated "U" of lego: two legs extending away from the backstop and dead-ending with the housings for the light source and photoresistor.
Step 3: Step 3: the Photoresistor, Switch, and LED Build
Our photoresistor and press-switch were scavenged from a SnapCircuits electronics kit. They have nice big plastic housings and snap-on wire connectors (and you can pick up SnapCircuit - Breadboard Pin cables) which makes them ideal candidates for Rubber-band to LEGO mounts.
(OK, I'm going to apologise right here, right now, to the LEGO purists out there. Our build lacks the aesthetic and structural purity we really love in true LEGO MOCs, and I'm genuinely sorry we didn't take more time to make it beautiful, figure out ways to not use elastic and build in pure bricks. If someone wants to build up a worthy reversioning of this project, steal everything here and build it better!!!!)
We enclosed the photosensor as best we could in a LEGO box structure, with a window brick to limit changes in ambient light and shadows causing changes in resistance. We hit on a code solution later which recalibrates an average light reading on each iteration of the code, so you may not need to go to this extreme to isolate your photoresistor. But overall, the less change in light from other angles the less likely you are to get false readings on the beam-break.
The Slam Bar:
I gotta give credit to my son Dylan for this one. It's one of the best, most reliably engineered parts in our rig, and he dreamed it up in his 10-year-old head all by himself. The slam bar is made by placing a popsicle stick along the back wall of the unit just in front of the press switch. It's held up at either end by a LEGO brace with just enough room for the stick to move forward when struck (along flat nubless tiles on the bottom surface) and be held in place by the front and back of mount. A hole the width of a single LEGO row is just right. You want the stick encased on top as well so it doesn't pop up into the air, and you may have to shave a tiny bit of wood off the top of the stick at either end to get complete freedom of movement. If you get it right, the marble will trigger the switch no matter where it hits the slam bar.
The switch we used is Normally Open, which means it doesn't conduct electricity in its rest state (and so transmits "0" to pin A5 of the Arduino. It only sends an electric pulse when pressed, then resets to its Normally Open state all by itself. If you use a different kind of switch, you may need to vary the Arduino code.
The LED just above the slam bar gives an essential piece of feedback: it turns on when the light beam is broken. That's handy to making sure you got a good reading on your measurement and for telling when the unit isn't in ready state for a new speed run: if the light is on, you need to reset the unit, which you can do simply by pressing the slam-bar switch. That also turns the LED off by setting it low.
Since it's quite easy to accidentally break the light beam, (even changing light conditions can cause this) the light is a good indicator that you need to reset, which automatically recalibrates the light average.
Step 4: Step 4: Plugging It All In: the Circuit
First step, connect your 5v and ground from the Arduino to the positive and negative rails on your breadboard. (Remember that the power rails on a breadboard (marked with red and blue lines in the illustration) are connected horizontally, while the middle banks of holes are connected vertically, with a break across the middle.)
Connect one of your Photoresistor leads to analog input A0 on the Arduino and ground, with a resistor of around 10K in between. (I used 16K because they were lying around)
The other lead goes to the +5v rail on your breadboard.
Connect one lead from the switch on the slam-bar to analog input A5 on the arduino and ground, with another resistor of around 10K between. The other lead again goes to the positive +5 volt rail.
Your LED gets connected between digital pin 13 and ground. NB: some LEDs require you to put a resistor in the circuit to avoid a short. Some have a resistor built in. If in doubt, put a resistor in your circuit. You really don't want to short your Arduino out!
That's all you need for the sensing circuits. If you're going to just get readings from the Serial window of the Arduino's parent computer, you can skip the next step. But if you want a stand-alone speedometer that runs on a 9 volt battery, get yourself an LCD display. They're fun.
Step 5: Step 5: the LCD Display (Optional)
Before you run out and buy a display, dig around in your basement. You may be able to find a Hitachi 16 x 2 or 16 x 1 LCD display in an old printer or fax machine, video camera, or even toy. If it's got 16 pins, it's most likely a Hitachi. Because these things could display simple messages in Kanji or ascii, they were in electronics all over the world for many many years. A little applied pressure and a soldering iron can bring new display options to your Arduino right out of the junk heap.
Now if you've looked at the circuit above and asked "A variable potentiometer? Really?" Let me save you some time. Really. Without it, you can't adjust the contrast on the display, and that's pretty essential. You may have a working circuit and a blank screen. Without that pot to adjust contrast, you won't see anything in some light conditions. We snagged ours from our SnapCircuits kit again, but any old scavenged 10 ohm pot will do.
As in the diagram, you want to connect:
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
10K pot to +5V and GND, with wiper output to LCD screens VO pin (pin3).
(Not shown in the diagram above, but if you run a cable from +5 volts on your breadboard to pin 15 on the LCD you'll fire up the backlight, which helps see the display at night if you're having a B-Daman sleep-over.)
Step 6: Step 5: the Code
Here's the Code to upload to the Arduino. You'll need to install the Stopwatch Class library. The LCD Library will already be in your default distribution libraries that came with the Arduino. Note that to get accurate speed readings, you will need to change the RunwayLength variable to match the distance between your photosensor and switch: NOT the B-Daman itself! Remember, you're calculating the time between the light-beam break and the switch press.
(This code is also available on GitHub, where somebody may have improved it! Dammit, Jim, I'm a hobbyist, not a Code Monkey!)
7 years ago on Introduction
cool i like b daman this is cool!!
8 years ago on Introduction
Also you should think about entering this into our First Time Author's Challenge!
Reply 8 years ago on Introduction
Thanks, but that wouldn't be fair -- I've authored before on another account. Just messed up loging in when I posted this... DOH....
8 years ago on Introduction
You sir are an awesome geek dad. This is a very cool contraption, and it looks like it works really well! I hope your kid enjoyed the knowledge!
Reply 8 years ago on Introduction
Awwww, shucks. Yeah, we had a great time building it, and he's having a great time competing with his friends for who's b-daman is the fastest.