Introduction: Practise Metronome
Hello, My name is Prabjyot Singh, and this is my practice metronome. I have made a metronome which can detect if you are actually sitting down and practicing your instrument. if you are not, the metronome will flash an led to catch your attention and to bring you back. The metronome has a green LED which displays the tempo, and a potentiometer which is used to change the tempo. It also has an on/off switch so that you can turn it off once you are done. Let's see how this circuit is made.
Supplies
1 x Arduino Uno ($46.95)
1 x Breadboard ($6.50)
1 x Distance Sensor ($4.50)
1 x Sound Sensor ($2.50)
1 x Slide Switch ($0.45)
1 x Potentiometer ($1.95)
1 x Green Led ($0.01)
1 x Red Led ($0.01)
3 x 330 Ohm Resistors ($0.89 per resistor)
Step 1: Start Building Circuit on Breadboard
For the first step, start placing components into your breadboard. You can copy the placements on my breadboard, or see the next instructions. Make sure to connect these components to the ground and power rails correctly, and using resistors when needed. The distance sensor and the sound sensor should be facing the user. The potentiometer and slide switch should be easily accessible and in a different location than the input components. The leds should be in a highly visible place.
Step 2: Wiring Up With the Arduino
Connect up all of these components with the Arduino. Connect up the power and ground rails on the breadboard to the 5V power and GND ground pins of the Arduino. The potentiometer and the sound sensor are analog input devices, so they must be connected to analog input pins. The rest of the components are digital inputs and outputs so they can be connected to digital pins.
Step 3: Coding
Once everything is connected, it is time to code. The code's variables are sndsnsr (sound sensor), pot (potentiometer), led (green led), alarmled (red led), onoff (slide switch), trig, and echo (distance sensor). The code first defines all of these variables and then it defines the minimum BPM and max BPM. It then declares all of the pins and if they are an input or an output. There are many different functions that can be called upon. The main function is void on, which turns starts the main code for reading the sound sensor and the distance sensor. This function is called upon only if the on off switch is in the on position. In order to make this metronome, I have 2 different states the metronome can be in, the metronome state and the alarm state. When the code is on, it reads the distance and sound, and if the distance is low enough and/or sound is loud enough, the circuit will be in the metronome state. The metronome state reads from the potentiometer and the tempo of the metronome is dependent on the value of the potentiometer's signal. If the potentiometer's signal is higher, the tempo will be higher, it its output is lower the tempo will be lower. This tempo the gets outputted to the green led and the speed of the flashing on the green led is the tempo that the user must follow. But if the distance sensor detects that the user is not nearby and/or the sound sensor detects a low volume, the metronome will be in alarm mode. Alarm mode just flashes the alarm led very quickly over and over again. These modes can be switched in between each other while the circuit is on and working.
Attachments
Step 4: Code
int pot = A1;
int led = 3;
int alarmled = 5;
int onoff = 4;
int trig = 12;
int echo = 13;
int bpm;
#define MIN_BPM 20
#define MAX_BPM 240
void setup (){
pinMode (led, OUTPUT);
pinMode (alarmled, OUTPUT);
pinMode (onoff, INPUT);
pinMode (trig, OUTPUT);
pinMode (echo, INPUT);
Serial.begin(9600);
}
void loop(){
if (digitalRead (onoff)== HIGH)
on();
}
void on(){
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long duration, inches;
duration = pulseIn(echo, HIGH);
inches = duration/74/2;
Serial.println(inches);
int value = analogRead (sndsnsr);
Serial.println(value);
if((value > 550)||(inches < 15)){
metronome();
}
else {
alarm();
}
}
void alarm(){
digitalWrite (alarmled, HIGH);
delay (50);
digitalWrite (alarmled, LOW);
delay (50);
}
void metronome(){
bpm = map(analogRead(pot), 0, 1023, MIN_BPM, MAX_BPM);
tone(led, 2000);
delay(6000 / bpm);
noTone(led);
delay(54000 / bpm);
}
Step 5: Finished Project
the finished project is the practice metronome. To turn it on, simply switch the on/off switch into the on position and start playing an instrument while sitting relatively close to it.