1 00:00:00,370 --> 00:00:07,169 Hello! In this video tutorial we are going to learn how to use a buzzer. A buzzer or a beeper, 2 00:00:07,169 --> 00:00:14,929 as you can see on the screen, is a device that produces sound. So the first thing we need to 3 00:00:14,929 --> 00:00:21,730 know is that there is a buzzer here in the library of components. In Spanish we say piezo or piezo 4 00:00:21,730 --> 00:00:30,929 electrical so just click and drag you can use the proto board we are going to use the arduino board 5 00:00:30,929 --> 00:00:37,170 and connecting the big part to the or the buzzer to the arduino board is really really really easy 6 00:00:37,170 --> 00:00:42,850 one of the connectors is going to be connected to the ground and the other one to 7 00:00:43,890 --> 00:00:50,770 whatever digital pin we want for instance here the buzzer has been connected to 12. 8 00:00:50,770 --> 00:00:56,130 Okay, this is the connection. Really, really easy. Programming is not really difficult either. 9 00:00:57,090 --> 00:01:03,969 We have a look at the code. This is the simplest way of programming the buzzer. We have used 10 00:01:04,769 --> 00:01:11,250 one blue block. Remember, the blue library is the output. We use the reproducir altavoz and 11 00:01:11,250 --> 00:01:16,049 el pasador. Pasador means connector here. We're going to connect. We have connected it to 12. 12 00:01:16,049 --> 00:01:27,049 Tono is the frequency, here it's going to be 50 Hz, and it's going to sound for half a second. 13 00:01:27,049 --> 00:01:31,049 And we will wait for one second before we start again. 14 00:01:31,049 --> 00:01:38,049 Be careful, because sounding for half a second and waiting one second, 15 00:01:38,049 --> 00:01:43,049 it doesn't mean that the whole program will last one and a half seconds, 16 00:01:43,049 --> 00:01:45,049 because it works a little bit different. 17 00:01:45,049 --> 00:01:50,489 The moment we start the sound, we start the waiting tool. 18 00:01:51,209 --> 00:01:51,569 Do you understand? 19 00:01:51,709 --> 00:01:55,849 So it means that while we are waiting, there is also sound. 20 00:01:56,469 --> 00:02:01,349 So here it means that we are going to be waiting for one second, 21 00:02:01,590 --> 00:02:08,169 but during this one second, half of this one second is going to be sound. 22 00:02:08,669 --> 00:02:11,990 So here we have a square wave, una onda cuadrada. 23 00:02:11,990 --> 00:02:17,750 half of the second is going to be is going to be sound the other one the one 24 00:02:17,750 --> 00:02:22,430 that the second half of the second there will be no sound because we are waiting 25 00:02:22,430 --> 00:02:27,590 that the second finishes do you understand the idea so on what happens 26 00:02:27,590 --> 00:02:35,210 if we start the simulation if we start simulation this is the sound okay now 27 00:02:35,210 --> 00:02:42,949 let's change the frequency instead of having 50 we are going to have 100 what 28 00:02:42,949 --> 00:02:50,830 happens if I start the simulation now it sounds different because the frequency 29 00:02:50,830 --> 00:02:58,909 is higher now let's try another possibility instead of producing sound 30 00:02:58,909 --> 00:03:08,889 for 0.5 seconds, we are going to produce sound for 0.7 seconds, okay? It means 70% of the time 31 00:03:08,889 --> 00:03:15,889 there will be sound during the 70% of the time we are waiting. You understand the idea? So let's 32 00:03:15,889 --> 00:03:27,270 produce the sound again. Can you hear the period of time? While there is no sound, it's shorter 33 00:03:27,270 --> 00:03:36,810 than before there is sound for 0.7 there is no sound for 0.3 30 seconds okay okay this is the 34 00:03:36,810 --> 00:03:43,349 simplest way of programming a beeper but we are going to program it a little bit more we are going 35 00:03:43,349 --> 00:03:47,889 to make a program we are going to do a program a little bit more complicated we are going to 36 00:03:47,889 --> 00:03:54,930 program it this way using a different loop and you see contar this is the loop this is the program 37 00:03:54,930 --> 00:03:58,810 We already have the reproducer altavoz and the weight and it will be 38 00:03:58,810 --> 00:04:04,800 inside a loop. Contar arriba. Two possibilities. Arriba 39 00:04:04,800 --> 00:04:08,900 abajo. Arriba means counting upwards or counting downwards. 40 00:04:09,199 --> 00:04:12,580 It means we are going to move upwards or downwards. 41 00:04:14,240 --> 00:04:16,759 Okay, let's start here. 42 00:04:17,279 --> 00:04:20,899 It means, well, first thing we need is a variable. The name for this 43 00:04:20,899 --> 00:04:24,639 variable is tono, just because I want. It could be frequency or whatever. 44 00:04:24,639 --> 00:04:29,639 So it means that with this variable we are controlling the frequency. 45 00:04:29,639 --> 00:04:37,639 We are going to sweep frequencies from 10 Hz to 130 Hz. 46 00:04:37,639 --> 00:04:43,639 Each time we will step 10 units. We will move upwards. 47 00:04:43,639 --> 00:04:46,639 I'm going to show it using the example. 48 00:04:46,639 --> 00:04:52,639 First frequency, 10 Hz. Second one, 10 plus 20, 30. 49 00:04:52,639 --> 00:04:55,300 Third one, 30 plus 20, 50. 50 00:04:55,480 --> 00:05:01,240 Next one, 70, 90, 110, and 130, the last one. 51 00:05:01,240 --> 00:05:07,180 It means that each time we jump, or each time we add, we add 20 units. 52 00:05:07,319 --> 00:05:12,279 This is the meaning of 20, this is the meaning of 10, this is the meaning of 130, the final value. 53 00:05:12,680 --> 00:05:15,959 Here we have the variable we are using to store the numbers, 54 00:05:15,959 --> 00:05:22,100 and here having upwards, having arriba, it means that we are going to move 55 00:05:22,100 --> 00:05:27,060 10, 30, 50, 70, 90, 100, 10, 130. 56 00:05:27,699 --> 00:05:32,899 We could move hacia abajo, downwards, but this way we will start here, 57 00:05:33,000 --> 00:05:39,920 130, and we will finish at 10, 130, 110, 90, 70, 50, 30, and 10. 58 00:05:39,920 --> 00:05:43,420 Do you understand? I think now you understand all the variables, 59 00:05:43,420 --> 00:05:47,519 or the numbers or the possibilities here in this loop. 60 00:05:48,019 --> 00:05:49,420 And this loop is here, okay? 61 00:05:49,620 --> 00:05:51,180 I mean, this is the main program, 62 00:05:51,300 --> 00:05:53,339 the one we had in the previous example 63 00:05:53,339 --> 00:05:56,620 that is now inside the variable, inside the loop. 64 00:05:57,300 --> 00:05:58,759 So let's start the simulation. 65 00:06:10,420 --> 00:06:11,600 And we start again. 66 00:06:12,019 --> 00:06:13,259 So there is a full loop, 67 00:06:13,319 --> 00:06:16,060 and when the loop ends, we start again, okay? 68 00:06:16,300 --> 00:06:19,300 So the second one is the one we have to reproduce, 69 00:06:19,300 --> 00:06:21,420 and there will be also two more questions. 70 00:06:22,639 --> 00:06:23,699 So, good luck!