For this week's assignment, the idea is to Build and Program a smart circuit using an Arduino UNO which reads a signal from an input component to control an action component using code blocks . I decided to focus on something that could be implemented in my final project, the Montessori busy board for kids. One of the nice to have in my project is a Mini-Piano, so i decided to make a Mini-piano. The following link helped me in doing it.
We used Tinker CAD which is a free web app for electronics, coding and 3D design. On Tinker CAD we can create simulations of circuits in which we there is a dashboard that contains all the components needed to create any circuit, we can just drag and drop the component that we want to use, so we can design and test our ideas virtually, which helps us to experiment the circuit before physically doing it. https://www.tinkercad.com/
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them
Arduino UNO is a low-cost, flexible, and easy-to-use programmable open-source microcontroller board that can be integrated into a variety of electronic projects. It consists of various pins, which makes it more compatible and can be used to connect different electronic components.
A breadboard is a plastic board with tiny holes. These holes make it easily to insert electronic components to prototype, create electric circuits.
The USB port serves two purposes: First, it is the cable connection to a computer which allows you to program the board. The USB cord will also provide power for the Arduino if you're not using the power port
RGB stands for Red, Green, and Blue, the primary colors of light. An RGB LED, therefore, is a light-emitting diode that combines these three colors to produce over 16 million hues of light.
Push button is a simple switch mechanism to control some aspect of a machine or a process.
Buzzer is an electronic component that generates sound through the transmission of electrical signals. Its primary function is to provide an audible alert or notification
A resistor is a two-terminal electrical component that provides electrical resistance, used to lower the flow of current, divide voltages
Jumper wires are used to connect components together and it has different types like Male-Male, Male-Female, and Female-Female.
On/Off switch used to open or close an electrical circuit in a stable manner.
Open TinkerCAD and create a circuit.
Drag and drop the needed components.
Assemble the components on the breadboard.
Connect the GND of Arduino with the -ve of the breadboard.
Connect the terminals of the buzzer, the +ve terminal to an Analog pin on the Arduino (Pin9), and the -ve terminal to the GND connected already to the breadboard.
Connect the 5-Push buttons, as the first terminal connected to the GND and the other terminal connected to pins in the Arduino (Pins 2,3,4,5 and6).
Connect the common terminal of the RGB with GND and the other 3-terminals connect each terminal to a 220 ohms resistor and connect them to pins in Arduino (Pins 10,11 and 12).
Finally to control the circuit connect an ON/OFF Switch, one of terminals to the 5V Arduino pin and the other one to any pin in Arduino (Pin7) and the common terminal to the GND.
Input component: ON/Off Switch and 5-Push buttons.
Output components: Buzzer and RGB
Circuit link: https://www.tinkercad.com/things/iCzDXv2qHDC-copy-of-mini-piano
// C++ code
//
void setup()
{
pinMode(7, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(9, OUTPUT);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
}
void loop()
{
while (digitalRead(7) == HIGH) {
if (digitalRead(2) == LOW) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
tone(9, 294, 500); // play tone 262 (A#21 = 61101017 Hz)
}
if (digitalRead(3) == LOW) {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
tone(9, 330, 500); // play tone 294 (F#24 = 387967272 Hz)
}
if (digitalRead(4) == LOW) {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
tone(9, 349, 500); // play tone 330 (F#27 = 3103738174 Hz)
}
if (digitalRead(5) == LOW) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
tone(9, 392, 500); // play tone 349 (C#29 = 9300705743 Hz)
}
if (digitalRead(6) == LOW) {
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
tone(9, 440, 500); // play tone 392 (G#32 = 111482505874 Hz)
}
}
noTone(0);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
delay(10); // Delay a little bit to improve simulation performance
}
pseudo code:
If push button 2 is pressed, light up the RGB with Red and play the buzzer on tone 294 (Do), If push button 3 is pressed, light up the RGB with Green and play the buzzer on tone 330 (Re), If push button 4 is pressed, light up the RGB with (Green-Blue) and play the buzzer on tone 349 (Me), If push button 5 is pressed, light up the RGB with (Green-Red) and play the buzzer on tone 392 (Fa), If push button 6 is pressed, light up the RGB with Purple and play the buzzer on tone 440 (So).
Play and repeat all the previous If conditions, while the switch is turned On and turn off the LED and the buzzer, if the switch is turned OFF (While-Loop).
Simulation
The Code Block didn't work on perfectly on Tinker Cad because of the PULLUP command, that should be added when configuring the push buttons, so that i edit it on the Arduino IDE and it works on reality. I also searched how to make the Do, Re, Me, Fa, So tones using the buzzer and i found alot of websites that helped me to figure them out.
I re-build the circuit exactly the same way on Tinker-CAD, upload the code on the Arduino board using IDE App, and it worked perfectly, i also searched how to make the Do, Re, Me, Fa, So tones using the buzzer and i found alot of websites that helped me to figure them out.
A video present the Mini-Piano in reality.
At first i wanted to use 5-different LEDs for each push buttons, but i recognized that the pins will not be enough for all of them, So i decided to use the RGB instead of them and make 5-diffrent color for each push button and after using the RGB, i have just 2-output pins empty in the Arduino board😅.
Also using Pushbuttons on the Tinker CAD is not accurate at all because of the pullup command that is not exist, so they are all the time high or all the time low according to the code, but its not working when pressing on it, so that's why we have to edit it on Arduino IDE.
It was a great choice that could be implemented in my final project idea, but it consumes alot of Pins in the Arduino, So i don't know if there is a way to add more components or not.
Guess the song played in the video 🐤🐱
The Extra session
Building a simple paper circuit using a copper tape, learning about the printed circuit boards (PCB), using the soldering machine to enclosure the components into the PCB, it was really amazing.