The software for the fidget spinner tachometer is an Arduino sketch that's included in the Adafruit Circuit Playground library. Make sure you've installed the Adafruit Circuit Playground library, either using the Arduino library manager or with a manual installation from its source on Github. If you already have the library installed be sure to use Arduino's library manager to update the library to the latest version so you get the most recent example sketch code.
Next look for the tachometer or tachometer_led_display examples in the Adafruit Circuit Playground library in Arduino:
The tachometer example will detect the speed of a fidget spinner and just print it out on the serial monitor, and the tachometer_led_display example will do the same but also print the speed on a connected 7-segment LED backpack display. Open the appropriate example for your hardware setup.
If you don't see the tachometer examples be sure to update your Circuit Playground library to the latest version!
At the top of the tachometer sketches are configuration defines which you can optionally change to adjust the behavior of the tachometer:
// Configuration values. You don't have to change these but they're // interesting to adjust the logic. If your spinner has more or less // than three arms be sure to change the SPINNER_ARMS value below: #define SPINNER_ARMS 3 // Number of arms on the fidget spinner. // This is used to calculate the true // revolutions per second of the spinner // as one full revolution of the spinner // will actually see this number of cycles // pass by the light sensor. Set this to // the value 1 to ignore this calculation // and just see the raw cycles / second. #define SAMPLE_DEPTH 512 // How many samples to take when measuring // the spinner speed. The larger this value // the more memory that will be consumed but // the slower a spinner speed that can be // detected (larger sample depths mean longer // period waves can be detected). You're // limited by the amount of memory on the // board for this value. On a classic // Circuit Playground with 2kb of memory // you can only go up to about 512 or so (each // sample is 2 bytes, so 1kb of space total). // On an express board you can go much higher, // like up to 10240 for 20kb of sample data. #define SAMPLE_PERIOD_US 1500 // Amount of time in microseconds to delay // between each light sensor sample. This is // a balance between how fast and slow of // a spinner reading that can be measured. // The higher this value the slower a spinner // you can measure, but at the tradeoff of // not accurately measuring fast spinners. // Low values (even 0) mean very fast speeds // can be detected but slow speeds (below 10hz) // are harder to detect. You can increase the // sample depth to help improve the range // of detection speeds, but there's a limit // based on the memory available. #define THRESHOLD 400 // How big the amplitude of a cyclic // signal has to be before the measurement // logic kicks in. This is a value from // 0 to 1023 and might need to be adjusted // up or down if the detection is too // sensitive or not sensitive enough. // Raising this value will make the detection // less sensitive and require a very large // difference in amplitude (i.e. a very close // or highly reflective spinner), and lowering // the value will make the detection more // sensitive and potentially pick up random // noise from light in the room. #define MEASURE_PERIOD_MS 1000 // Number of milliseconds to wait // between measurements. Default is // one second (1000 milliseconds).
In particular the SPINNER_ARMS configuration define might need to be adjusted based on the number of arms on the fidget spinner you're using with the sketch. Set this value to the number of arms or protrusions from the spinner. The sketch uses this value to correctly determine the speed of an entire revolution of the spinner. If you just want to see the speed of a single arm moving by the sensor (or are unsure how many arms are on your spinner) try setting this to a value of 1 to get the raw spinning speed.
The other configuration defines are optional and adjust the sensitivity and range of speeds the tachometer can detect. Read the comments next to the defines, and watch the video about the tachometer code to see how these values adjust the behavior of the tachometer.
When you're ready to use the tachometer upload it to your Circuit Playground board. Once uploaded you should see the first three NeoPixels turn on to bright white color. Then open the serial monitor at 115200 baud and you're ready to detect the speed of a spinner.
Flick a fidget spinner to get it moving very quickly and then hold it perpendicular (i.e. at a 90 degree angle) to the Circuit Playground board right above the light sensor (the light sensor is right below the 3 lit up NeoPixels and has a little eye symbol printed on the board). Hold the spinner as close to the sensor as you can without it hitting the board. Now look at the serial monitor output and you should see the detect speed printed out every second!
Notice as the spinner slows down the frequency, or number of times the spinner rotates in a second, slows down too. In addition the RPM (revolutions per minute) of the spinner slows down, and the period, or amount of time between a full spin of the spinner, increases.
If you're holding your spinner in front of the sensor and not seeing any output from the serial monitor you might need to adjust the THRESHOLD define at the top of the sketch and try again. Try lowering the threshold to smaller value like 300 or 200. The lower you make the threshold the more sensitive the tachometer, however one the threshold is too low it might be too sensitive and detect random noise as speed.
If you're using the tachometer_led_display example you should see it print the frequency, or speed of the spinner in revolutions per second, on the display in addition to the serial monitor. If you don't see the display printing the speed but do see it output in the serial monitor double check your LED backpack wiring.
That's all there is to using the fidget spinner tachometer example! Check out the video about this project to learn how the tachometer works, specifically how it uses reflections of light hitting the light sensor to determine the speed of the spinner. The sketch performs a simple frequency detection by counting how often the light sensor signal changes during a short period of time.
Text editor powered by tinymce.