1 00:00:00,320 --> 00:00:07,120 Hello, today we are going to make a new circuit. As always we need the protoboard, 2 00:00:08,480 --> 00:00:16,480 we need the Arduino board, and this circuit is going to use an LED as an output. So let's look 3 00:00:16,480 --> 00:00:21,519 for the LED here, and we are going to connect it the same way we have done it the previous days. 4 00:00:22,399 --> 00:00:28,160 We need the ground connection, we are going to connect it here to the horizontal line, 5 00:00:28,160 --> 00:00:36,960 and the wire is going to be black. Okay, and again we are going to connect the ground 6 00:00:38,000 --> 00:00:44,479 to this terminal, to the anode, to the cathode, I'm sorry, and this wire is going to be black again, 7 00:00:45,280 --> 00:00:51,119 and again we need the protection resistor. Remember that the protection resistor is always 8 00:00:51,119 --> 00:01:02,320 a 220 ohms one, change it here, and we connect it to this connector, the one that is called the anode, 9 00:01:03,119 --> 00:01:08,000 and we are going to control the circuit, we are going to control the LED, I'm sorry, 10 00:01:08,000 --> 00:01:16,510 using the connector number 13, to change the way the wires are connected, but it's exactly the same. 11 00:01:16,510 --> 00:01:24,620 Ok, this wire is easier to see it, and this wire is going to be green just because. 12 00:01:24,620 --> 00:01:32,379 So can you see that I have closed the circuit from connector number 13 to the LED and we 13 00:01:32,379 --> 00:01:33,379 go back to the ground. 14 00:01:33,379 --> 00:01:38,780 Ok, now this is the output part, because we are going to control the LED from the Arduino 15 00:01:38,780 --> 00:01:39,780 board. 16 00:01:39,780 --> 00:01:45,500 It will shine or it won't, it depends on the things we want. 17 00:01:45,500 --> 00:01:54,579 Now the new part. We are going to add a button. We click and drag and the button is here now. 18 00:01:54,579 --> 00:01:58,980 So we are going to connect the button this way. This is the standard way of connecting 19 00:01:58,980 --> 00:02:04,379 buttons. Every time we need a button, we are going to connect it this way. We are going 20 00:02:04,379 --> 00:02:14,379 to use a 5V connection that is here. We click from this one to here. The wire I am going 21 00:02:14,379 --> 00:02:20,539 to use we're going to be red just because well red is the usual color for a five volts connection 22 00:02:20,539 --> 00:02:26,300 so okay we can see that you can we see the wire from this position to this one and here in the 23 00:02:26,300 --> 00:02:33,259 other a connector of the of the button we are going to connect it to for instance from this 24 00:02:33,259 --> 00:02:42,939 position to 12. and color for instance i don't know orange right so and we need something else 25 00:02:42,939 --> 00:02:48,699 we need a pull-down resistor. You are going to see how to connect it. The pull-down resistor 26 00:02:48,699 --> 00:02:54,379 is a 10 kilo ohms one. Can you see that it's a 10 kilo ohms one? And it's going to be connected 27 00:02:54,379 --> 00:02:59,180 this way. And here realize that this is the ground. Can you see that here is the ground 28 00:02:59,180 --> 00:03:03,979 because of the horizontal line? So now using the drawing I'm going to explain the button. 29 00:03:04,699 --> 00:03:12,460 If the button is pressed, if you click here while the circuit is being simulated, if you 30 00:03:12,460 --> 00:03:16,960 press here, there will be a connection between this wire, between this point, and 31 00:03:16,960 --> 00:03:20,560 this point. It means this wire. So because there is a connection between this one 32 00:03:20,560 --> 00:03:24,460 and this one, if we have this one and this one, if we have five poles here, we 33 00:03:24,460 --> 00:03:31,479 will have five poles here, and five poles will be here in pin number 12. Okay. But 34 00:03:31,479 --> 00:03:35,439 if we don't press the button, there will be no connection between this point and 35 00:03:35,439 --> 00:03:41,620 this point. So this point will be connected to ground through this 36 00:03:41,620 --> 00:03:46,900 resistor. It means that we will have zero here, we will have zero here in pin 37 00:03:46,900 --> 00:03:52,659 number 12. So it means that if we don't press, we have zero here in pin number 38 00:03:52,659 --> 00:04:00,080 12. If we press, we have five volts because of the red wire, okay? Do you 39 00:04:00,080 --> 00:04:04,240 understand? If you don't understand, try to watch it a second time and I think it 40 00:04:04,240 --> 00:04:10,180 will be easier. Now, what do we need now? We need the program. So we click here on 41 00:04:10,180 --> 00:04:16,100 code and now we have the program we click and drag to the left the previous program we remove it and 42 00:04:16,660 --> 00:04:24,180 we are going to start programming the first thing we need is an is an input input so 43 00:04:25,220 --> 00:04:32,259 okay we are going to use this block leer pasado digital for instance 12 because it's the one we 44 00:04:32,259 --> 00:04:41,290 are reading okay so we are going to read it here and but we need something else we need a variable 45 00:04:41,290 --> 00:04:46,529 A variable is a kind of a box to store something, some values, some number we have read. 46 00:04:46,730 --> 00:04:49,930 So we are going to use a variable, variable, create variable. 47 00:04:50,069 --> 00:04:55,009 And the name for this variable will be, for instance, input, because it's the one we are reading. 48 00:04:55,550 --> 00:05:01,170 So we are going to use this block, define input this way. 49 00:05:01,709 --> 00:05:03,129 So let's see if you understand. 50 00:05:03,569 --> 00:05:05,810 This is the reading from number 12. 51 00:05:06,350 --> 00:05:09,069 And this reading will be stored here. 52 00:05:09,069 --> 00:05:10,470 Input is like a box. 53 00:05:10,470 --> 00:05:15,730 It's a place to save, to store this number, the number from number 12, okay? 54 00:05:15,990 --> 00:05:19,550 So now we have our input in the variable input. 55 00:05:20,129 --> 00:05:22,170 Now, what we are going to do now? 56 00:05:22,990 --> 00:05:24,250 What are we going to do now? 57 00:05:24,509 --> 00:05:32,329 We are going to check the value of the input, of the value that is here. 58 00:05:33,149 --> 00:05:37,389 And we are going to compare the input with something else, with a value, for instance. 59 00:05:37,730 --> 00:05:38,470 What do we want? 60 00:05:38,470 --> 00:05:42,470 We want to use this block. The block is here in the green 61 00:05:42,470 --> 00:05:46,470 library, the one about maths. We are going to use 62 00:05:46,470 --> 00:05:50,470 it later, but for the moment the only block we are going to use is this one, the second one. 63 00:05:50,470 --> 00:05:54,470 Here we can compare two values. We can compare if one of them is lower, 64 00:05:54,470 --> 00:05:58,470 lower or equal, equal, not equal, 65 00:05:58,470 --> 00:06:02,470 higher or equal. For the moment let's use 66 00:06:02,470 --> 00:06:06,470 equal. And what do we want to compare? 67 00:06:06,470 --> 00:06:11,629 compare? We want to compare the input. If the input 68 00:06:11,629 --> 00:06:12,370 equals 69 00:06:12,370 --> 00:06:29,000 this is the one I was 70 00:06:29,000 --> 00:06:32,660 looking for. I don't want a number. I want two 71 00:06:32,660 --> 00:06:36,639 possibilities. High or low because these are digital inputs. We cannot 72 00:06:36,639 --> 00:06:40,379 compare this one with a number because we are reading digital inputs. 73 00:06:40,379 --> 00:06:43,939 Take it into account. Digital means high or low. 74 00:06:43,939 --> 00:06:52,459 Analog means whatever value you need. So if input equals high it means 75 00:06:52,459 --> 00:06:56,600 that we are pressing this button because we are reading 12. Remember we are reading 76 00:06:56,600 --> 00:07:01,519 12. This value is stored here and now we are comparing this value with high. So 77 00:07:01,519 --> 00:07:06,439 what happens if we are pressing the value? So for instance I want number 13 78 00:07:06,439 --> 00:07:16,620 high. How can I do it? Here, in salida, definir. Puls, pasador, 13, and alta. Number 13, high. 79 00:07:16,939 --> 00:07:22,720 Okay, perfect. So, with this program, if I press the button, the LED will shine. Do you 80 00:07:22,720 --> 00:07:28,939 agree? We read the value, we store it here in input, we compare the input with high, 81 00:07:29,560 --> 00:07:34,220 C, if input equals high, 13 will be high. 82 00:07:35,540 --> 00:07:37,339 And C no, what does it mean, C no? 83 00:07:37,399 --> 00:07:38,459 In English we say else. 84 00:07:38,839 --> 00:07:42,240 Else is the things that will happen if the condition is not true, 85 00:07:42,459 --> 00:07:43,420 because this is a condition. 86 00:07:43,860 --> 00:07:46,540 What do we want if we are not pressing the button? 87 00:07:46,959 --> 00:07:52,100 If input is low, we want, just because we want it this way, 88 00:07:52,100 --> 00:07:58,420 we want that 13 is low, baja. 89 00:07:58,420 --> 00:08:11,459 So this way, if we press the button, we store the value here, we compare the value with high, and if the value is high, the LED will shine because it's connected to 13. 90 00:08:11,680 --> 00:08:16,680 And if the condition is not true, the LED connected to 13 will be low. 91 00:08:17,000 --> 00:08:17,860 This is the idea. 92 00:08:18,180 --> 00:08:26,600 We have connected everything, the output part, we have the input part with the button and the pull-down resistor, and we have the blocks. 93 00:08:26,600 --> 00:08:28,079 We have everything we need. 94 00:08:28,079 --> 00:08:30,079 So let's start the simulation. 95 00:08:30,079 --> 00:08:33,080 Okay, apparently nothing happens, 96 00:08:33,080 --> 00:08:36,080 but if we press the button, we click here, 97 00:08:36,080 --> 00:08:38,080 the LED is shining. Can you see it? 98 00:08:38,080 --> 00:08:41,080 And if I finish pressing it, the LED doesn't shine. 99 00:08:41,080 --> 00:08:44,080 Everything according to our program. 100 00:08:44,080 --> 00:08:48,080 Okay, so the exercise today is just repeating this example. 101 00:08:48,080 --> 00:08:51,080 Nothing else. Okay, good luck.