The hardware is just a home made electromagnet powered through a ULN2003 (linking 2 channels to boost current). This was controlled using an Arduino Nano. I added an LED to indicate when the electromagnet was activated, and a button to activate it. The switch that detected the ball hitting the ground was also home made from a peg, some paperclips and tin foil:
The plan for the program was:
- Push a button on the rig to activate the electromagnet for long enough to attach a bearing but not so long it burns out the hardware (4 seconds seemed about right)
- Switch off the electromagnet automatically and simultaneously start a timer.
- When the pressure switch is activated by the ball hitting the ground, stop the timer.
- Work out the acceleration using a = 2s / t**2
- (s= distance fallen, t is the time)
I started the code in Ardublock because it avoids typing errors, but the calculations refused to give a valid result even when the timing was giving valid readings. After a frustrating hour of trying to fix it within Ardublock, 3 minutes with the actual code in the Arduino IDE had it working well. The erroneous values are when the ball missed the switch and I had to trigger it manually.
The code:
https://github.com/jcwyatt/gravityfalls
No comments:
Post a Comment