-
Bare ATMega328p, $5 from Sparkfun (and Tiny AVR Programmer, $20)
-
28-pin DIP socket for ATMega328p, $1
-
7-segment 4-character LED with decimal points, common anode $2 from SparkFun though a version with an I2C interface may be worth the $10 for easy wiring
-
Electromagnet (hand-wound magnet wire on iron rod, 5 ohms)
-
MOSFET ($1) to drive coil
-
Flyback Schottky diode (15 cents) for coil; a 1N4001 seems to work fine too
-
IR rangefinder (VCNL4000)
-
3.3v regulator, $2 for IR rangefinder (note the linked regulator has unusual pinouts)
-
5x 1/8W 1K ohm resistors (current limiting for transistor and MOSFET bases; exact value is not critical)
-
4x transistors for LED segment anodes
-
4x 1/4W 220 ohm resistors for LED segment anodes
-
5v 3A switching power supply (110-220VAC input), about $10, and lamp cord to connect to mains power. My PSU, billed as an LED power supply, had coil whine (more from Corsair), and coating one of its inductors with clear nail polish helped slightly. I also tried using repurposing a computer PSU, which had sufficient current on one unit but reset occasionally with another.
The spinner draws 1.5A max, and about 200mA when the coil is off. The LED segment anodes can be powered directly from 1K ohm resistors from the ATMega, but that renders them somewhat dim. Using a transistor to provide 5v to the (common) anode pin keeps the per-pin current low while providing more power to the LED segments.
You can add a bypass or filter capacitor by the coil, microcontroller, and/or power supply; I found it didn’t make a difference with my PSU.
Burning a bootloader and uploading sketches to a bare ATMega328p using the Tiny AVR programmer follows SparkFun’s and Arduino’s documentation. Additional notes:
-
Connect the Tiny AVR programmer to the DIP on a breadboard as pictured.
-
Upload sketches using Sketch > Upload using Programmer. The normal upload button will not work.
-
An external crystal is required if fuses are not already set for an internal clock.
-
Empirically, it seems the external pullup resistor and the AREF-side ground and AVCC are not required for uploading sketches.
-
This spins a 3D-printed spinner designed and printed by Jesse Johnson; see it in OnShape (login required). It uses a 22m bearing and 3/4" balls.