Arduino Robot Plays Music on Wine Glasses
Introduction: Arduino Robot Plays Music on Wine Glasses
Hello everyone, today I will tell you about how I assembled an arduino robot that plays music on wine glasses.
Supplies
And so, let's take everything in order. To implement the project, I will need: wine glasses, a stepper motor, a car relay, a4988 stepper motor driver - an arduino nano will manage the whole thing.
Step 1:
You can write the melody yourself or find a ready-made one on the musicboxmaniacs website. If you use a ready-made melody, then first you need to remove polyphony from it - this means that there should not be more than one note in one musical measure. After that, transfer it manually in the following order: the lowest note has a value of 0, and so on up to the highest. I have only 7 glasses at my disposal, which means that there should not be more than 7 notes. For simple melodies this will be enough. And there is also an empty bar - its value in the array is 255. The sound of the glasses is adjusted to the desired note with the help of water. To lower the tone, you need to add water to it. For fine tuning, you can use the Piano Tuner smartphone app from play Google.
Step 2:
The algorithm of the code is as follows: the array stores notes numbered in ascending order from the lowest equal to 0 and to the highest equal to 6. 1003
Each note corresponds to its own glass. An empty measure is numbered with a value of 255. The melody is clocked by a timer and the tempo of the music can be set in the code settings. To do this, you need to specify the required number of ticks per second. But keep in mind, there is a limit to everything and a moment will come when the motor will not keep up with the tempo of the music and will start skipping notes. Especially when moving from the highest pitch to the lowest, and vice versa. By the way, the more glasses there are, the fewer steps you need to scroll between notes. With each measure, the current and next note is selected from the array, which is converted into the corresponding number of steps and sent for execution to the stepper motor. The algorithm reads notes in advance by 1 step, which makes it possible to move the hammer to the next glass in advance. All settings are in the header of the sketch and are written in the define directives.
Step 3:
#include "Adafruit_NeoPixel.h"
#include "CyberLib.h"
#define DEBUG false //false true включить режим отладки
#define DIR_1 D8_High
#define STEP_1 D9_High
#define HAMMER_1 D10_High
#define DIR_0 D8_Low
#define STEP_0 D9_Low
#define HAMMER_0 D10_Low
#define WS2812_PIN 11 // выход для подключения ws2812
#define step_num 400 // количество шагов на 1 оборот ШД. включен полушаговый режим для снижения шума
#define note_num 7 // Количество нот-бокалов
#define step_note step_num/note_num // количество шагов двигателя между нотами. 226