During the hands-on minds-on exercise at the start of the week session, we played different melodies using Arduino on TinkerCad.
Following that, I was tempted to build a MIDI Keyboard that could play a scale, and communicate Musical Instrument Digital Interface (MIDI) data to my laptop's DAW.
And, in order to reduce the number of buttons required (8 notes in a major scale) to match the analog input pins (5 on the Arduino board), I chose to employ an ultrasonic sensor in a way similar to laser projection keyboards.
TinkerCad:
To create the circuit from scratch and design its function using code blocks.
Arduino IDE:
To upload the code into the Arduino UNO board.
Hairless MIDI:
To Communicate MIDI Data from Arduino to the DAW.
Protools First:
DAW (Digital Audio Workstation)
Arduino Uno R3
100 Ω Resistor
Piezo Buzzer
Ultrasonic Distance Sensor
220 Ω Resistor
1 kΩ Potentiometer
Red LED
I have a potentiometer for the input that changes the maximum distance the user is allowed to place their hands for the Buzzer to make a sound.
An ultrasonic sensor then sends distances in centimeters to the Arduino.
The distance is then "mapped" by the Arduino into LED brightness and Piezo Buzzer tones.
For output, I have a LED and a Piezo Buzzer, and the maximum distance will be displayed on the serial monitor.
I declared two variables: brightness and maximum distance.
I used the map function three times:
to map the potentiometer into the maximum distance variable
to map the Ultrasonic Sensor reading into a brightness (range of 0 to 255) to power the LED.
to map the Ultrasonic Sensor Reading into tones (from 262 to 494); the A Major Scale
After printing the Max Distance for the user on the serial, the code then executes an if condition (if my hand's distance is within the max distance range, then
play the tone corresponding to my hands' position.
illuminate the LED with the corresponding brightness.
I placed all of the components on the breadboard. And I double-checked that the Ultrasonic Sensor and potentiometer were connected to the proper pins specified in the code blocks.
Then, after testing the jumpers with an Avometer, I wired the Arduino's power and ground terminals to the board and finished the rest of the wiring.
After that, I downloaded the Tinkercad code, changed some of the inputs to input pull-up, double-checked for logical errors, and uploaded it to the Arduino.
To accomplish the second goal of this assignment (communicating midi data to a DAW), I included a library (MIDI.h) in the code and added lines of code based on the library's documentation on GitHub.
p.s. To download libraries from the Arduino IDE, press "Ctrl+Shift+I" and type the name of the library into the search bar.
Our peer, Mohammed Abo Warda, suggested using INPUT_PULLUP for the pinMode instead of connecting a resistor to the component, as it sets an internal resistance of 20k to 50k.
During the Midweek Session, our instructor Ahmed Khaled demonstrated how to set RGB LED colors using decimal (R, G, B) codes ranging from 0 to 255. So, for example, Red is (255,0,0), Green is (0,255,0), Blue is (0,0,255), and all other colors are essentially a combination of all three. And that we could obtain the RGB code of our desired shade using tools as simple as Microsoft Paint.
We also had an extra task where we experimented with designing different Modes using Nested Conditioning!
Variables
Instead of writing the map function every time I wanted to do something to the tone/brightness, I stored them in variables.
I did the same thing with the maximum distance variable
2. Tinkercad was not compiling properly.
One of the variables was initially named "tone," which turned out to be a reserved word. Whereas, a reserved word (keyword) cannot be used as a variable name. So, I changed it to "freq" (to represent frequency).
3. When I used Hairless MIDI, the Arduino only sent error messages
so I followed these tutorials and discovered that the errors appear to be caused by the fact that it has a default baud rate different from the one I specified in the code (9600)