This week we learned about output devices, which are controlled electronically and convert power into motion (motors), light (diodes LED, electroluminescent wire) and sound (piezoelectric). We also talked about electromagnetism and how that works in different types of motors (DC motors and mosfets, steppers, servomotor).
An output device is any device we can be using as an output of data. In this week's assignment, we measured DC motors a LED and the ESP32 consumption using a variable power supply and a multimeter. To measure the consumption of the DC motors we measured the amperes that the DC motor feeds itself using the power supply. A DC motor will require initially more ampers to start then to keep going. Usually DC motors work between 6-12 volts, the amperes can vary depending of what the motor is holding and the type of DC motor we work with. For example a DC motor that has a very thin cable will have less resistance therefore will need more amperes to work. The DC motor we measured consumed between 300-400 milliampere at 12v.
The ESP32 consumed 60 milliampere at 5v and the LED consumed 7 milliampere at 3v.
→ Group Page here
For this week's project, I wanted to work with sound, so I decided to go ahead with the Piezo buzzer. To start I decided to explore a little bit first by using the piezo buzzer with Arduino UNO and Barduino.
Trying piezo buzzer with Arduino Uno
I started by searching for online tutorials that could help me get started. In this tutorial, I got the schematics. It seemed pretty straightforward. Using a breadboard and Arduino UNO we feed the board with 5v and the piezo buzzer connects 1 pin to GND and another one to a digital pin (we define that pin as the OUTPUT pin). We also use a resistor of 100 Ohm so that we make sure there is not too much voltage passing to the piezo buzzer.
Then I went ahead and added the code to Arduino IDE and uploaded it to the Arduino UNO board. I wanted to make it more playful and remembered that in the class we saw that we can even use music by using a library "pitches.h". I then went to check any songs that have been made already and used the godfather song as a song emitted by the piezo buzzer! Because the code was all commented I understood what it was doing without any problems.
Trying piezo buzzer with Barduino
Then I was also curious to do it with the FabLab board - Barduino. I used exactly the same circuit and went ahead to upload the same code. What I understood is that Barduino has less memory than Arduino UNO and it said it didn't have enough space when I tried to upload it to the board, I assume it was because of the length of the song. So I just used a simple short sound with a few notes. For the code, I used the Arduino example for tone melody, which uses the same library ("pitches.h").
Exploring the piezo buzzer in the Arduino UNO and in the Barduino really helped me understand the circuit and what I needed to design for this week's PCB.
Sketching
Because I also learned last week how important it is to think carefully about everything I started by sketching on paper the piezo buzzer connections. I only needed to connect the piezo buzzer to GND (-) and a Pin (+), I also added a 100ohm resistor as i saw it in the previous tutorials mentioned above. Because of the short circuit in the board on last week I though it was better to include it as well. I also saw that in the tutorials there was a connection to a 5v, which I was kinda confused since I was going to plug in to the previous board that was already being charged by the mini usb. Later I realized that the 5v was not needed for this board (neither for the tests in Arduino and Barduino).
Doing the shematics in Kicad
Since I was still working on last week's PCB I ended up adding the circuit for the piezo buzzer on the board. I went back to my schematics and added a 12mm piezo buzzer (measured the one I was going to use) and made sure I added a connection to GND and another to a PIN - which I realized after testing it was causing a short circuit, so I designed a new board to connect to last week's board instead (that was working perfectly without the piezo).
FFor this board, I simply used the piezo buzzer with the - connected to GND and the + connected to the PIN. Then I added a female head that fits the male heads on the other board making this connection. I also used a 100ohm resistor between the piezo buzzer and the PIN head.
Since I have been doing this since last week, this process was quite straightforward.
Preparing the files
I started by preparing the files, this time what I did differently was to use Figma, then open Inkscape to change the dpi to 100 and then check the size. I only check the size and updated the Figma files with that size. I did this because in Inkscape it was creating a white line on the edge of the SVG. It worked perfectly!
Once I got the PNGs I went to MODS and added the images of the traces, outline, and holes. For the traces, I used again 1/64 (0,4mm) and for the holes and outlines I used 1/32 (0,8mm). I updated the origin coordinates to 0 and made sure to add a 15mm distance between points when cutting so the endmill doesn't scratch the board.
Milling
Then, once I had the files for the machine I added the board to the bed of the machine with double side tape. I also made sure the surface was really clean. I then proceed to set up the x, and y-axis by using the arrows in the machine and set it up. Then for the a axis, I moved the endmill as close to the board as I could (in the center of the board) and then with my hand loosened the endmill and made it drop until it touched the board, then I locked it and set up the z-axis in the machine. I then move the z up so It didn't scratch the board and clicked "cut", added the file, and clicked "output".
I did the same procedure for the holes and outline but with the 1/32(0,8mm) endmill. Everything went well and perfectly.
The components
For this mini board I used:
List of components
|
---|
Soldering
This time I left the soldering iron longer (because I understood I was not leaving it long enough). It was nice to solder the piezo buzzer and the pin heads differently (through the holes).
The code
I was really eager to see if this board was working correctly after such a extensive debugging with the previous one! I went ahead and used the example code we already have in Arduino IDE for the tony melody and simply updated the OUTPUT PIN to match the one I have.
This is an example code that plays a melody in 8 bit. It uses a library and I call that library at the beginning of the code: #include "pitches.h". This library contains all the pitch values for typical notes so that we can call them in the code.
So after that, I declare my variable which is an int (integer) where I first define which notes I am calling for the melody.
int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; |
Then I have another variable that sets the duration of notes, they are in the same order as the notes above meaning we are attributing to the notes specific times, so it creates a melody.
int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; |
In the setup() - setup is the code that runs only once, in my case I use in setup because I only wanted to play once, if I wanted to play in loop I could have put this code inside the loop() function), I declare a "for" condition (that repeats a block of statements) that counts all the notes (++) that are = 0 or less than 8.
for (int thisNote = 0; thisNote < 8; thisNote++) {} |
Inside this condition, we declare another variable:
int noteDuration = 1000 / noteDurations[thisNote]; |
This is dividing the duration of the note (quarter note, eight note) by time, so if we want the notes to take longer we could change the 1000 (1 second) to be more for example.
Then we say the pin we are using in this case (GPIO 15) is going to play the melody (variable we defined earlier) for the count we had set before (so the 8 notes) and for how long each note plays (noteDuration).
tone(15, melody[thisNote], noteDuration); |
To finish it up, we have a variable to have a little of time between each note
int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); |
So, for every note being played there is a delay of 1000 (noteDuration)*1.30, meanings its 1 second and 20 milliseconds (more or less).
So I decided to play a bit more with the code and created a new melody using 16 notes instead, for that I added in the melody variable more musical notes:
int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_B3, NOTE_B3, NOTE_G3, NOTE_G3, NOTE_G3 }; |
Then I had to update the note durations and add the new durations to it:
int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4, 4, 8, 8, 4, 4, 4, 4, 4 }; |
And finally, I just needed to increase the count to 16!
for (int thisNote = 0; thisNote < 8; thisNote++) { |
→ Design files here
Manufacturing this board was really straight forward as I had been manufacturing a few boards for the previous week. The circuit was really straightforward and I made sure I was soldering properly by leaving the soldering iron longer. I was really happy that everything worked!