1 00:00:00,110 --> 00:00:08,109 Hello, in this video tutorial I'm going to show to you how to use a servo motor. 2 00:00:08,109 --> 00:00:16,109 This type of motor, you can see it here, they are not the usual type of motors that they turn and turn and turn. 3 00:00:16,109 --> 00:00:18,109 They work in a different way. 4 00:00:18,109 --> 00:00:22,109 Using one block like this one, can you see it? 5 00:00:22,109 --> 00:00:28,129 can you see it? Girar servo en el pasador 10 a cero grados. Using this block, we can send an order, 6 00:00:29,129 --> 00:00:35,810 a command, to the servo, this one, connected to number 10, and the command, instead of being 7 00:00:35,810 --> 00:00:43,210 turning and turning, is saying that the servo has to place itself in zero degrees position. 8 00:00:43,750 --> 00:00:50,109 For instance, here the servo is in zero degrees, this is zero. Okay, so the servo is connected, 9 00:00:50,109 --> 00:01:01,109 The green wire, the one on the left, is connected here, for instance, to number 10, or 11, or 9, whatever you prefer. 10 00:01:01,750 --> 00:01:03,750 And there are also two other connectors. 11 00:01:04,230 --> 00:01:10,969 The red one, the one in the middle, is connected to the power source, and the one on the right is connected to ground. 12 00:01:11,590 --> 00:01:13,469 Here, we have an extra component. 13 00:01:13,590 --> 00:01:14,129 Can you see it? 14 00:01:14,370 --> 00:01:15,629 This is a power supply. 15 00:01:15,629 --> 00:01:27,629 The servo motor is here, so you can click and drag, but if you look for the power source, you can't find it here. 16 00:01:27,629 --> 00:01:35,629 You will have to look in the standard library, the one that has all the components. 17 00:01:35,629 --> 00:01:47,409 The moment we are looking for every component, todos, if we move down, down and down and down, here we have the power source. 18 00:01:47,549 --> 00:01:48,650 So we click and drag. 19 00:01:49,569 --> 00:01:58,129 The reason we need a power source is that the Arduino board that is here can't provide enough energy to the servo motor. 20 00:01:59,890 --> 00:02:04,049 But anyway, the Arduino board needs the ground. 21 00:02:04,049 --> 00:02:11,009 The ground is connected to the ground. The ground of the Arduino board is connected to the ground of the servo motor and to the ground of the power source. 22 00:02:11,409 --> 00:02:15,229 This way, the three of them have a common point of reference. 23 00:02:15,729 --> 00:02:19,770 This is also the idea of the ground. It's a reference of voltage. 24 00:02:19,990 --> 00:02:27,050 It's not just the way we close the circuit, that is true, but it's also a common point of reference for voltage. 25 00:02:27,050 --> 00:02:34,729 So, now I think you understand why the red wire is connected here and why the black wire is connected here. 26 00:02:34,810 --> 00:02:40,889 Because the power to move the servo is going to be provided by the power source, okay? 27 00:02:41,349 --> 00:02:51,930 So, the program you will have to create, okay, I repeat, before, I repeat, I'm not going to show the code today. 28 00:02:52,150 --> 00:02:55,169 I'm going to send, I'm going to show you how the program behaves. 29 00:02:55,169 --> 00:02:56,689 I'm going to start the simulation. 30 00:02:57,050 --> 00:03:03,050 The program starts here, starts here, and it will be turning and turning and turning, 31 00:03:03,050 --> 00:03:11,050 because we are always sending commands to make the motor be in different positions. 32 00:03:11,050 --> 00:03:16,050 So we have started in 0 degrees, we are moving up and up and up, 33 00:03:16,050 --> 00:03:24,050 and the moment we are in 90 degrees, we start moving down, 90, 85, 80, 75, 70, 34 00:03:24,050 --> 00:03:29,189 70, and the program will finish in zero degrees again, okay? 35 00:03:29,610 --> 00:03:31,710 This is the intensity, can you see? 36 00:03:31,830 --> 00:03:35,330 That is providing the power source, okay? 37 00:03:35,629 --> 00:03:39,830 At the moment we arrive to zero degrees, the program will stop, okay? 38 00:03:39,889 --> 00:03:40,710 It doesn't move anymore. 39 00:03:41,030 --> 00:03:41,889 We can't stop it anyway. 40 00:03:42,590 --> 00:03:46,909 So, the first thing you need to do is connecting the circuit this way. 41 00:03:46,909 --> 00:03:50,610 They are doing a board, the servo, and the power source. 42 00:03:50,610 --> 00:03:54,930 And I hope you are understanding why the power source is needed. 43 00:03:55,650 --> 00:03:59,669 And the blocks, I'm not going to show them to you, 44 00:03:59,990 --> 00:04:03,909 but I'm going to show the main idea. 45 00:04:04,250 --> 00:04:07,189 The first thing we need is a block like this one. 46 00:04:07,689 --> 00:04:11,969 With this block, you are saying that the servo connected to number 10 47 00:04:11,969 --> 00:04:13,990 is going to be in zero degrees. 48 00:04:14,889 --> 00:04:16,370 Okay, this is the way we start. 49 00:04:16,649 --> 00:04:18,810 We always need to start somewhere. 50 00:04:19,750 --> 00:04:25,850 We always need to be sure that our servo will start in the desired position 51 00:04:25,850 --> 00:04:28,769 because we don't know, usually we don't know where it will be. 52 00:04:28,829 --> 00:04:32,649 It will be forever in 45 or 50 or 30, I don't know. 53 00:04:32,889 --> 00:04:36,310 So the first order is always start in zero degrees. 54 00:04:37,269 --> 00:04:40,069 Then we will have to wait, for instance, one second. 55 00:04:40,069 --> 00:04:47,790 Every time we make the servo turn, we need to wait some time. 56 00:04:47,790 --> 00:04:49,949 We need to give time to the servo to move. 57 00:04:51,029 --> 00:04:53,550 Okay, so this is the first part of the code. 58 00:04:53,829 --> 00:04:57,870 Then there will be a second part that will be something like that. 59 00:04:58,050 --> 00:05:01,870 This part is taken from the previous exercise, okay? 60 00:05:02,089 --> 00:05:05,910 This is not the one we are going to use to move the servo, but it's going to be really similar. 61 00:05:05,910 --> 00:05:18,509 The first time you will move upwards, you will, for instance, turn or jump every 5 degrees from 0 to 90, okay? 62 00:05:18,610 --> 00:05:20,490 Remember the simulation you have for racing? 63 00:05:21,370 --> 00:05:25,730 And then you will send the order to move, and again, we will use a variable. 64 00:05:25,730 --> 00:05:40,389 The same way we use the variable to send a frequency to the buzzer, we will use a variable to send an angle to the servo. 65 00:05:40,870 --> 00:05:49,949 Again, we will have to wait to give time, so this one will be the second part of the program, and there will be a third part, really similar to the second one. 66 00:05:49,949 --> 00:05:53,129 But instead of moving upwards, we will move downwards. 67 00:05:53,689 --> 00:05:58,769 Again, we will jump every 5 degrees from 90 to 0. 68 00:05:59,050 --> 00:06:04,470 And again, we will send commands to the servo using a variable. 69 00:06:04,569 --> 00:06:06,069 A variable, for instance, for angle. 70 00:06:06,509 --> 00:06:10,490 And then every time we make it move, we will wait for one second. 71 00:06:10,870 --> 00:06:12,529 So this is the program you will need. 72 00:06:12,790 --> 00:06:16,810 The first part, something similar to this one for the second part, 73 00:06:16,970 --> 00:06:19,430 and something similar to this one for the third part. 74 00:06:19,430 --> 00:06:25,790 And if you program it properly, it will behave the same way you have seen in the simulation, okay? 75 00:06:26,269 --> 00:06:28,410 The exercise is not difficult. 76 00:06:28,550 --> 00:06:30,629 Just follow my instruction, okay? 77 00:06:31,050 --> 00:06:32,089 So, good luck.